import unittest
from soundex import letters_to_numbers, truncate_to_three_digits, add_zero_padding
from french_count import french_count, prepare_input
from morphology import generate
from fsmutils import trace

class TestSequenceFunctions(unittest.TestCase):
    def setUp(self):
        self.f1 = letters_to_numbers()
        self.f2 = truncate_to_three_digits()
        self.f3 = add_zero_padding()

        self.french = french_count()

    def test_letters(self):
        s = []
        # trace(self.f1, [x for x in "Adams"])
        try: self.assertEqual("".join(self.f1.transduce(x for x in "washington")), "w25235")
        except: s.append(1)
        try: self.assertEqual("".join(self.f1.transduce(x for x in "jefferson")), "j1625")
        except: s.append(2)
        try: self.assertEqual("".join(self.f1.transduce(x for x in "ashcraft")), "a22613")
        except: s.append(3)
        try: self.assertEqual("".join(self.f1.transduce(x for x in "bush")), "b2")
        except: s.append(4)
        try: self.assertEqual("".join(self.f1.transduce(x for x in "akshay")), "a2")
        except: s.append(5)

        print '\nNumber of failed letters tests:', str(len(s))
        if len(s)!=0: print 'Failed letters tests:', ','.join([str(x) for x in s])

    def test_truncation(self):
        s = []
        # trace(self.f2, [x for x in "a33333"])
        try: self.assertEqual("".join(self.f2.transduce(x for x in "A33333")), "A333")
        except: s.append(1)
        try: self.assertEqual("".join(self.f2.transduce(x for x in "123456")), "123")
        except: s.append(2)
        try: self.assertEqual("".join(self.f2.transduce(x for x in "11")), "11")
        except: s.append(3)
        try: self.assertEqual("".join(self.f2.transduce(x for x in "5")), "5")
        except: s.append(4)

        print '\nNumber of failed truncation tests:', str(len(s))
        if len(s)!=0: print 'Failed truncation tests:', ','.join([str(x) for x in s])

    def test_padding(self):
        s = []
        try: self.assertEqual("".join(self.f3.transduce(x for x in "A2")), "A200")
        except: s.append(1)
        try: self.assertEqual("".join(self.f3.transduce(x for x in "b56")), "b560")
        except: s.append(2)
        try: self.assertEqual("".join(self.f3.transduce(x for x in "c111")), "c111")
        except: s.append(3)

        print '\nNumber of failed padding tests:', str(len(s))
        if len(s)!=0: print 'Failed padding tests:', ','.join([str(x) for x in s])

    def test_numbers(self):
        s = []
        try: val=' '.join(self.french.transduce(prepare_input(745)));self.assertEqual(val, "sept cent quarante cinq")
        except: print "got "+val+", expected: sept cent quarante cinq for 745";s.append(745)
        try: val=' '.join(self.french.transduce(prepare_input(746)));self.assertEqual(val, "sept cent quarante six")
        except: print "got "+val+", expected: sept cent quarante six for 746";s.append(746)
        try: val=' '.join(self.french.transduce(prepare_input(747)));self.assertEqual(val, "sept cent quarante sept")
        except: print "got "+val+", expected: sept cent quarante sept for 747";s.append(747)
        try: val=' '.join(self.french.transduce(prepare_input(748)));self.assertEqual(val, "sept cent quarante huit")
        except: print "got "+val+", expected: sept cent quarante huit for 748";s.append(748)
        try: val=' '.join(self.french.transduce(prepare_input(749)));self.assertEqual(val, "sept cent quarante neuf")
        except: print "got "+val+", expected: sept cent quarante neuf for 749";s.append(749)
        try: val=' '.join(self.french.transduce(prepare_input(750)));self.assertEqual(val, "sept cent cinquante")
        except: print "got "+val+", expected: sept cent cinquante for 750";s.append(750)
        try: val=' '.join(self.french.transduce(prepare_input(751)));self.assertEqual(val, "sept cent cinquante et un")
        except: print "got "+val+", expected: sept cent cinquante et un for 751";s.append(751)
        try: val=' '.join(self.french.transduce(prepare_input(752)));self.assertEqual(val, "sept cent cinquante deux")
        except: print "got "+val+", expected: sept cent cinquante deux for 752";s.append(752)
        try: val=' '.join(self.french.transduce(prepare_input(753)));self.assertEqual(val, "sept cent cinquante trois")
        except: print "got "+val+", expected: sept cent cinquante trois for 753";s.append(753)
        try: val=' '.join(self.french.transduce(prepare_input(754)));self.assertEqual(val, "sept cent cinquante quatre")
        except: print "got "+val+", expected: sept cent cinquante quatre for 754";s.append(754)
        try: val=' '.join(self.french.transduce(prepare_input(755)));self.assertEqual(val, "sept cent cinquante cinq")
        except: print "got "+val+", expected: sept cent cinquante cinq for 755";s.append(755)
        try: val=' '.join(self.french.transduce(prepare_input(756)));self.assertEqual(val, "sept cent cinquante six")
        except: print "got "+val+", expected: sept cent cinquante six for 756";s.append(756)
        try: val=' '.join(self.french.transduce(prepare_input(757)));self.assertEqual(val, "sept cent cinquante sept")
        except: print "got "+val+", expected: sept cent cinquante sept for 757";s.append(757)
        try: val=' '.join(self.french.transduce(prepare_input(758)));self.assertEqual(val, "sept cent cinquante huit")
        except: print "got "+val+", expected: sept cent cinquante huit for 758";s.append(758)
        try: val=' '.join(self.french.transduce(prepare_input(759)));self.assertEqual(val, "sept cent cinquante neuf")
        except: print "got "+val+", expected: sept cent cinquante neuf for 759";s.append(759)
        try: val=' '.join(self.french.transduce(prepare_input(760)));self.assertEqual(val, "sept cent soixante")
        except: print "got "+val+", expected: sept cent soixante for 760";s.append(760)
        try: val=' '.join(self.french.transduce(prepare_input(761)));self.assertEqual(val, "sept cent soixante et un")
        except: print "got "+val+", expected: sept cent soixante et un for 761";s.append(761)
        try: val=' '.join(self.french.transduce(prepare_input(762)));self.assertEqual(val, "sept cent soixante deux")
        except: print "got "+val+", expected: sept cent soixante deux for 762";s.append(762)
        try: val=' '.join(self.french.transduce(prepare_input(763)));self.assertEqual(val, "sept cent soixante trois")
        except: print "got "+val+", expected: sept cent soixante trois for 763";s.append(763)
        try: val=' '.join(self.french.transduce(prepare_input(764)));self.assertEqual(val, "sept cent soixante quatre")
        except: print "got "+val+", expected: sept cent soixante quatre for 764";s.append(764)
        try: val=' '.join(self.french.transduce(prepare_input(765)));self.assertEqual(val, "sept cent soixante cinq")
        except: print "got "+val+", expected: sept cent soixante cinq for 765";s.append(765)
        try: val=' '.join(self.french.transduce(prepare_input(766)));self.assertEqual(val, "sept cent soixante six")
        except: print "got "+val+", expected: sept cent soixante six for 766";s.append(766)
        try: val=' '.join(self.french.transduce(prepare_input(767)));self.assertEqual(val, "sept cent soixante sept")
        except: print "got "+val+", expected: sept cent soixante sept for 767";s.append(767)
        try: val=' '.join(self.french.transduce(prepare_input(768)));self.assertEqual(val, "sept cent soixante huit")
        except: print "got "+val+", expected: sept cent soixante huit for 768";s.append(768)
        try: val=' '.join(self.french.transduce(prepare_input(769)));self.assertEqual(val, "sept cent soixante neuf")
        except: print "got "+val+", expected: sept cent soixante neuf for 769";s.append(769)
        try: val=' '.join(self.french.transduce(prepare_input(770)));self.assertEqual(val, "sept cent soixante dix")
        except: print "got "+val+", expected: sept cent soixante dix for 770";s.append(770)
        try: val=' '.join(self.french.transduce(prepare_input(771)));self.assertEqual(val, "sept cent soixante et onze")
        except: print "got "+val+", expected: sept cent soixante et onze for 771";s.append(771)
        try: val=' '.join(self.french.transduce(prepare_input(772)));self.assertEqual(val, "sept cent soixante douze")
        except: print "got "+val+", expected: sept cent soixante douze for 772";s.append(772)
        try: val=' '.join(self.french.transduce(prepare_input(773)));self.assertEqual(val, "sept cent soixante treize")
        except: print "got "+val+", expected: sept cent soixante treize for 773";s.append(773)
        try: val=' '.join(self.french.transduce(prepare_input(774)));self.assertEqual(val, "sept cent soixante quatorze")
        except: print "got "+val+", expected: sept cent soixante quatorze for 774";s.append(774)
        try: val=' '.join(self.french.transduce(prepare_input(775)));self.assertEqual(val, "sept cent soixante quinze")
        except: print "got "+val+", expected: sept cent soixante quinze for 775";s.append(775)
        try: val=' '.join(self.french.transduce(prepare_input(776)));self.assertEqual(val, "sept cent soixante seize")
        except: print "got "+val+", expected: sept cent soixante seize for 776";s.append(776)
        try: val=' '.join(self.french.transduce(prepare_input(777)));self.assertEqual(val, "sept cent soixante dix sept")
        except: print "got "+val+", expected: sept cent soixante dix sept for 777";s.append(777)
        try: val=' '.join(self.french.transduce(prepare_input(778)));self.assertEqual(val, "sept cent soixante dix huit")
        except: print "got "+val+", expected: sept cent soixante dix huit for 778";s.append(778)
        try: val=' '.join(self.french.transduce(prepare_input(779)));self.assertEqual(val, "sept cent soixante dix neuf")
        except: print "got "+val+", expected: sept cent soixante dix neuf for 779";s.append(779)
        try: val=' '.join(self.french.transduce(prepare_input(780)));self.assertEqual(val, "sept cent quatre vingt")
        except: print "got "+val+", expected: sept cent quatre vingt for 780";s.append(780)
        try: val=' '.join(self.french.transduce(prepare_input(781)));self.assertEqual(val, "sept cent quatre vingt un")
        except: print "got "+val+", expected: sept cent quatre vingt un for 781";s.append(781)
        try: val=' '.join(self.french.transduce(prepare_input(782)));self.assertEqual(val, "sept cent quatre vingt deux")
        except: print "got "+val+", expected: sept cent quatre vingt deux for 782";s.append(782)
        try: val=' '.join(self.french.transduce(prepare_input(783)));self.assertEqual(val, "sept cent quatre vingt trois")
        except: print "got "+val+", expected: sept cent quatre vingt trois for 783";s.append(783)
        try: val=' '.join(self.french.transduce(prepare_input(784)));self.assertEqual(val, "sept cent quatre vingt quatre")
        except: print "got "+val+", expected: sept cent quatre vingt quatre for 784";s.append(784)
        try: val=' '.join(self.french.transduce(prepare_input(785)));self.assertEqual(val, "sept cent quatre vingt cinq")
        except: print "got "+val+", expected: sept cent quatre vingt cinq for 785";s.append(785)
        try: val=' '.join(self.french.transduce(prepare_input(786)));self.assertEqual(val, "sept cent quatre vingt six")
        except: print "got "+val+", expected: sept cent quatre vingt six for 786";s.append(786)
        try: val=' '.join(self.french.transduce(prepare_input(787)));self.assertEqual(val, "sept cent quatre vingt sept")
        except: print "got "+val+", expected: sept cent quatre vingt sept for 787";s.append(787)
        try: val=' '.join(self.french.transduce(prepare_input(788)));self.assertEqual(val, "sept cent quatre vingt huit")
        except: print "got "+val+", expected: sept cent quatre vingt huit for 788";s.append(788)
        try: val=' '.join(self.french.transduce(prepare_input(789)));self.assertEqual(val, "sept cent quatre vingt neuf")
        except: print "got "

        print '\nNumber of failed numbers tests:', str(len(s))
        if len(s)!=0: print 'Failed numbers tests:', ','.join([str(x) for x in s])

    def test_morphology(self):
        s = []
        try: self.assertEqual(generate("pack+ing"), "packing")
        except: s.append(1)
        try: self.assertEqual(generate("ice+ing"), "icing")
        except: s.append(2)
        try: self.assertEqual(generate("frolic+ed"), "frolicked")
        except: s.append(3)
        try: self.assertEqual(generate("pace+ed"), "paced")
        except: s.append(4)
        try: self.assertEqual(generate("ace+ed"), "aced")
        except: s.append(5)
        try: self.assertEqual(generate("traffic+ed"), "trafficked")
        except: s.append(6)
        try: self.assertEqual(generate("lilac+ing"), "lilacking")
        except: s.append(7)
        try: self.assertEqual(generate("lick+ed"), "licked")
        except: s.append(8)

        print '\nNumber of failed morphology tests:', str(len(s))
        if len(s)!=0: print 'Failed morphology tests:', ','.join([str(x) for x in s])

if __name__ == '__main__':
    unittest.main()
