/* 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 "../hunspellprintercompounding.h" #include "../wordlistparserall.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 setuphmhm() { std::map plxclasses; int i = 1; plxclasses.insert(std::pair("GaB", i)); ++i; plxclasses.insert(std::pair("GaBO", i)); ++i; plxclasses.insert(std::pair("GpBO", i)); ++i; plxclasses.insert(std::pair("JuBO", i)); ++i; plxclasses.insert(std::pair("NAB", i)); ++i; plxclasses.insert(std::pair("NABI", i)); ++i; plxclasses.insert(std::pair("NABO", i)); ++i; plxclasses.insert(std::pair("NAE", i)); ++i; plxclasses.insert(std::pair("NAI", i)); ++i; plxclasses.insert(std::pair("NAIBOE", i)); ++i; plxclasses.insert(std::pair("NAIE", i)); ++i; plxclasses.insert(std::pair("NAIX", i)); ++i; plxclasses.insert(std::pair("NAPBX", i)); ++i; plxclasses.insert(std::pair("NB", i)); ++i; plxclasses.insert(std::pair("NBX", i)); ++i; plxclasses.insert(std::pair("NEX", i)); ++i; plxclasses.insert(std::pair("NI", i)); ++i; plxclasses.insert(std::pair("NIE", i)); ++i; plxclasses.insert(std::pair("NIX", i)); ++i; plxclasses.insert(std::pair("NO", i)); ++i; plxclasses.insert(std::pair("NaAE", i)); ++i; plxclasses.insert(std::pair("NaO", i)); ++i; plxclasses.insert(std::pair("NePABO", i)); ++i; plxclasses.insert(std::pair("NePABX", i)); ++i; plxclasses.insert(std::pair("NePAE", i)); ++i; plxclasses.insert(std::pair("NePAOE", i)); ++i; plxclasses.insert(std::pair("NePE", i)); ++i; plxclasses.insert(std::pair("NePIE", i)); ++i; plxclasses.insert(std::pair("NePIEX", i)); ++i; plxclasses.insert(std::pair("NePIOE", i)); ++i; plxclasses.insert(std::pair("NePOE", i)); ++i; plxclasses.insert(std::pair("NpAE", i)); ++i; plxclasses.insert(std::pair("NpO", i)); ++i; plxclasses.insert(std::pair("NtPAB", i)); ++i; plxclasses.insert(std::pair("VI", i)); ++i; plxclasses.insert(std::pair("VaE", i)); ++i; plxclasses.insert(std::pair("WEIX", i)); ++i; plxclasses.insert(std::pair("WI", i)); ++i; plxclasses.insert(std::pair("WIX", i)); ++i; return plxclasses; } std::string setupafmap () { std::stringstream s; s << "AF 64" << std::endl; s << "AF 65007,65006,65002 # 1" << std::endl; s << "AF 65007,65006,65005,65002 # 2" << std::endl; s << "AF 65007,65006,65005,65002 # 3" << std::endl; s << "AF 65007,65006,65005,65002 # 4" << std::endl; s << "AF 65007,65006,65002 # 5" << std::endl; s << "AF 65007,65006,65009 # 6" << std::endl; s << "AF 65007,65006,65005,65002 # 7" << std::endl; s << "AF 65007,65004,65009 # 8" << std::endl; s << "AF 65009 # 9" << std::endl; s << "AF 65007,65006,65005,65004,65009 # 10" << std::endl; s << "AF 65007,65004,65009 # 11" << std::endl; s << "AF 65001,65009 # 12" << std::endl; s << "AF 65001,65007,65006,65002 # 13" << std::endl; s << "AF 65007,65006,65002 # 14" << std::endl; s << "AF 65001,65007,65006,65002 # 15" << std::endl; s << "AF 65001,65007,65004,65009 # 16" << std::endl; s << "AF 65009 # 17" << std::endl; s << "AF 65007,65004,65009 # 18" << std::endl; s << "AF 65001,65009 # 19" << std::endl; s << "AF 65007,65005,65002 # 20" << std::endl; s << "AF 65007,65004,65009 # 21" << std::endl; s << "AF 65007,65005,65002 # 22" << std::endl; s << "AF 65007,65006,65005,65002 # 23" << std::endl; s << "AF 65001,65007,65006,65002 # 24" << std::endl; s << "AF 65007,65004,65009 # 25" << std::endl; s << "AF 65007,65005,65004,65009 # 26" << std::endl; s << "AF 65007,65004,65009 # 27" << std::endl; s << "AF 65007,65004,65009 # 28" << std::endl; s << "AF 65001,65007,65004,65009 # 29" << std::endl; s << "AF 65007,65005,65004,65009 # 30" << std::endl; s << "AF 65007,65005,65004,65009 # 31" << std::endl; s << "AF 65007,65004,65009 # 32" << std::endl; s << "AF 65007,65005,65002 # 33" << std::endl; s << "AF 65007,65006,65002 # 34" << std::endl; s << "AF 65009 # 35" << std::endl; s << "AF 65007,65004,65009 # 36" << std::endl; s << "AF 65001,65007,65004,65009 # 37" << std::endl; s << "AF 65009 # 38" << std::endl; s << "AF 65001,65009 # 39" << std::endl; s << "AF 1,2,3,4,5,6,65008 # 40" << std::endl; s << "AF 1,3,65008 # 41" << std::endl; s << "AF 1,3,4,65008 # 42" << std::endl; s << "AF 3,65008 # 43" << std::endl; s << "AF 4,5,6,7,8,65008 # 44" << std::endl; s << "AF 6,14,15,16,65008 # 45" << std::endl; s << "AF 6,14,16,65008 # 46" << std::endl; s << "AF 6,16,65008 # 47" << std::endl; s << "AF 8,65008 # 48" << std::endl; s << "AF 9,10,65008 # 49" << std::endl; s << "AF 10,65008 # 50" << std::endl; s << "AF 10,28,65008 # 51" << std::endl; s << "AF 11,12,65008 # 52" << std::endl; s << "AF 11,27,65008 # 53" << std::endl; s << "AF 13,65008 # 54" << std::endl; s << "AF 17,65008 # 55" << std::endl; s << "AF 18,65008 # 56" << std::endl; s << "AF 19,65008 # 57" << std::endl; s << "AF 20,65008 # 58" << std::endl; s << "AF 21,65008 # 59" << std::endl; s << "AF 22,65008 # 60" << std::endl; s << "AF 23,65008 # 61" << std::endl; s << "AF 24,65008 # 62" << std::endl; s << "AF 25,65008 # 63" << std::endl; s << "AF 26,65008 # 64" << std::endl; s << std::endl; return s.str(); } TEST(printAfflist) { std::map wantAffMap; std::map wantStemMap; std::istream* inputfile = setupinputfile(); WordlistParserAll wp; wp.processFile(inputfile); HunspellPrinterCompounding hp("tst"); std::map got = hp.preparePLXClasses(wp.getPlxClasses()); std::map want = setuphmhm(); CHECK_EQUAL(want.size(), got.size()); CHECK(equal(want.begin(), want.end(), got.begin())); SetOptimizer so(wp.getSuffixSetStemSet()); hp.prepareAfmap(so.giveSubsetsToStems()); CHECK_EQUAL(setupafmap(), hp.printAfflist()); } TEST(TestPrintStems) { std::map wantAffMap; std::map wantStemMap; std::istream* inputfile = setupinputfile(); WordlistParserAll wp; wp.processFile(inputfile); HunspellPrinterCompounding hp("tst"); std::map hmhm = hp.preparePLXClasses(wp.getPlxClasses()); SetOptimizer so(wp.getSuffixSetStemSet()); hp.prepareAfmap(so.giveSubsetsToStems()); std::string wantStems("42\n100000-geardásačča/40\n100000-geardásaš/44\n10000-geardásačča/42\n10000-geardásaš/48\n1000-geardásačča/41\n1000-geardásaš/48\n10-Đ/49\n10-Đ-/52\n1-D/50\n1-D-/52\n2-C/50\n2-C-/52\n3-juvllatsihkkel/54\n7. juni-plassen/45\nAabakken/46\nAabel/47\nabandonere/55\nabess-/56\nabess.-/56\nabl-/56\naborigiinnalačča/57\nabsoluhta/58\nabsoluhtalačča/57\naddalanvuoigatvuođa/43\naddámuša/43\naddinbeai/59\naddinvejolašvuođa/43\nadvokáhta gukto/60\nagibeai/59\na./61\nalmmustusbeai/59\na-/62\nas/63\ná-/62\nc-/62\nčuohpan/64\ndáppe/53\ndieppe/53\ndoppe/53\nNSR/51\n"); wantStems += hp.makeDicEasterEgg(); CHECK_EQUAL(wantStems, hp.makeDicString(wp.getStems())); } TEST(TestPrintSuffixes) { std::string wantSuffixes("SFX 1 Y 5\nSFX 1 0 0/2 . GaBO\nSFX 1 0 id/7 . NABO\nSFX 1 0 id/30 . NePIOE\nSFX 1 0 id/11 . NAIE\nSFX 1 0 id/26 . NePAOE\n\nSFX 2 Y 7\nSFX 2 0 ide/11 . NAIE\nSFX 2 0 ide/25 . NePAE\nSFX 2 0 id/25 . NePAE\nSFX 2 0 id-/16 . NEX\nSFX 2 0 id-/39 . WIX\nSFX 2 0 iguin/11 . NAIE\nSFX 2 0 iguin/25 . NePAE\n\nSFX 3 Y 1\nSFX 3 0 id/3 . GpBO\n\nSFX 4 Y 2\nSFX 4 0 0/11 . NAIE\nSFX 4 0 0/31 . NePOE\n\nSFX 5 Y 1\nSFX 5 0 -/16 . NEX\n\nSFX 6 Y 1\nSFX 6 0 -/39 . WIX\n\nSFX 7 Y 1\nSFX 7 0 0/7 . NABO\n\nSFX 8 Y 1\nSFX 8 0 0/10 . NAIBOE\n\nSFX 9 Y 6\nSFX 9 0 :ide/17 . NI\nSFX 9 0 :ide/27 . NePE\nSFX 9 0 :id/17 . NI\nSFX 9 0 :id/27 . NePE\nSFX 9 0 :iguin/17 . NI\nSFX 9 0 :iguin/27 . NePE\n\nSFX 10 Y 2\nSFX 10 0 0/27 . NePE\nSFX 10 0 0/38 . WI\n\nSFX 11 Y 1\nSFX 11 0 0/19 . NIX\n\nSFX 12 Y 1\nSFX 12 0 0/23 . NePABO\n\nSFX 13 Y 3\nSFX 13 0 aččade/17 . NI\nSFX 13 0 aččadet/17 . NI\nSFX 13 0 aččaidanguin/17 . NI\n\nSFX 14 Y 4\nSFX 14 0 a/28 . NePIE\nSFX 14 0 a/36 . VaE\nSFX 14 0 a-/4 . JuBO\nSFX 14 0 a-/29 . NePIEX\n\nSFX 15 Y 6\nSFX 15 0 ii/28 . NePIE\nSFX 15 0 iin/28 . NePIE\nSFX 15 0 0/28 . NePIE\nSFX 15 0 0/36 . VaE\nSFX 15 0 -/4 . JuBO\nSFX 15 0 -/29 . NePIEX\n\nSFX 16 Y 3\nSFX 16 0 -/1 . GaB\nSFX 16 0 -/14 . NB\nSFX 16 0 -/23 . NePABO\n\nSFX 17 Y 24\nSFX 17 0 ba/35 . VI\nSFX 17 0 beahtti/35 . VI\nSFX 17 0 behtet/35 . VI\nSFX 17 0 dan/21 . NaAE\nSFX 17 0 dan/6 . NABI\nSFX 17 0 dan/8 . NAE\nSFX 17 0 dan/22 . NaO\nSFX 17 0 dan/20 . NO\nSFX 17 0 dan/32 . NpAE\nSFX 17 0 dan/33 . NpO\nSFX 17 0 deaddjái/21 . NaAE\nSFX 17 0 deaddjái/8 . NAE\nSFX 17 0 deaddjái/32 . NpAE\nSFX 17 0 deaddji/21 . NaAE\nSFX 17 0 deaddji/8 . NAE\nSFX 17 0 deaddji/22 . NaO\nSFX 17 0 deaddjin/32 . NpAE\nSFX 17 0 deaddji/20 . NO\nSFX 17 0 deaddji/33 . NpO\nSFX 17 0 deami/22 . NaO\nSFX 17 0 deami/20 . NO\nSFX 17 0 deami/33 . NpO\nSFX 17 0 dišgoahtán/6 . NABI\nSFX 17 0 duvvogoahtán/6 . NABI\n\nSFX 18 Y 1\nSFX 18 0 0/24 . NePABX\n\nSFX 19 Y 1\nSFX 19 0 t/9 . NAI\n\nSFX 20 Y 1\nSFX 20 0 buččat/9 . NAI\n\nSFX 21 Y 3\nSFX 21 0 0/5 . NAB\nSFX 21 0 -/12 . NAIX\nSFX 21 0 -/24 . NePABX\n\nSFX 22 Y 3\nSFX 22 0 de/18 . NIE\nSFX 22 0 det/18 . NIE\nSFX 22 0 me/18 . NIE\n\nSFX 23 Y 9\nSFX 23 0 :in/37 . WEIX\nSFX 23 0 :in-/24 . NePABX\nSFX 23 0 :in-/39 . WIX\nSFX 23 0 :i/37 . WEIX\nSFX 23 0 :i-/24 . NePABX\nSFX 23 0 :i-/39 . WIX\nSFX 23 0 :n/37 . WEIX\nSFX 23 0 :n-/24 . NePABX\nSFX 23 0 :n-/39 . WIX\n\nSFX 24 Y 1\nSFX 24 0 0/15 . NBX\n\nSFX 25 Y 3\nSFX 25 0 :ide/38 . WI\nSFX 25 0 :id/38 . WI\nSFX 25 0 :iguin/38 . WI\n\nSFX 26 Y 3\nSFX 26 0 laččaide/11 . NAIE\nSFX 26 0 laččaid/11 . NAIE\nSFX 26 0 laččaiguin/11 . NAIE\n\nSFX 27 Y 2\nSFX 27 0 0/13 . NAPBX\nSFX 27 0 0/34 . NtPAB\n\nSFX 28 Y 2\nSFX 28 0 :i/17 . NI\nSFX 28 0 :i/27 . NePE\n\nSFX 65009 Y 2\nSFX 65009 0 goson .\nSFX 65009 0 naigo .\n"); std::map wantAffMap; std::map wantStemMap; std::istream* inputfile = setupinputfile(); WordlistParserAll wp; wp.processFile(inputfile); HunspellPrinterCompounding 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())); }