]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/20_util/hash/chi2_q_document_words.cc
Update copyright years in libstdc++-v3/
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / hash / chi2_q_document_words.cc
CommitLineData
ca9431f7
HPN
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 { ! simulator } } }
4// { dg-options "-std=gnu++0x" }
5
aa118a03 6// Copyright (C) 2010-2014 Free Software Foundation, Inc.
ca9431f7
HPN
7//
8// This file is part of the GNU ISO C++ Library. This library is free
9// software; you can redistribute it and/or modify it under the
10// terms of the GNU General Public License as published by the
11// Free Software Foundation; either version 3, or (at your option)
12// any later version.
13//
14// This library is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17// GNU General Public License for more details.
18//
19// You should have received a copy of the GNU General Public License
20// along with this library; see the file COPYING3. If not see
21// <http://www.gnu.org/licenses/>.
22
23#include "chi2_quality.h"
24
25// Tests chi^2 for a set of words taken from a document written in English.
26void
27test_document_words()
28{
29 bool test __attribute__((unused)) = true;
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
47int
48main()
49{
50 test_document_words();
51 return 0;
52}