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