/* Copyright (C) 2008-2012 Børre Gaup This file is part of the program wordlist2hunspell. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #define private public // dirty trick to make private functions available for testing :D // place includes for classes that should be test below this line #include "../hunspellprinternocompounding.h" #include "../wordlistparsernocompound.h" extern std::istream* setupinputfile(); extern void debugoutputIntSetSet(std::set< std::set > intsetset); extern void debugoutputIntMapSetSet(std::map< std::set, std::set > intmapsetset); extern void debugoutputIntMapSet(std::map > afMap); extern void debugoutputAfMap(std::map< std::set, int> afMap); std::map setuphmhmnocompounding() { std::map plxclasses; int i = 1; plxclasses.insert(std::pair("I", i)); ++i; plxclasses.insert(std::pair("X", i)); ++i; return plxclasses; } std::string setupafmapnocompounding() { std::stringstream s; s << "AF 21" << std::endl; s << "AF 65006,65009 # 1" << std::endl; s << "AF 65006 # 2" << std::endl; s << "AF 1,2,3,4,65008 # 3" << std::endl; s << "AF 2,65008 # 4" << std::endl; s << "AF 2,3,65008 # 5" << std::endl; s << "AF 3,65008 # 6" << std::endl; s << "AF 3,4,65008 # 7" << std::endl; s << "AF 3,4,8,9,65008 # 8" << std::endl; s << "AF 3,5,65008 # 9" << std::endl; s << "AF 3,16,65008 # 10" << std::endl; s << "AF 4,65008 # 11" << std::endl; s << "AF 4,8,65008 # 12" << std::endl; s << "AF 5,65008 # 13" << std::endl; s << "AF 6,65008 # 14" << std::endl; s << "AF 7,65008 # 15" << std::endl; s << "AF 10,65008 # 16" << std::endl; s << "AF 11,65008 # 17" << std::endl; s << "AF 12,65008 # 18" << std::endl; s << "AF 13,65008 # 19" << std::endl; s << "AF 14,65008 # 20" << std::endl; s << "AF 15,65008 # 21" << std::endl; s << std::endl; return s.str(); } TEST(NoCompoundPrintAfflist) { std::map wantAffMap; std::map wantStemMap; std::istream* inputfile = setupinputfile(); WordlistParserNoCompound wp; wp.processFile(inputfile); HunspellPrinterNoCompounding hp("tst"); std::map got = hp.preparePLXClasses(wp.getPlxClasses()); std::map want = setuphmhmnocompounding(); CHECK_EQUAL(want.size(), got.size()); CHECK(equal(want.begin(), want.end(), got.begin())); SetOptimizer so(wp.getSuffixSetStemSet()); hp.prepareAfmap(so.giveSubsetsToStems()); CHECK_EQUAL(setupafmapnocompounding(), hp.printAfflist()); } TEST(NoCompoundTestPrintStems) { std::map wantAffMap; std::map wantStemMap; std::istream* inputfile = setupinputfile(); WordlistParserNoCompound wp; wp.processFile(inputfile); HunspellPrinterNoCompounding hp("tst"); std::map hmhm = hp.preparePLXClasses(wp.getPlxClasses()); SetOptimizer so(wp.getSuffixSetStemSet()); hp.prepareAfmap(so.giveSubsetsToStems()); std::string wantStems("33\n100000-geardásačča/3\n100000-geardásaš/7\n10000-geardásačča/5\n10000-geardásaš/6\n1000-geardásačča/4\n1000-geardásaš/6\n10-Đ/9\n10-Đ-/14\n1-D/6\n1-D-/14\n2-C/6\n2-C-/14\n3-juvllatsihkkel/15\n7. juni-plassen/8\nAabakken/12\nAabel/11\nabandonere/16\naborigiinnalačča/17\nabsoluhta/18\nabsoluhtalačča/17\naddinbeai/11\nadvokáhta gukto/19\nagibeai/11\na./20\nalmmustusbeai/11\nas/13\nčuohpan/21\ndáppe/14\ndieppe/14\ndoppe/14\nNSR/10\n"); wantStems += hp.makeDicEasterEgg(); CHECK_EQUAL(wantStems, hp.makeDicString(wp.getStems())); } TEST(NoCompoundPrintSuffixes) { std::string wantSuffixes("SFX 1 Y 3\nSFX 1 0 ide/1 . I\nSFX 1 0 id-/2 . X\nSFX 1 0 iguin/1 . I\n\nSFX 2 Y 1\nSFX 2 0 id/1 . I\n\nSFX 3 Y 1\nSFX 3 0 0/1 . I\n\nSFX 4 Y 1\nSFX 4 0 -/2 . X\n\nSFX 5 Y 3\nSFX 5 0 :ide/1 . I\nSFX 5 0 :id/1 . I\nSFX 5 0 :iguin/1 . I\n\nSFX 6 Y 1\nSFX 6 0 0/2 . X\n\nSFX 7 Y 3\nSFX 7 0 aččade/1 . I\nSFX 7 0 aččadet/1 . I\nSFX 7 0 aččaidanguin/1 . I\n\nSFX 8 Y 2\nSFX 8 0 a/1 . I\nSFX 8 0 a-/2 . X\n\nSFX 9 Y 2\nSFX 9 0 ii/1 . I\nSFX 9 0 iin/1 . I\n\nSFX 10 Y 9\nSFX 10 0 ba/1 . I\nSFX 10 0 beahtti/1 . I\nSFX 10 0 behtet/1 . I\nSFX 10 0 dan/1 . I\nSFX 10 0 deaddjái/1 . I\nSFX 10 0 deaddji/1 . I\nSFX 10 0 deaddjin/1 . I\nSFX 10 0 dišgoahtán/1 . I\nSFX 10 0 duvvogoahtán/1 . I\n\nSFX 11 Y 1\nSFX 11 0 t/1 . I\n\nSFX 12 Y 1\nSFX 12 0 buččat/1 . I\n\nSFX 13 Y 3\nSFX 13 0 de/1 . I\nSFX 13 0 det/1 . I\nSFX 13 0 me/1 . I\n\nSFX 14 Y 6\nSFX 14 0 :in/2 . X\nSFX 14 0 :in-/2 . X\nSFX 14 0 :i/2 . X\nSFX 14 0 :i-/2 . X\nSFX 14 0 :n/2 . X\nSFX 14 0 :n-/2 . X\n\nSFX 15 Y 3\nSFX 15 0 laččaide/1 . I\nSFX 15 0 laččaid/1 . I\nSFX 15 0 laččaiguin/1 . I\n\nSFX 16 Y 1\nSFX 16 0 :i/1 . I\n\nSFX 65009 Y 2\nSFX 65009 0 goson .\nSFX 65009 0 naigo .\n"); std::map wantAffMap; std::map wantStemMap; std::istream* inputfile = setupinputfile(); WordlistParserNoCompound wp; wp.processFile(inputfile); HunspellPrinterNoCompounding hp("tst"); std::map hmhm = hp.preparePLXClasses(wp.getPlxClasses()); SetOptimizer so(wp.getSuffixSetStemSet()); hp.prepareAfmap(so.giveSubsetsToStems()); CHECK_EQUAL(wantSuffixes, hp.printSuffixes(hmhm, wp.getSuffixMap(), so.getSuffixMap())); }