28 class DawgTest :
public testing::Test {
31 std::locale::global(std::locale(
""));
34 void LoadWordlist(
const std::string& filename, std::set<std::string>* words)
const {
35 std::ifstream
file(filename);
38 while (getline(
file, line)) {
40 while (!line.empty() && (line.back() ==
'\n' || line.back() ==
'\r')) {
41 line.resize(line.size() - 1);
44 words->insert(line.c_str());
58 TessBinaryPath(program) +
" " + arg1 +
" " + arg2 +
" " + arg3;
59 return system(cmdline.c_str());
64 void TestDawgRoundTrip(
const std::string& unicharset_filename,
66 std::set<std::string> orig_words, roundtrip_words;
69 std::string output_dawg = OutputNameToPath(wordlist_filename +
".dawg");
70 std::string output_wordlist = OutputNameToPath(wordlist_filename);
71 LoadWordlist(orig_wordlist, &orig_words);
73 RunCommand(
"wordlist2dawg", orig_wordlist, output_dawg, unicharset), 0);
75 RunCommand(
"dawg2wordlist", unicharset, output_dawg, output_wordlist),
77 LoadWordlist(output_wordlist, &roundtrip_words);
78 EXPECT_EQ(orig_words, roundtrip_words);
82 TEST_F(DawgTest, TestDawgConversion) {
83 TestDawgRoundTrip(
"eng.unicharset",
"eng.wordlist.clean.freq");
86 TEST_F(DawgTest, TestMatching) {
90 unicharset.
size(), 0);
92 trie.add_word_to_dawg(space_apos);
97 EXPECT_TRUE(trie.prefix_in_dawg(space,
false));
99 EXPECT_FALSE(trie.word_in_dawg(space));
100 EXPECT_FALSE(trie.prefix_in_dawg(space,
true));
103 EXPECT_TRUE(trie.prefix_in_dawg(space_apos,
false));
104 EXPECT_TRUE(trie.word_in_dawg(space_apos));
105 EXPECT_TRUE(trie.prefix_in_dawg(space_apos,
true));