]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/20_util/hash/chi2_q_uniform_random.cc
modula2: Tidyup remove unnecessary parameters
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / hash / chi2_q_uniform_random.cc
CommitLineData
ca9431f7
HPN
1// Use smaller statistics when running on simulators, so it takes less time.
2// For powerpc-eabi, SAMPLES=30000 fails.
18a20f3f
JW
3// { dg-options "-DSAMPLES=35000" { target simulator } }
4// { dg-do run { target c++11 } }
ca9431f7 5
a945c346 6// Copyright (C) 2010-2024 Free Software Foundation, Inc.
ca9431f7
HPN
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 for a distribution of uniformly generated random strings.
26void
27test_uniform_random()
28{
ca9431f7
HPN
29 std::srand(137);
30 std::unordered_set<std::string> set;
31 std::string s;
32 const unsigned long N = SAMPLES;
33 const unsigned long k = N/100;
34 const unsigned int len = 25;
35 while (set.size() < N)
36 {
37 s.clear();
38 for (unsigned int i = 0; i < len; ++i)
39 s.push_back(rand() % 128);
40 set.insert(s);
41 }
42
43 double chi2 = chi2_hash(set, k);
44 VERIFY( chi2 < k*1.1 );
45}
46
47int
48main()
49{
50 test_uniform_random();
51 return 0;
52}