Debian Codegraph @

libstdc++-v3/testsuite/20_util/hash/chi2_q_document_words.cc

raw
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-2025 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 // { dg-additional-files "thirty_years_among_the_dead_preproc.txt" }
23
24 #include "chi2_quality.h"
25
26 // Tests chi^2 for a set of words taken from a document written in English.
27 void
28 test_document_words()
29 {
30 const std::string f_name = "thirty_years_among_the_dead_preproc.txt";
31 std::ifstream in(f_name);
32 VERIFY( in.is_open() );
33 std::vector<std::string> words;
34 words.assign(std::istream_iterator<std::string>(in),
35 std::istream_iterator<std::string>());
36 VERIFY( words.size() > 100000 );
37 std::sort(words.begin(), words.end());
38 auto it = std::unique(words.begin(), words.end());
39 words.erase(it, words.end());
40 VERIFY( words.size() > 5000 );
41
42 const unsigned long k = words.size() / 20;
43 double chi2 = chi2_hash(words, k);
44 VERIFY( chi2 < k*1.1 );
45 }
46
47 int
48 main()
49 {
50 test_document_words();
51 return 0;
52 }