1 // { dg-options "-std=gnu++0x" }
2 // Use smaller statistics when running on simulators, so it takes less time.
3 // { dg-options "-std=gnu++0x -DSAMPLES=30000" { target simulator } }
5 // Copyright (C) 2010-2014 Free Software Foundation, Inc.
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this library; see the file COPYING3. If not see
20 // <http://www.gnu.org/licenses/>.
22 #include "chi2_quality.h"
24 // Tests chi^2 for a distribution of strings that differ from each
25 // other by only a few bits. We start with an arbitrary base string, and
26 // flip three random bits for each member of the set.
30 bool test
__attribute__((unused
)) = true;
31 const unsigned long N
= SAMPLES
;
32 const unsigned long k
= N
/100;
33 const unsigned int len
= 67;
34 const unsigned int bitlen
= len
* 8;
35 const unsigned int bits_to_flip
= 3;
36 const char base
[len
+1] = "abcdefghijklmnopqrstuvwxyz"
37 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
40 std::unordered_set
<std::string
> set
;
41 while (set
.size() < N
)
43 std::string
s(base
, base
+len
);
44 for (unsigned int i
= 0; i
< bits_to_flip
; ++i
)
46 int bit
= rand() % bitlen
;
47 s
[bit
/8] ^= (1 << (bit
%8));
52 double chi2
= chi2_hash(set
, k
);
53 VERIFY( chi2
< k
*1.1 );