]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/hash/chi2_q_bit_flip_set.cc
1 // Use smaller statistics when running on simulators, so it takes less time.
2 // { dg-options "-DSAMPLES=30000" { target simulator } }
3 // { dg-do run { target c++11 } }
5 // Copyright (C) 2010-2016 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 const unsigned long N
= SAMPLES
;
31 const unsigned long k
= N
/100;
32 const unsigned int len
= 67;
33 const unsigned int bitlen
= len
* 8;
34 const unsigned int bits_to_flip
= 3;
35 const char base
[len
+1] = "abcdefghijklmnopqrstuvwxyz"
36 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
39 std::unordered_set
<std::string
> set
;
40 while (set
.size() < N
)
42 std::string
s(base
, base
+len
);
43 for (unsigned int i
= 0; i
< bits_to_flip
; ++i
)
45 int bit
= rand() % bitlen
;
46 s
[bit
/8] ^= (1 << (bit
%8));
51 double chi2
= chi2_hash(set
, k
);
52 VERIFY( chi2
< k
*1.1 );