| 1 |
// Use smaller statistics when running on simulators, so it takes less time. |
| 2 |
// For e.g. cris-elf, mipsisa32r2el-elf, powerpc-eabi and i386-linux-gnu, |
| 3 |
// this test fails for SAMPLES=30000. |
| 4 |
// { dg-options "-DSAMPLES=35000" { target simulator } } |
| 5 |
// { dg-do run { target c++11 } } |
| 6 |
|
| 7 |
// Copyright (C) 2010-2025 Free Software Foundation, Inc. |
| 8 |
// |
| 9 |
// This file is part of the GNU ISO C++ Library. This library is free |
| 10 |
// software; you can redistribute it and/or modify it under the |
| 11 |
// terms of the GNU General Public License as published by the |
| 12 |
// Free Software Foundation; either version 3, or (at your option) |
| 13 |
// any later version. |
| 14 |
// |
| 15 |
// This library is distributed in the hope that it will be useful, |
| 16 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 |
// GNU General Public License for more details. |
| 19 |
// |
| 20 |
// You should have received a copy of the GNU General Public License |
| 21 |
// along with this library; see the file COPYING3. If not see |
| 22 |
// <http://www.gnu.org/licenses/>. |
| 23 |
|
| 24 |
#include "chi2_quality.h" |
| 25 |
|
| 26 |
// Tests chi^2 for a set of strings that all consist of '1' and '0'. |
| 27 |
void |
| 28 |
test_bit_string_set() |
| 29 |
{ |
| 30 |
const unsigned long N = SAMPLES; |
| 31 |
const unsigned long k = N/100; |
| 32 |
std::vector<std::string> set; |
| 33 |
std::string s; |
| 34 |
for (unsigned long i = 0; i < N; ++i) |
| 35 |
{ |
| 36 |
s.clear(); |
| 37 |
for (unsigned int j = 0; j < sizeof(unsigned long) * 8; ++j) |
| 38 |
{ |
| 39 |
const bool bit = (1UL << j) & i; |
| 40 |
s.push_back(bit ? '1' : '0'); |
| 41 |
} |
| 42 |
set.push_back(s); |
| 43 |
} |
| 44 |
|
| 45 |
double chi2 = chi2_hash(set, k); |
| 46 |
VERIFY( chi2 < k*1.1 ); |
| 47 |
} |
| 48 |
|
| 49 |
int |
| 50 |
main() |
| 51 |
{ |
| 52 |
test_bit_string_set(); |
| 53 |
return 0; |
| 54 |
} |