1 /* Copyright (c) 2007 Eric Scott Albright
\r
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
\r
4 * of this software and associated documentation files (the "Software"), to deal
\r
5 * in the Software without restriction, including without limitation the rights
\r
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
7 * copies of the Software, and to permit persons to whom the Software is
\r
8 * furnished to do so, subject to the following conditions:
\r
10 * The above copyright notice and this permission notice shall be included in
\r
11 * all copies or substantial portions of the Software.
\r
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\r
21 #define NOMINMAX //don't want windows to collide with std::min
\r
22 #include <UnitTest++.h>
\r
23 #include <enchant.h>
\r
24 #include <enchant-provider.h>
\r
26 #include "../EnchantDictionaryTestFixture.h"
\r
28 #include <algorithm>
\r
31 DictionarySuggestsSat (EnchantDict * dict, const char *const word, size_t len, size_t * out_n_suggs)
\r
34 char **sugg_arr = NULL;
\r
36 sugg_arr = g_new0 (char *, *out_n_suggs + 1);
\r
37 sugg_arr[0] = g_strdup ("sat");
\r
42 static EnchantDict* MockProviderRequestSuggestMockDictionary(EnchantProvider * me, const char *tag)
\r
45 EnchantDict* dict = MockProviderRequestEmptyMockDictionary(me, tag);
\r
46 dict->suggest = DictionarySuggestsSat;
\r
50 static void DictionarySuggest_ProviderConfiguration (EnchantProvider * me, const char *)
\r
52 me->request_dict = MockProviderRequestSuggestMockDictionary;
\r
53 me->dispose_dict = MockProviderDisposeDictionary;
\r
54 me->free_string_list = MockProviderFreeStringList;
\r
58 struct EnchantPwlWithDictSuggs_TestFixture : EnchantDictionaryTestFixture
\r
60 EnchantPwlWithDictSuggs_TestFixture(const std::string& languageTag="qaa"):
\r
61 EnchantDictionaryTestFixture(DictionarySuggest_ProviderConfiguration, languageTag)
\r
65 struct EnchantPwl_TestFixture : EnchantDictionaryTestFixture
\r
68 EnchantPwl_TestFixture(const std::string& languageTag="qaa"):
\r
69 EnchantDictionaryTestFixture(EmptyDictionary_ProviderConfiguration, languageTag)
\r
73 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
74 GetSuggestionsFromWord_MultipleSuggestions_ReturnsOnlyClosest)
\r
76 std::vector<const std::string> sNoiseWords;
\r
77 sNoiseWords.push_back("spat");
\r
78 sNoiseWords.push_back("tots");
\r
79 sNoiseWords.push_back("tater");
\r
80 sNoiseWords.push_back("ton");
\r
81 sNoiseWords.push_back("gnat");
\r
83 std::vector<const std::string> sWords;
\r
84 sWords.push_back("cat");
\r
85 sWords.push_back("hat");
\r
86 sWords.push_back("that");
\r
87 sWords.push_back("bat");
\r
88 sWords.push_back("tot");
\r
90 AddWordsToDictionary(sWords);
\r
91 AddWordsToDictionary(sNoiseWords);
\r
93 std::vector<const std::string> suggestions = GetSuggestionsFromWord("tat");
\r
94 CHECK_EQUAL(sWords.size(), suggestions.size());
\r
96 std::sort(sWords.begin(), sWords.end());
\r
97 std::sort(suggestions.begin(), suggestions.end());
\r
99 CHECK_ARRAY_EQUAL(sWords, suggestions, std::min(sWords.size(), suggestions.size()));
\r
102 TEST_FIXTURE(EnchantPwlWithDictSuggs_TestFixture,
\r
103 GetSuggestionsFromWord_MultipleSuggestions_ReturnsOnlyAsCloseAsDict)
\r
105 std::vector<const std::string> sNoiseWords;
\r
106 sNoiseWords.push_back("spat");
\r
107 sNoiseWords.push_back("tots");
\r
108 sNoiseWords.push_back("tater");
\r
109 sNoiseWords.push_back("ton");
\r
110 sNoiseWords.push_back("gnat");
\r
112 std::vector<const std::string> sWords;
\r
113 sWords.push_back("cat");
\r
114 sWords.push_back("hat");
\r
115 sWords.push_back("that");
\r
116 sWords.push_back("bat");
\r
117 sWords.push_back("tot");
\r
119 AddWordsToDictionary(sWords);
\r
120 AddWordsToDictionary(sNoiseWords);
\r
122 std::vector<const std::string> suggestions = GetSuggestionsFromWord("tat");
\r
123 sWords.push_back("sat");
\r
124 CHECK_EQUAL(sWords.size(), suggestions.size());
\r
126 std::sort(sWords.begin(), sWords.end());
\r
127 std::sort(suggestions.begin(), suggestions.end());
\r
129 CHECK_ARRAY_EQUAL(sWords, suggestions, std::min(sWords.size(), suggestions.size()));
\r
132 /////////////////////////////////////////////////////////////////////////////////////////////////
\r
133 // External File change
\r
134 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
135 IsWordInDictionary_DictionaryChangedExternally_Successful)
\r
137 std::vector<const std::string> sWords;
\r
138 sWords.push_back("cat");
\r
139 sWords.push_back("hat");
\r
140 sWords.push_back("that");
\r
141 sWords.push_back("bat");
\r
142 sWords.push_back("tot");
\r
144 ExternalAddWordsToDictionary(sWords);
\r
146 for(std::vector<const std::string>::const_iterator itWord = sWords.begin(); itWord != sWords.end(); ++itWord){
\r
147 CHECK( IsWordInDictionary(*itWord) );
\r
150 std::vector<const std::string> sNewWords;
\r
151 sNewWords.push_back("potatoe");
\r
152 sNewWords.push_back("grow");
\r
153 sNewWords.push_back("another");
\r
155 ExternalAddNewLineToDictionary();
\r
156 ExternalAddWordsToDictionary(sNewWords);
\r
158 for(std::vector<const std::string>::const_iterator itWord = sNewWords.begin(); itWord != sNewWords.end(); ++itWord){
\r
159 CHECK( IsWordInDictionary(*itWord) );
\r
160 if(!IsWordInDictionary(*itWord)){
\r
161 testResults_.OnTestFailure(UnitTest::TestDetails(m_details, __LINE__), itWord->c_str());
\r
166 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
167 Suggest_DictionaryChangedExternally_Successful)
\r
169 std::vector<const std::string> sWords;
\r
170 sWords.push_back("cat");
\r
171 sWords.push_back("hat");
\r
172 sWords.push_back("that");
\r
173 sWords.push_back("bat");
\r
174 sWords.push_back("tot");
\r
176 ExternalAddWordsToDictionary(sWords);
\r
178 std::vector<const std::string> suggestions = GetSuggestionsFromWord("tat");
\r
180 CHECK_EQUAL(sWords.size(), suggestions.size());
\r
182 std::sort(sWords.begin(), sWords.end());
\r
183 std::sort(suggestions.begin(), suggestions.end());
\r
185 CHECK_ARRAY_EQUAL(sWords, suggestions, std::min(sWords.size(), suggestions.size()));
\r
189 /////////////////////////////////////////////////////////////////////////////////////////////////
\r
190 // DictionaryBeginsWithBOM
\r
191 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
192 IsWordInDictionary_DictionaryBeginsWithBOM_Successful)
\r
194 char* Utf8Bom = "\xef\xbb\xbf";
\r
196 Sleep(1000); // FAT systems have a 2 second resolution
\r
197 // NTFS is appreciably faster but no specs on what it is exactly
\r
198 // c runtime library's time_t has a 1 second resolution
\r
199 FILE * f = g_fopen(GetPersonalDictFileName().c_str(), "at");
\r
208 ReloadTestDictionary();
\r
210 CHECK( IsWordInDictionary("cat") );
\r
213 /////////////////////////////////////////////////////////////////////////////////////////////////
\r
214 // DictionaryHasInvalidUtf8
\r
215 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
216 IsWordInDictionary_DictionaryHasInvalidUtf8Data_OnlyReadsValidLines)
\r
218 std::vector<const std::string> sWords;
\r
219 sWords.push_back("cat");
\r
220 sWords.push_back("hat");
\r
221 sWords.push_back("that");
\r
222 sWords.push_back("bat");
\r
223 sWords.push_back("tot");
\r
225 std::vector<const std::string>::const_iterator bad = sWords.insert(sWords.begin()+2, "\xa5\xf1\x08"); //invalid utf8 data
\r
226 ExternalAddWordsToDictionary(sWords);
\r
228 ReloadTestDictionary();
\r
230 for(std::vector<const std::string>::const_iterator itWord = sWords.begin(); itWord != bad; ++itWord){
\r
231 CHECK( IsWordInDictionary(*itWord) );
\r
233 CHECK(!IsWordInDictionary(*bad) );
\r
235 for(std::vector<const std::string>::const_iterator itWord = bad+1; itWord != sWords.end(); ++itWord){
\r
236 CHECK(IsWordInDictionary(*itWord) );
\r
240 /////////////////////////////////////////////////////////////////////////////////////////////////
\r
241 // Last word in Dictionary terminated By EOF instead of NL
\r
242 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
243 IsWordInDictionary_LastWordNotTerminatedByNL_WordsAppendedOkay)
\r
245 std::vector<const std::string> sWords;
\r
246 sWords.push_back("cat");
\r
247 sWords.push_back("hat");
\r
248 sWords.push_back("that");
\r
249 sWords.push_back("bat");
\r
250 sWords.push_back("tot");
\r
252 Sleep(1000); // FAT systems have a 2 second resolution
\r
253 // NTFS is appreciably faster but no specs on what it is exactly
\r
254 // c runtime library's time_t has a 1 second resolution
\r
255 FILE * f = g_fopen(GetPersonalDictFileName().c_str(), "at");
\r
258 fputs(sWords[0].c_str(), f);
\r
262 for(std::vector<const std::string>::const_iterator itWord = sWords.begin() +1;
\r
263 itWord != sWords.end();
\r
266 AddWordToDictionary(*itWord);
\r
269 for(std::vector<const std::string>::const_iterator itWord = sWords.begin();
\r
270 itWord != sWords.end();
\r
272 CHECK( IsWordInDictionary(*itWord) );
\r
276 ////////////////////////////////////////////////////////////////////////////////////////////////
\r
278 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
279 GetSuggestions_DistanceUsesUnicodeChar)
\r
281 std::string puaWord("\xF4\x80\x80\x80ord"); // private use character
\r
282 AddWordToDictionary(puaWord); //edit distance 1 using unichar; 4 using utf8
\r
284 std::vector<const std::string> suggestions = GetSuggestionsFromWord("word");
\r
286 CHECK( !suggestions.empty());
\r
288 if(!suggestions.empty()){
\r
289 CHECK_EQUAL(puaWord, suggestions[0]);
\r
293 // Word which is prefix of another gets edit distance which is one less.
\r
294 // This means it moves to the top of the list normally but once we only bring
\r
295 // back the best matches, it means the rest of the mathes aren't returned
\r
296 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
297 PwlSuggest_EditDistanceOnWordWhichIsPrefixOfAnother)
\r
299 std::vector<const std::string> sNoiseWords;
\r
300 sNoiseWords.push_back("hastens"); //4
\r
302 std::vector<const std::string> sWords;
\r
303 sWords.push_back("cashes"); //3
\r
304 sWords.push_back("hasten"); //3
\r
305 sWords.push_back("washes"); //3
\r
307 AddWordsToDictionary(sWords);
\r
308 AddWordsToDictionary(sNoiseWords);
\r
310 std::vector<const std::string> suggestions = GetSuggestionsFromWord("saskep");
\r
311 CHECK(suggestions[0] != "hasten");
\r
312 CHECK_EQUAL(sWords.size(), suggestions.size());
\r
314 std::sort(sWords.begin(), sWords.end());
\r
315 std::sort(suggestions.begin(), suggestions.end());
\r
317 CHECK_ARRAY_EQUAL(sWords, suggestions, std::min(sWords.size(), suggestions.size()));
\r
321 /////////////////////////////////////////////////////////////////////////////////////////////////
\r
322 // Commented Lines ignored
\r
323 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
324 IsWordInDictionary_DictionaryHasCommentedLines_DoesNotReadCommentedLines)
\r
326 std::vector<const std::string> sWords;
\r
327 sWords.push_back("cat");
\r
328 sWords.push_back("hat");
\r
329 sWords.push_back("that");
\r
330 sWords.push_back("bat");
\r
331 sWords.push_back("tot");
\r
333 std::vector<const std::string>::const_iterator comment = sWords.insert(sWords.begin()+2, "#sat"); //comment
\r
334 ExternalAddWordsToDictionary(sWords);
\r
335 ReloadTestDictionary();
\r
337 for(std::vector<const std::string>::const_iterator itWord = sWords.begin(); itWord != comment; ++itWord){
\r
338 CHECK( IsWordInDictionary(*itWord) );
\r
341 CHECK(!IsWordInDictionary(*comment) );
\r
342 CHECK(!IsWordInDictionary("sat") );
\r
344 for(std::vector<const std::string>::const_iterator itWord = comment+1; itWord != sWords.end(); ++itWord){
\r
345 CHECK(IsWordInDictionary(*itWord) );
\r
349 /////////////////////////////////////////////////////////////////////////////////////////////////
\r
350 // Too long lines ignored
\r
351 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
352 IsWordInDictionary_DictionaryHasSuperLongLine_DoesNotReadLine)
\r
354 const size_t lineLen = 2048;
\r
356 std::vector<const std::string> sWords;
\r
357 sWords.push_back("cat");
\r
358 sWords.push_back("hat");
\r
359 sWords.push_back("that");
\r
360 sWords.push_back("bat");
\r
361 sWords.push_back("tot");
\r
363 std::vector<const std::string>::const_iterator superlong = sWords.insert(sWords.begin()+2, std::string(lineLen, 'c')); //super long line
\r
364 ExternalAddWordsToDictionary(sWords);
\r
365 ReloadTestDictionary();
\r
367 for(std::vector<const std::string>::const_iterator itWord = sWords.begin(); itWord != superlong; ++itWord){
\r
368 CHECK( IsWordInDictionary(*itWord) );
\r
371 CHECK(!IsWordInDictionary(*superlong) );
\r
372 for(size_t i=0; i != lineLen; ++i)
\r
374 CHECK(!IsWordInDictionary(std::string(i, 'c')) );
\r
377 for(std::vector<const std::string>::const_iterator itWord = superlong+1; itWord != sWords.end(); ++itWord){
\r
378 CHECK(IsWordInDictionary(*itWord) );
\r
382 /////////////////////////////////////////////////////////////////////////////////////////////////
\r
383 // Unicode normalization
\r
384 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
385 IsWordInDictionary_DictionaryHasComposed_SuccessfulCheckWithComposedAndDecomposed)
\r
387 ExternalAddWordToDictionary(Convert(L"fianc\xe9")); // u00e9 = Latin small letter e with acute
\r
389 ReloadTestDictionary();
\r
391 CHECK( IsWordInDictionary(Convert(L"fianc\xe9")) ); //NFC
\r
392 CHECK( IsWordInDictionary(Convert(L"fiance\x301")) ); //NFD u0301 = Combining acute accent
\r
395 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
396 IsWordInDictionary_AddedComposed_SuccessfulCheckWithComposedAndDecomposed)
\r
398 AddWordToDictionary(Convert(L"fianc\xe9")); // u00e9 = Latin small letter e with acute
\r
400 CHECK( IsWordInDictionary(Convert(L"fianc\xe9")) ); //NFC
\r
401 CHECK( IsWordInDictionary(Convert(L"fiance\x301")) ); //NFD u0301 = Combining acute accent
\r
404 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
405 IsWordInDictionary_DictionaryHasDecomposed_SuccessfulCheckWithComposedAndDecomposed)
\r
407 ExternalAddWordToDictionary(Convert(L"fiance\x301")); // u0301 = Combining acute accent
\r
409 ReloadTestDictionary();
\r
411 CHECK( IsWordInDictionary(Convert(L"fianc\xe9")) ); //NFC
\r
412 CHECK( IsWordInDictionary(Convert(L"fiance\x301")) ); //NFD
\r
415 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
416 IsWordInDictionary_AddedDecomposed_SuccessfulCheckWithComposedAndDecomposed)
\r
418 AddWordToDictionary(Convert(L"fiance\x301")); // u0301 = Combining acute accent
\r
420 CHECK( IsWordInDictionary(Convert(L"fianc\xe9")) ); //NFC
\r
421 CHECK( IsWordInDictionary(Convert(L"fiance\x301")) ); //NFD
\r
424 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
425 Suggest_DictionaryHasComposed_ReturnsComposed)
\r
427 ExternalAddWordToDictionary(Convert(L"fianc\xe9")); // u00e9 = Latin small letter e with acute
\r
429 ReloadTestDictionary();
\r
431 std::vector<const std::string> suggestions = GetSuggestionsFromWord("fiance");
\r
433 std::vector<const std::string> expected;
\r
434 expected.push_back(Convert(L"fianc\xe9")); // u00e9 = Latin small letter e with acute
\r
435 CHECK_EQUAL(expected.size(), suggestions.size());
\r
436 if(expected.size() == suggestions.size())
\r
438 CHECK_ARRAY_EQUAL(expected, suggestions, expected.size());
\r
442 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
443 Suggest_AddedComposed_ReturnsComposed)
\r
445 AddWordToDictionary(Convert(L"fianc\xe9")); // u00e9 = Latin small letter e with acute
\r
447 std::vector<const std::string> suggestions = GetSuggestionsFromWord("fiance");
\r
449 std::vector<const std::string> expected;
\r
450 expected.push_back(Convert(L"fianc\xe9")); // u00e9 = Latin small letter e with acute
\r
451 CHECK_EQUAL(expected.size(), suggestions.size());
\r
452 if(expected.size() == suggestions.size())
\r
454 CHECK_ARRAY_EQUAL(expected, suggestions, expected.size());
\r
458 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
459 Suggest_DictionaryHasDecomposed_ReturnsDecomposed)
\r
461 ExternalAddWordToDictionary(Convert(L"fiance\x301")); // u0301 = Combining acute accent
\r
463 ReloadTestDictionary();
\r
465 std::vector<const std::string> suggestions = GetSuggestionsFromWord("fiance");
\r
467 std::vector<const std::string> expected;
\r
468 expected.push_back(Convert(L"fiance\x301")); // u0301 = Combining acute accent
\r
469 CHECK_EQUAL(expected.size(), suggestions.size());
\r
470 if(expected.size() == suggestions.size())
\r
472 CHECK_ARRAY_EQUAL(expected, suggestions, expected.size());
\r
476 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
477 Suggest_AddedDecomposed_ReturnsDecomposed)
\r
479 AddWordToDictionary(Convert(L"fiance\x301")); // u0301 = Combining acute accent
\r
481 std::vector<const std::string> suggestions = GetSuggestionsFromWord("fiance");
\r
483 std::vector<const std::string> expected;
\r
484 expected.push_back(Convert(L"fiance\x301")); // u0301 = Combining acute accent
\r
485 CHECK_EQUAL(expected.size(), suggestions.size());
\r
486 if(expected.size() == suggestions.size())
\r
488 CHECK_ARRAY_EQUAL(expected, suggestions, expected.size());
\r
492 /////////////////////////////////////////////////////////////////////////////////////////////////
\r
494 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
495 IsWordInDictionary_AddedAllCaps_OnlyAllCapsSuccessful)
\r
497 AddWordToDictionary("CIA");
\r
499 CHECK( IsWordInDictionary("CIA") );
\r
500 CHECK(!IsWordInDictionary("CIa") );
\r
501 CHECK(!IsWordInDictionary("Cia") );
\r
502 CHECK(!IsWordInDictionary("cia") );
\r
503 CHECK(!IsWordInDictionary("cIa") );
\r
505 CHECK( IsWordInSession("CIA") );
\r
506 CHECK(!IsWordInSession("CIa") );
\r
507 CHECK(!IsWordInSession("Cia") );
\r
508 CHECK(!IsWordInSession("cia") );
\r
509 CHECK(!IsWordInSession("cIa") );
\r
512 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
513 IsWordInDictionary_AddedTitle_lowerCaseAndMixedCaseNotSuccessful)
\r
515 AddWordToDictionary("Eric");
\r
517 CHECK( IsWordInDictionary("ERIC") );
\r
518 CHECK(!IsWordInDictionary("ERic") );
\r
519 CHECK( IsWordInDictionary("Eric") );
\r
520 CHECK(!IsWordInDictionary("eric") );
\r
521 CHECK(!IsWordInDictionary("eRic") );
\r
523 CHECK( IsWordInSession("ERIC") );
\r
524 CHECK(!IsWordInSession("ERic") );
\r
525 CHECK( IsWordInSession("Eric") );
\r
526 CHECK(!IsWordInSession("eric") );
\r
527 CHECK(!IsWordInSession("eRic") );
\r
530 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
531 IsWordInDictionary_Addedlower_MixedCaseNotSuccessful)
\r
533 AddWordToDictionary("rice");
\r
535 CHECK( IsWordInDictionary("RICE") );
\r
536 CHECK(!IsWordInDictionary("RIce") );
\r
537 CHECK( IsWordInDictionary("Rice") );
\r
538 CHECK( IsWordInDictionary("rice") );
\r
539 CHECK(!IsWordInDictionary("rIce") );
\r
541 CHECK( IsWordInSession("RICE") );
\r
542 CHECK(!IsWordInSession("RIce") );
\r
543 CHECK( IsWordInSession("Rice") );
\r
544 CHECK( IsWordInSession("rice") );
\r
545 CHECK(!IsWordInSession("rIce") );
\r
548 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
549 IsWordInDictionary_AddedAllCapsOfTrueTitleCase_OnlyAllCapsSuccessful)
\r
551 AddWordToDictionary(Convert(L"\x01f1IE")); // u01f1 is Latin captial letter Dz
\r
553 CHECK( IsWordInDictionary(Convert(L"\x01f1IE")) ); // u01f1 is Latin captial letter Dz
\r
554 CHECK(!IsWordInDictionary(Convert(L"\x01f2IE")) ); // u01f2 is Latin capital letter d with small letter z
\r
555 CHECK(!IsWordInDictionary(Convert(L"\x01f2ie")) ); // u01f2 is Latin capital letter d with small letter z
\r
556 CHECK(!IsWordInDictionary(Convert(L"\x01f3ie")) ); // u01f3 is Latin small letter dz
\r
557 CHECK(!IsWordInDictionary(Convert(L"\x01f3Ie")) );
\r
559 CHECK( IsWordInSession(Convert(L"\x01f1IE")) ); // u01f1 is Latin captial letter Dz
\r
560 CHECK(!IsWordInSession(Convert(L"\x01f2IE")) ); // u01f2 is Latin capital letter d with small letter z
\r
561 CHECK(!IsWordInSession(Convert(L"\x01f2ie")) ); // u01f2 is Latin capital letter d with small letter z
\r
562 CHECK(!IsWordInSession(Convert(L"\x01f3ie")) ); // u01f3 is Latin small letter dz
\r
563 CHECK(!IsWordInSession(Convert(L"\x01f3Ie")) );
\r
566 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
567 IsWordInDictionary_AddedTrueTitleCase_lowerCaseAndMixedCaseNotSuccessful)
\r
569 AddWordToDictionary(Convert(L"\x01f2ie")); // u01f2 is Latin capital letter d with small letter z
\r
571 CHECK( IsWordInDictionary(Convert(L"\x01f1IE")) ); // u01f1 is Latin captial letter Dz
\r
572 CHECK(!IsWordInDictionary(Convert(L"\x01f2IE")) ); // u01f2 is Latin capital letter d with small letter z
\r
573 CHECK( IsWordInDictionary(Convert(L"\x01f2ie")) ); // u01f2 is Latin capital letter d with small letter z
\r
574 CHECK(!IsWordInDictionary(Convert(L"\x01f3ie")) ); // u01f3 is Latin small letter dz
\r
575 CHECK(!IsWordInDictionary(Convert(L"\x01f3Ie")) );
\r
577 CHECK( IsWordInSession(Convert(L"\x01f1IE")) ); // u01f1 is Latin captial letter Dz
\r
578 CHECK(!IsWordInSession(Convert(L"\x01f2IE")) ); // u01f2 is Latin capital letter d with small letter z
\r
579 CHECK( IsWordInSession(Convert(L"\x01f2ie")) ); // u01f2 is Latin capital letter d with small letter z
\r
580 CHECK(!IsWordInSession(Convert(L"\x01f3ie")) ); // u01f3 is Latin small letter dz
\r
581 CHECK(!IsWordInSession(Convert(L"\x01f3Ie")) );
\r
584 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
585 IsWordInDictionary_AddedLowerOfTrueTitleCase_MixedCaseNotSuccessful)
\r
587 AddWordToDictionary(Convert(L"\x01f3ie")); // u01f2 is Latin small letter dz
\r
589 CHECK( IsWordInDictionary(Convert(L"\x01f1IE")) ); // u01f1 is Latin captial letter Dz
\r
590 CHECK(!IsWordInDictionary(Convert(L"\x01f2IE")) ); // u01f2 is Latin capital letter d with small letter z
\r
591 CHECK( IsWordInDictionary(Convert(L"\x01f2ie")) ); // u01f2 is Latin capital letter d with small letter z
\r
592 CHECK( IsWordInDictionary(Convert(L"\x01f3ie")) ); // u01f3 is Latin small letter dz
\r
593 CHECK(!IsWordInDictionary(Convert(L"\x01f3Ie")) );
\r
595 CHECK( IsWordInSession(Convert(L"\x01f1IE")) ); // u01f1 is Latin captial letter Dz
\r
596 CHECK(!IsWordInSession(Convert(L"\x01f2IE")) ); // u01f2 is Latin capital letter d with small letter z
\r
597 CHECK( IsWordInSession(Convert(L"\x01f2ie")) ); // u01f2 is Latin capital letter d with small letter z
\r
598 CHECK( IsWordInSession(Convert(L"\x01f3ie")) ); // u01f3 is Latin small letter dz
\r
599 CHECK(!IsWordInSession(Convert(L"\x01f3Ie")) );
\r
602 ///////////////////////////////////////////////////////////////////////////////////////////
\r
603 // Capitalization on Suggestions
\r
604 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
605 GetSuggestions_AddedAllCaps_WordAllCaps_SuggestionAllCaps)
\r
607 AddWordToDictionary("CIA");
\r
609 std::vector<const std::string> suggestions = GetSuggestionsFromWord("CEA");
\r
611 std::vector<const std::string> expected;
\r
612 expected.push_back("CIA");
\r
613 CHECK_EQUAL(expected.size(), suggestions.size());
\r
614 if(expected.size() == suggestions.size())
\r
616 CHECK_ARRAY_EQUAL(expected, suggestions, expected.size());
\r
620 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
621 GetSuggestions_AddedAllCaps_WordTitleCase_SuggestionAllCaps)
\r
623 AddWordToDictionary("CIA");
\r
625 std::vector<const std::string> suggestions = GetSuggestionsFromWord("Cea");
\r
627 std::vector<const std::string> expected;
\r
628 expected.push_back("CIA");
\r
629 CHECK_EQUAL(expected.size(), suggestions.size());
\r
630 if(expected.size() == suggestions.size())
\r
632 CHECK_ARRAY_EQUAL(expected, suggestions, expected.size());
\r
636 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
637 GetSuggestions_AddedAllCaps_WordLowerCase_SuggestionAllCaps)
\r
639 AddWordToDictionary("CIA");
\r
641 std::vector<const std::string> suggestions = GetSuggestionsFromWord("cea");
\r
643 std::vector<const std::string> expected;
\r
644 expected.push_back("CIA");
\r
645 CHECK_EQUAL(expected.size(), suggestions.size());
\r
646 if(expected.size() == suggestions.size())
\r
648 CHECK_ARRAY_EQUAL(expected, suggestions, expected.size());
\r
652 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
653 GetSuggestions_AddedTitleCase_WordAllCaps_SuggestionAllCaps)
\r
655 AddWordToDictionary("Eric");
\r
657 std::vector<const std::string> suggestions = GetSuggestionsFromWord("RIC");
\r
659 std::vector<const std::string> expected;
\r
660 expected.push_back("ERIC");
\r
661 CHECK_EQUAL(expected.size(), suggestions.size());
\r
662 CHECK_ARRAY_EQUAL(expected, suggestions, expected.size());
\r
665 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
666 GetSuggestions_AddedTitleCase_WordTitleCase_SuggestionTitleCase)
\r
668 AddWordToDictionary("Eric");
\r
670 std::vector<const std::string> suggestions = GetSuggestionsFromWord("Ric");
\r
672 std::vector<const std::string> expected;
\r
673 expected.push_back("Eric");
\r
674 CHECK_EQUAL(expected.size(), suggestions.size());
\r
675 CHECK_ARRAY_EQUAL(expected, suggestions, expected.size());
\r
678 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
679 GetSuggestions_AddedTitleCase_WordLowerCase_SuggestionTitleCase)
\r
681 AddWordToDictionary("Eric");
\r
683 std::vector<const std::string> suggestions = GetSuggestionsFromWord("ric");
\r
685 std::vector<const std::string> expected;
\r
686 expected.push_back("Eric");
\r
687 CHECK_EQUAL(expected.size(), suggestions.size());
\r
688 CHECK_ARRAY_EQUAL(expected, suggestions, expected.size());
\r
691 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
692 GetSuggestions_AddedLowerCase_WordAllCaps_SuggestionAllCaps)
\r
694 AddWordToDictionary("rice");
\r
696 std::vector<const std::string> suggestions = GetSuggestionsFromWord("RIC");
\r
698 std::vector<const std::string> expected;
\r
699 expected.push_back("RICE");
\r
700 CHECK_EQUAL(expected.size(), suggestions.size());
\r
701 CHECK_ARRAY_EQUAL(expected, suggestions, expected.size());
\r
704 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
705 GetSuggestions_AddedLowerCase_WordTitleCase_SuggestionTitleCase)
\r
707 AddWordToDictionary("rice");
\r
709 std::vector<const std::string> suggestions = GetSuggestionsFromWord("Ric");
\r
711 std::vector<const std::string> expected;
\r
712 expected.push_back("Rice");
\r
713 CHECK_EQUAL(expected.size(), suggestions.size());
\r
714 CHECK_ARRAY_EQUAL(expected, suggestions, expected.size());
\r
717 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
718 GetSuggestions_AddedLowerCase_WordLowerCase_SuggestionLowerCase)
\r
720 AddWordToDictionary("rice");
\r
722 std::vector<const std::string> suggestions = GetSuggestionsFromWord("ric");
\r
724 std::vector<const std::string> expected;
\r
725 expected.push_back("rice");
\r
726 CHECK_EQUAL(expected.size(), suggestions.size());
\r
727 CHECK_ARRAY_EQUAL(expected, suggestions, expected.size());
\r
735 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
736 GetSuggestions_AddedAllCapsOfTrueTitleCase_WordAllCaps_SuggestionAllCaps)
\r
738 AddWordToDictionary(Convert(L"\x01f1IE")); // u01f1 is Latin captial letter Dz
\r
740 std::vector<const std::string> suggestions = GetSuggestionsFromWord("RIE");
\r
742 std::vector<const std::string> expected;
\r
743 expected.push_back(Convert(L"\x01f1IE")); // u01f1 is Latin captial letter Dz
\r
744 CHECK_EQUAL(expected.size(), suggestions.size());
\r
745 if(expected.size() == suggestions.size())
\r
747 CHECK_ARRAY_EQUAL(expected, suggestions, expected.size());
\r
751 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
752 GetSuggestions_AddedAllCapsOfTrueTitleCase_WordTitleCase_SuggestionAllCaps)
\r
754 AddWordToDictionary(Convert(L"\x01f1IE")); // u01f1 is Latin captial letter Dz
\r
756 std::vector<const std::string> suggestions = GetSuggestionsFromWord("Rie");
\r
758 std::vector<const std::string> expected;
\r
759 expected.push_back(Convert(L"\x01f1IE")); // u01f1 is Latin captial letter Dz
\r
760 CHECK_EQUAL(expected.size(), suggestions.size());
\r
761 if(expected.size() == suggestions.size())
\r
763 CHECK_ARRAY_EQUAL(expected, suggestions, expected.size());
\r
767 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
768 GetSuggestions_AddedAllCapsOfTrueTitleCase_WordLowerCase_SuggestionAllCaps)
\r
770 AddWordToDictionary(Convert(L"\x01f1IE")); // u01f1 is Latin captial letter Dz
\r
772 std::vector<const std::string> suggestions = GetSuggestionsFromWord("rie");
\r
774 std::vector<const std::string> expected;
\r
775 expected.push_back(Convert(L"\x01f1IE")); // u01f1 is Latin captial letter Dz
\r
776 CHECK_EQUAL(expected.size(), suggestions.size());
\r
777 if(expected.size() == suggestions.size())
\r
779 CHECK_ARRAY_EQUAL(expected, suggestions, expected.size());
\r
783 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
784 GetSuggestions_AddedTitleCaseOfTrueTitleCase_WordAllCaps_SuggestionAllCaps)
\r
786 AddWordToDictionary(Convert(L"\x01f2ie")); // u01f2 is Latin capital letter d with small letter z
\r
788 std::vector<const std::string> suggestions = GetSuggestionsFromWord("RIE");
\r
790 std::vector<const std::string> expected;
\r
791 expected.push_back(Convert(L"\x01f1IE")); // u01f1 is Latin captial letter Dz
\r
792 CHECK_EQUAL(expected.size(), suggestions.size());
\r
793 if(expected.size() == suggestions.size())
\r
795 CHECK_ARRAY_EQUAL(expected, suggestions, expected.size());
\r
799 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
800 GetSuggestions_AddedTitleCaseOfTrueTitleCase_WordTitleCase_SuggestionTitleCase)
\r
802 AddWordToDictionary(Convert(L"\x01f2ie")); // u01f2 is Latin capital letter d with small letter z
\r
804 std::vector<const std::string> suggestions = GetSuggestionsFromWord("Rie");
\r
806 std::vector<const std::string> expected;
\r
807 expected.push_back(Convert(L"\x01f2ie")); // u01f2 is Latin capital letter d with small letter z
\r
808 CHECK_EQUAL(expected.size(), suggestions.size());
\r
809 if(expected.size() == suggestions.size())
\r
811 CHECK_ARRAY_EQUAL(expected, suggestions, expected.size());
\r
815 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
816 GetSuggestions_AddedTitleCaseOfTrueTitleCase_WordLowerCase_SuggestionTitleCase)
\r
818 AddWordToDictionary(Convert(L"\x01f2ie")); // u01f2 is Latin capital letter d with small letter z
\r
820 std::vector<const std::string> suggestions = GetSuggestionsFromWord("rie");
\r
822 std::vector<const std::string> expected;
\r
823 expected.push_back(Convert(L"\x01f2ie")); // u01f2 is Latin capital letter d with small letter z
\r
824 CHECK_EQUAL(expected.size(), suggestions.size());
\r
825 if(expected.size() == suggestions.size())
\r
827 CHECK_ARRAY_EQUAL(expected, suggestions, expected.size());
\r
831 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
832 GetSuggestions_AddedLowerCaseOfTrueTitleCase_WordAllCaps_SuggestionAllCaps)
\r
834 AddWordToDictionary(Convert(L"\x01f3ie")); // u01f3 is Latin small letter dz
\r
836 std::vector<const std::string> suggestions = GetSuggestionsFromWord("RIE");
\r
838 std::vector<const std::string> expected;
\r
839 expected.push_back(Convert(L"\x01f1IE")); // u01f1 is Latin captial letter Dz
\r
840 CHECK_EQUAL(expected.size(), suggestions.size());
\r
841 if(expected.size() == suggestions.size())
\r
843 CHECK_ARRAY_EQUAL(expected, suggestions, expected.size());
\r
847 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
848 GetSuggestions_AddedLowerCaseOfTrueTitleCase_WordTitleCase_SuggestionTitleCase)
\r
850 AddWordToDictionary(Convert(L"\x01f3ie")); // u01f3 is Latin small letter dz
\r
852 std::vector<const std::string> suggestions = GetSuggestionsFromWord("Rie");
\r
854 std::vector<const std::string> expected;
\r
855 expected.push_back(Convert(L"\x01f2ie")); // u01f2 is Latin capital letter d with small letter z
\r
856 CHECK_EQUAL(expected.size(), suggestions.size());
\r
857 if(expected.size() == suggestions.size())
\r
859 CHECK_ARRAY_EQUAL(expected, suggestions, expected.size());
\r
863 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
864 GetSuggestions_AddedLowerCaseOfTrueTitleCase_WordLowerCase_SuggestionLowerCase)
\r
866 AddWordToDictionary(Convert(L"\x01f3ie")); // u01f3 is Latin small letter dz
\r
868 std::vector<const std::string> suggestions = GetSuggestionsFromWord("rie");
\r
870 std::vector<const std::string> expected;
\r
871 expected.push_back(Convert(L"\x01f3ie")); // u01f3 is Latin small letter dz
\r
872 CHECK_EQUAL(expected.size(), suggestions.size());
\r
873 if(expected.size() == suggestions.size())
\r
875 CHECK_ARRAY_EQUAL(expected, suggestions, expected.size());
\r
880 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
881 GetSuggestions_AddedAllCapsWithPrefix_WordLowerCase_SuggestionAllCaps)
\r
883 AddWordToDictionary("CIAL");
\r
884 AddWordToDictionary("CIALAND");
\r
886 std::vector<const std::string> suggestions = GetSuggestionsFromWord("ceal");
\r
888 std::vector<const std::string> expected;
\r
889 expected.push_back("CIAL");
\r
890 CHECK_EQUAL(expected.size(), suggestions.size());
\r
891 if(expected.size() == suggestions.size())
\r
893 CHECK_ARRAY_EQUAL(expected, suggestions, expected.size());
\r
897 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
898 GetSuggestions_AddedTitleCaseWithPrefix_WordLowerCase_SuggestionTitlecase)
\r
900 AddWordToDictionary("Eric");
\r
901 AddWordToDictionary("Ericson");
\r
903 std::vector<const std::string> suggestions = GetSuggestionsFromWord("eruc");
\r
905 std::vector<const std::string> expected;
\r
906 expected.push_back("Eric");
\r
907 CHECK_EQUAL(expected.size(), suggestions.size());
\r
908 if(expected.size() == suggestions.size())
\r
910 CHECK_ARRAY_EQUAL(expected, suggestions, expected.size());
\r
914 /////////////////////////////////////////////////////////////////////////////
\r
916 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
917 PwlRemove_SharedPrefix1)
\r
919 AddWordToDictionary("help");
\r
920 AddWordToDictionary("hello");
\r
922 CHECK( IsWordInDictionary("help") );
\r
923 CHECK( IsWordInDictionary("hello") );
\r
925 RemoveWordFromDictionary("help");
\r
927 CHECK(!IsWordInDictionary("help") );
\r
928 CHECK( IsWordInDictionary("hello") );
\r
931 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
932 PwlRemove_SharedPrefix2)
\r
934 AddWordToDictionary("help");
\r
935 AddWordToDictionary("hello");
\r
937 CHECK( IsWordInDictionary("help") );
\r
938 CHECK( IsWordInDictionary("hello") );
\r
940 RemoveWordFromDictionary("hello");
\r
942 CHECK( IsWordInDictionary("help") );
\r
943 CHECK(!IsWordInDictionary("hello") );
\r
946 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
947 PwlRemove_SharedPrefix3)
\r
949 AddWordToDictionary("help");
\r
950 AddWordToDictionary("hello");
\r
951 AddWordToDictionary("helm");
\r
953 CHECK( IsWordInDictionary("help") );
\r
954 CHECK( IsWordInDictionary("hello") );
\r
955 CHECK( IsWordInDictionary("helm") );
\r
957 RemoveWordFromDictionary("hello");
\r
959 CHECK( IsWordInDictionary("help") );
\r
960 CHECK(!IsWordInDictionary("hello") );
\r
961 CHECK( IsWordInDictionary("helm") );
\r
964 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
965 PwlRemove_SharedPrefix4)
\r
967 AddWordToDictionary("help");
\r
968 AddWordToDictionary("hello");
\r
969 AddWordToDictionary("helm");
\r
971 CHECK( IsWordInDictionary("help") );
\r
972 CHECK( IsWordInDictionary("hello") );
\r
973 CHECK( IsWordInDictionary("helm") );
\r
975 RemoveWordFromDictionary("help");
\r
977 CHECK(!IsWordInDictionary("help") );
\r
978 CHECK( IsWordInDictionary("hello") );
\r
979 CHECK( IsWordInDictionary("helm") );
\r
982 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
983 PwlRemove_SingleWord)
\r
985 AddWordToDictionary("hello");
\r
987 CHECK( IsWordInDictionary("hello") );
\r
989 RemoveWordFromDictionary("hello");
\r
991 CHECK(!IsWordInDictionary("hello") );
\r
994 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
995 PwlRemove_MultipleWords1)
\r
997 AddWordToDictionary("special");
\r
998 AddWordToDictionary("hello");
\r
1000 CHECK( IsWordInDictionary("special") );
\r
1001 CHECK( IsWordInDictionary("hello") );
\r
1003 RemoveWordFromDictionary("hello");
\r
1005 CHECK( IsWordInDictionary("special") );
\r
1006 CHECK(!IsWordInDictionary("hello") );
\r
1009 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
1010 PwlRemove_MultipleWords2)
\r
1012 AddWordToDictionary("special");
\r
1013 AddWordToDictionary("hello");
\r
1015 CHECK( IsWordInDictionary("special") );
\r
1016 CHECK( IsWordInDictionary("hello") );
\r
1018 RemoveWordFromDictionary("special");
\r
1020 CHECK(!IsWordInDictionary("special") );
\r
1021 CHECK( IsWordInDictionary("hello") );
\r
1024 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
1025 PwlRemove_ProperPrefix1)
\r
1027 AddWordToDictionary("ant");
\r
1028 AddWordToDictionary("anteater");
\r
1030 CHECK( IsWordInDictionary("ant") );
\r
1031 CHECK( IsWordInDictionary("anteater") );
\r
1033 RemoveWordFromDictionary("ant");
\r
1035 CHECK(!IsWordInDictionary("ant") );
\r
1036 CHECK( IsWordInDictionary("anteater") );
\r
1039 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
1040 PwlRemove_ProperPrefix2)
\r
1042 AddWordToDictionary("anteater");
\r
1043 AddWordToDictionary("ant");
\r
1045 CHECK( IsWordInDictionary("ant") );
\r
1046 CHECK( IsWordInDictionary("anteater") );
\r
1048 RemoveWordFromDictionary("ant");
\r
1050 CHECK(!IsWordInDictionary("ant") );
\r
1051 CHECK( IsWordInDictionary("anteater") );
\r
1054 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
1055 PwlRemove_ProperPrefix3)
\r
1057 AddWordToDictionary("ant");
\r
1058 AddWordToDictionary("anteater");
\r
1060 CHECK( IsWordInDictionary("ant") );
\r
1061 CHECK( IsWordInDictionary("anteater") );
\r
1063 RemoveWordFromDictionary("anteater");
\r
1065 CHECK( IsWordInDictionary("ant") );
\r
1066 CHECK(!IsWordInDictionary("anteater") );
\r
1069 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
1070 PwlRemove_ProperPrefix4)
\r
1072 AddWordToDictionary("anteater");
\r
1073 AddWordToDictionary("ant");
\r
1075 CHECK( IsWordInDictionary("ant") );
\r
1076 CHECK( IsWordInDictionary("anteater") );
\r
1078 RemoveWordFromDictionary("anteater");
\r
1080 CHECK( IsWordInDictionary("ant") );
\r
1081 CHECK(!IsWordInDictionary("anteater") );
\r
1084 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
1085 PwlRemove_ItemRemovedFromFile)
\r
1087 std::vector<const std::string> sWords;
\r
1088 sWords.push_back("cat");
\r
1089 sWords.push_back("hat");
\r
1090 sWords.push_back("that");
\r
1091 sWords.push_back("bat");
\r
1092 sWords.push_back("tot");
\r
1094 std::vector<const std::string>::const_iterator removed = sWords.insert(sWords.begin()+2, "hello");
\r
1095 AddWordsToDictionary(sWords);
\r
1097 RemoveWordFromDictionary("hello");
\r
1099 ReloadTestDictionary(); // to see what actually persisted
\r
1101 for(std::vector<const std::string>::const_iterator itWord = sWords.begin(); itWord != removed; ++itWord){
\r
1102 CHECK( IsWordInDictionary(*itWord) );
\r
1104 CHECK(!IsWordInDictionary(*removed) );
\r
1106 for(std::vector<const std::string>::const_iterator itWord = removed+1; itWord != sWords.end(); ++itWord){
\r
1107 CHECK(IsWordInDictionary(*itWord) );
\r
1111 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
1112 PwlRemove_ItemRemovedFromBeginningOfFile)
\r
1114 std::vector<const std::string> sWords;
\r
1115 sWords.push_back("cat");
\r
1116 sWords.push_back("hat");
\r
1117 sWords.push_back("that");
\r
1118 sWords.push_back("bat");
\r
1119 sWords.push_back("tot");
\r
1121 std::vector<const std::string>::const_iterator removed = sWords.insert(sWords.begin(), "hello");
\r
1122 AddWordsToDictionary(sWords);
\r
1124 RemoveWordFromDictionary("hello");
\r
1126 ReloadTestDictionary(); // to see what actually persisted
\r
1128 CHECK(!IsWordInDictionary(*removed) );
\r
1130 for(std::vector<const std::string>::const_iterator itWord = removed+1; itWord != sWords.end(); ++itWord){
\r
1131 CHECK(IsWordInDictionary(*itWord) );
\r
1135 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
1136 PwlRemove_ItemRemovedFromBeginningOfFileWithBOM)
\r
1138 char* Utf8Bom = "\xef\xbb\xbf";
\r
1140 std::vector<const std::string> sWords;
\r
1141 sWords.push_back("hello");
\r
1142 sWords.push_back("cat");
\r
1143 sWords.push_back("hat");
\r
1145 Sleep(1000); // FAT systems have a 2 second resolution
\r
1146 // NTFS is appreciably faster but no specs on what it is exactly
\r
1147 // c runtime library's time_t has a 1 second resolution
\r
1148 FILE * f = g_fopen(GetPersonalDictFileName().c_str(), "at");
\r
1151 fputs(Utf8Bom, f);
\r
1152 for(std::vector<const std::string>::const_iterator
\r
1153 itWord = sWords.begin();
\r
1154 itWord != sWords.end();
\r
1157 if(itWord != sWords.begin()){
\r
1160 fputs(itWord->c_str(), f);
\r
1165 RemoveWordFromDictionary("hello");
\r
1167 ReloadTestDictionary(); // to see what actually persisted
\r
1169 CHECK(!IsWordInDictionary("hello") );
\r
1171 for(std::vector<const std::string>::const_iterator itWord = sWords.begin()+1; itWord != sWords.end(); ++itWord){
\r
1172 CHECK(IsWordInDictionary(*itWord) );
\r
1176 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
1177 PwlRemove_ItemRemovedFromEndOfFile)
\r
1179 std::vector<const std::string> sWords;
\r
1180 sWords.push_back("cat");
\r
1181 sWords.push_back("hat");
\r
1182 sWords.push_back("that");
\r
1183 sWords.push_back("bat");
\r
1184 sWords.push_back("tot");
\r
1186 std::vector<const std::string>::const_iterator removed = sWords.insert(sWords.end(), "hello");
\r
1187 AddWordsToDictionary(sWords);
\r
1189 RemoveWordFromDictionary("hello");
\r
1191 ReloadTestDictionary(); // to see what actually persisted
\r
1193 for(std::vector<const std::string>::const_iterator itWord = sWords.begin(); itWord != removed; ++itWord){
\r
1194 CHECK( IsWordInDictionary(*itWord) );
\r
1196 CHECK(!IsWordInDictionary(*removed) );
\r
1199 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
1200 PwlRemove_ItemRemovedFromEndOfFile_ExternalSetup)
\r
1202 std::vector<const std::string> sWords;
\r
1203 sWords.push_back("cat");
\r
1204 sWords.push_back("hat");
\r
1205 sWords.push_back("that");
\r
1206 sWords.push_back("bat");
\r
1207 sWords.push_back("tot");
\r
1209 std::vector<const std::string>::const_iterator removed = sWords.insert(sWords.end(), "hello");
\r
1210 ExternalAddWordsToDictionary(sWords);
\r
1212 RemoveWordFromDictionary("hello");
\r
1214 ReloadTestDictionary(); // to see what actually persisted
\r
1216 for(std::vector<const std::string>::const_iterator itWord = sWords.begin(); itWord != removed; ++itWord){
\r
1217 CHECK( IsWordInDictionary(*itWord) );
\r
1219 CHECK(!IsWordInDictionary(*removed) );
\r
1222 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
1223 PwlRemove_FileHasProperSubset_ItemRemovedFromFile)
\r
1225 std::vector<const std::string> sWords;
\r
1226 sWords.push_back("cat");
\r
1227 sWords.push_back("hat");
\r
1228 sWords.push_back("that");
\r
1229 sWords.push_back("bat");
\r
1230 sWords.push_back("tot");
\r
1231 sWords.push_back("anteater");
\r
1233 std::vector<const std::string>::const_iterator removed = sWords.insert(sWords.end(), "ant");
\r
1234 AddWordsToDictionary(sWords);
\r
1235 RemoveWordFromDictionary("ant");
\r
1237 ReloadTestDictionary(); // to see what actually persisted
\r
1239 for(std::vector<const std::string>::const_iterator itWord = sWords.begin(); itWord != removed; ++itWord){
\r
1240 CHECK( IsWordInDictionary(*itWord) );
\r
1242 CHECK(!IsWordInDictionary(*removed) );
\r
1245 //////////////////////////////////////////////////////////////////////////////////////////////////////////
\r
1246 // Pwl Edit distance
\r
1247 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
1248 PwlSuggest_HasProperSubset_SubstituteFirstChar)
\r
1250 std::vector<const std::string> sWords;
\r
1251 sWords.push_back("cat"); //1
\r
1253 AddWordsToDictionary(sWords);
\r
1255 AddWordToDictionary("catsup"); //4
\r
1257 std::vector<const std::string> suggestions = GetSuggestionsFromWord("tat");
\r
1259 CHECK_EQUAL(sWords.size(), suggestions.size());
\r
1261 std::sort(sWords.begin(), sWords.end());
\r
1262 std::sort(suggestions.begin(), suggestions.end());
\r
1264 CHECK_ARRAY_EQUAL(sWords, suggestions, std::min(sWords.size(), suggestions.size()));
\r
1267 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
1268 PwlSuggest_HasProperSubset_SubstituteFirstChar_Insert1)
\r
1270 std::vector<const std::string> sWords;
\r
1271 sWords.push_back("cats"); //2
\r
1273 AddWordsToDictionary(sWords);
\r
1275 AddWordToDictionary("catsup"); //4
\r
1277 std::vector<const std::string> suggestions = GetSuggestionsFromWord("tat");
\r
1279 CHECK_EQUAL(sWords.size(), suggestions.size());
\r
1281 std::sort(sWords.begin(), sWords.end());
\r
1282 std::sort(suggestions.begin(), suggestions.end());
\r
1284 CHECK_ARRAY_EQUAL(sWords, suggestions, std::min(sWords.size(), suggestions.size()));
\r
1287 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
1288 PwlSuggest_HasProperSubset_SubstituteFirstChar_Insert2)
\r
1290 std::vector<const std::string> sWords;
\r
1291 sWords.push_back("catch"); //3
\r
1293 AddWordsToDictionary(sWords);
\r
1295 AddWordToDictionary("catchy"); //4
\r
1297 std::vector<const std::string> suggestions = GetSuggestionsFromWord("tat");
\r
1299 CHECK_EQUAL(sWords.size(), suggestions.size());
\r
1301 std::sort(sWords.begin(), sWords.end());
\r
1302 std::sort(suggestions.begin(), suggestions.end());
\r
1304 CHECK_ARRAY_EQUAL(sWords, suggestions, std::min(sWords.size(), suggestions.size()));
\r
1307 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
1308 PwlSuggest_HasProperSubset_Insert1)
\r
1310 std::vector<const std::string> sWords;
\r
1311 sWords.push_back("tad"); //1
\r
1313 AddWordsToDictionary(sWords);
\r
1315 AddWordToDictionary("taddle"); //4
\r
1317 std::vector<const std::string> suggestions = GetSuggestionsFromWord("ta");
\r
1319 CHECK_EQUAL(sWords.size(), suggestions.size());
\r
1321 std::sort(sWords.begin(), sWords.end());
\r
1322 std::sort(suggestions.begin(), suggestions.end());
\r
1324 CHECK_ARRAY_EQUAL(sWords, suggestions, std::min(sWords.size(), suggestions.size()));
\r
1327 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
1328 PwlSuggest_HasProperSubset_Insert2)
\r
1330 std::vector<const std::string> sWords;
\r
1331 sWords.push_back("tote"); //2
\r
1333 AddWordsToDictionary(sWords);
\r
1335 AddWordToDictionary("totems"); //4
\r
1337 std::vector<const std::string> suggestions = GetSuggestionsFromWord("to");
\r
1339 CHECK_EQUAL(sWords.size(), suggestions.size());
\r
1341 std::sort(sWords.begin(), sWords.end());
\r
1342 std::sort(suggestions.begin(), suggestions.end());
\r
1344 CHECK_ARRAY_EQUAL(sWords, suggestions, std::min(sWords.size(), suggestions.size()));
\r
1346 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
1347 PwlSuggest_HasProperSubset_Insert3)
\r
1349 std::vector<const std::string> sWords;
\r
1350 sWords.push_back("catch"); //3
\r
1352 AddWordsToDictionary(sWords);
\r
1354 AddWordToDictionary("catchy"); //4
\r
1356 std::vector<const std::string> suggestions = GetSuggestionsFromWord("ca");
\r
1358 CHECK_EQUAL(sWords.size(), suggestions.size());
\r
1360 std::sort(sWords.begin(), sWords.end());
\r
1361 std::sort(suggestions.begin(), suggestions.end());
\r
1363 CHECK_ARRAY_EQUAL(sWords, suggestions, std::min(sWords.size(), suggestions.size()));
\r
1365 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
1366 PwlSuggest_HasProperSubset_Delete1)
\r
1368 std::vector<const std::string> sWords;
\r
1369 sWords.push_back("tape"); //1
\r
1371 AddWordsToDictionary(sWords);
\r
1373 AddWordToDictionary("tapestry"); //4
\r
1375 std::vector<const std::string> suggestions = GetSuggestionsFromWord("tapen");
\r
1377 CHECK_EQUAL(sWords.size(), suggestions.size());
\r
1379 std::sort(sWords.begin(), sWords.end());
\r
1380 std::sort(suggestions.begin(), suggestions.end());
\r
1382 CHECK_ARRAY_EQUAL(sWords, suggestions, std::min(sWords.size(), suggestions.size()));
\r
1385 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
1386 PwlSuggest_HasProperSubset_Delete2)
\r
1388 std::vector<const std::string> sWords;
\r
1389 sWords.push_back("tot"); //2
\r
1391 AddWordsToDictionary(sWords);
\r
1393 AddWordToDictionary("totality"); //4
\r
1395 std::vector<const std::string> suggestions = GetSuggestionsFromWord("totil");
\r
1397 CHECK_EQUAL(sWords.size(), suggestions.size());
\r
1399 std::sort(sWords.begin(), sWords.end());
\r
1400 std::sort(suggestions.begin(), suggestions.end());
\r
1402 CHECK_ARRAY_EQUAL(sWords, suggestions, std::min(sWords.size(), suggestions.size()));
\r
1404 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
1405 PwlSuggest_HasProperSubset_Delete3)
\r
1407 std::vector<const std::string> sWords;
\r
1408 sWords.push_back("cat"); //3
\r
1410 AddWordsToDictionary(sWords);
\r
1412 AddWordToDictionary("catcher"); //4
\r
1414 std::vector<const std::string> suggestions = GetSuggestionsFromWord("catsip");
\r
1416 CHECK_EQUAL(sWords.size(), suggestions.size());
\r
1418 std::sort(sWords.begin(), sWords.end());
\r
1419 std::sort(suggestions.begin(), suggestions.end());
\r
1421 CHECK_ARRAY_EQUAL(sWords, suggestions, std::min(sWords.size(), suggestions.size()));
\r
1424 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
1425 PwlSuggest_HasProperSubset_Substitute1)
\r
1427 std::vector<const std::string> sWords;
\r
1428 sWords.push_back("small"); //1
\r
1430 AddWordsToDictionary(sWords);
\r
1432 AddWordToDictionary("smallest"); //4
\r
1434 std::vector<const std::string> suggestions = GetSuggestionsFromWord("skall");
\r
1436 CHECK_EQUAL(sWords.size(), suggestions.size());
\r
1438 std::sort(sWords.begin(), sWords.end());
\r
1439 std::sort(suggestions.begin(), suggestions.end());
\r
1441 CHECK_ARRAY_EQUAL(sWords, suggestions, std::min(sWords.size(), suggestions.size()));
\r
1444 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
1445 PwlSuggest_HasProperSubset_Substitute2)
\r
1447 std::vector<const std::string> sWords;
\r
1448 sWords.push_back("catch"); //2
\r
1450 AddWordsToDictionary(sWords);
\r
1452 AddWordToDictionary("catcher"); //4
\r
1454 std::vector<const std::string> suggestions = GetSuggestionsFromWord("cafdh");
\r
1456 CHECK_EQUAL(sWords.size(), suggestions.size());
\r
1458 std::sort(sWords.begin(), sWords.end());
\r
1459 std::sort(suggestions.begin(), suggestions.end());
\r
1461 CHECK_ARRAY_EQUAL(sWords, suggestions, std::min(sWords.size(), suggestions.size()));
\r
1464 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
1465 PwlSuggest_HasProperSubset_Substitute3)
\r
1467 std::vector<const std::string> sWords;
\r
1468 sWords.push_back("hasten"); //3
\r
1470 AddWordsToDictionary(sWords);
\r
1472 AddWordToDictionary("hastens"); //4
\r
1474 std::vector<const std::string> suggestions = GetSuggestionsFromWord("hasopo");
\r
1476 CHECK_EQUAL(sWords.size(), suggestions.size());
\r
1478 std::sort(sWords.begin(), sWords.end());
\r
1479 std::sort(suggestions.begin(), suggestions.end());
\r
1481 CHECK_ARRAY_EQUAL(sWords, suggestions, std::min(sWords.size(), suggestions.size()));
\r
1484 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
1485 PwlSuggest_HasProperSubset_Transpose1)
\r
1487 std::vector<const std::string> sWords;
\r
1488 sWords.push_back("small"); //1
\r
1490 AddWordsToDictionary(sWords);
\r
1492 AddWordToDictionary("smallest"); //4
\r
1494 std::vector<const std::string> suggestions = GetSuggestionsFromWord("smlal");
\r
1496 CHECK_EQUAL(sWords.size(), suggestions.size());
\r
1498 std::sort(sWords.begin(), sWords.end());
\r
1499 std::sort(suggestions.begin(), suggestions.end());
\r
1501 CHECK_ARRAY_EQUAL(sWords, suggestions, std::min(sWords.size(), suggestions.size()));
\r
1504 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
1505 PwlSuggest_HasProperSubset_Transpose2)
\r
1507 std::vector<const std::string> sWords;
\r
1508 sWords.push_back("catch"); //2
\r
1510 AddWordsToDictionary(sWords);
\r
1512 AddWordToDictionary("catcher"); //4
\r
1514 std::vector<const std::string> suggestions = GetSuggestionsFromWord("acthc");
\r
1516 CHECK_EQUAL(sWords.size(), suggestions.size());
\r
1518 std::sort(sWords.begin(), sWords.end());
\r
1519 std::sort(suggestions.begin(), suggestions.end());
\r
1521 CHECK_ARRAY_EQUAL(sWords, suggestions, std::min(sWords.size(), suggestions.size()));
\r
1524 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
1525 PwlSuggest_HasProperSubset_Transpose3)
\r
1527 std::vector<const std::string> sWords;
\r
1528 sWords.push_back("hasten"); //3
\r
1530 AddWordsToDictionary(sWords);
\r
1532 AddWordToDictionary("hastens"); //4
\r
1534 std::vector<const std::string> suggestions = GetSuggestionsFromWord("ahtsne");
\r
1536 CHECK_EQUAL(sWords.size(), suggestions.size());
\r
1538 std::sort(sWords.begin(), sWords.end());
\r
1539 std::sort(suggestions.begin(), suggestions.end());
\r
1541 CHECK_ARRAY_EQUAL(sWords, suggestions, std::min(sWords.size(), suggestions.size()));
\r
1544 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
1545 PwlSuggest_Transpose1Insert2)
\r
1547 std::vector<const std::string> sWords;
\r
1548 sWords.push_back("catch"); //3
\r
1550 AddWordsToDictionary(sWords);
\r
1552 std::vector<const std::string> suggestions = GetSuggestionsFromWord("act");
\r
1554 CHECK_EQUAL(sWords.size(), suggestions.size());
\r
1556 std::sort(sWords.begin(), sWords.end());
\r
1557 std::sort(suggestions.begin(), suggestions.end());
\r
1559 CHECK_ARRAY_EQUAL(sWords, suggestions, std::min(sWords.size(), suggestions.size()));
\r
1562 TEST_FIXTURE(EnchantPwl_TestFixture,
\r
1563 PwlSuggest_Transpose2)
\r
1565 std::vector<const std::string> sWords;
\r
1566 sWords.push_back("catch"); //2
\r
1568 AddWordsToDictionary(sWords);
\r
1570 std::vector<const std::string> suggestions = GetSuggestionsFromWord("acthc");
\r
1572 CHECK_EQUAL(sWords.size(), suggestions.size());
\r
1574 std::sort(sWords.begin(), sWords.end());
\r
1575 std::sort(suggestions.begin(), suggestions.end());
\r
1577 CHECK_ARRAY_EQUAL(sWords, suggestions, std::min(sWords.size(), suggestions.size()));
\r