1// { dg-options "-std=gnu++11" } 2// Use smaller statistics when running on simulators, so it takes less time. 3// For e.g. cris-elf, mipsisa32r2el-elf, powerpc-eabi and i386-linux-gnu, 4// this test fails for SAMPLES=30000. 5// { dg-options "-std=gnu++11 -DSAMPLES=35000" { target simulator } } 6 7// Copyright (C) 2010-2015 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'. 27void 28test_bit_string_set() 29{ 30 bool test __attribute__((unused)) = true; 31 const unsigned long N = SAMPLES; 32 const unsigned long k = N/100; 33 std::vector<std::string> set; 34 std::string s; 35 for (unsigned long i = 0; i < N; ++i) 36 { 37 s.clear(); 38 for (unsigned int j = 0; j < sizeof(unsigned long) * 8; ++j) 39 { 40 const bool bit = (1UL << j) & i; 41 s.push_back(bit ? '1' : '0'); 42 } 43 set.push_back(s); 44 } 45 46 double chi2 = chi2_hash(set, k); 47 VERIFY( chi2 < k*1.1 ); 48} 49 50int 51main() 52{ 53 test_bit_string_set(); 54 return 0; 55} 56