]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/hash/chi2_q_document_words.cc
fae7bde71f824c8552c85b418024f65fd4cbaa3a
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / hash / chi2_q_document_words.cc
1 // On some simulators, the workload is simply too large with values big
2 // enough for the test to pass the quality test, so just skip it altogether.
3 // { dg-do run { target { c++11 && { ! simulator } } } }
4
5 // Copyright (C) 2010-2016 Free Software Foundation, Inc.
6 //
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)
11 // any later version.
12 //
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.
17 //
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/>.
21
22 #include "chi2_quality.h"
23
24 // Tests chi^2 for a set of words taken from a document written in English.
25 void
26 test_document_words()
27 {
28 bool test __attribute__((unused)) = true;
29 const std::string f_name = "thirty_years_among_the_dead_preproc.txt";
30 std::ifstream in(f_name);
31 VERIFY( in.is_open() );
32 std::vector<std::string> words;
33 words.assign(std::istream_iterator<std::string>(in),
34 std::istream_iterator<std::string>());
35 VERIFY( words.size() > 100000 );
36 std::sort(words.begin(), words.end());
37 auto it = std::unique(words.begin(), words.end());
38 words.erase(it, words.end());
39 VERIFY( words.size() > 5000 );
40
41 const unsigned long k = words.size() / 20;
42 double chi2 = chi2_hash(words, k);
43 VERIFY( chi2 < k*1.1 );
44 }
45
46 int
47 main()
48 {
49 test_document_words();
50 return 0;
51 }