1
exercism fetch python pig-latin

pig_latin_test.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import unittest

from pig_latin import translate


# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0

class PigLatinTests(unittest.TestCase):
    def test_word_beginning_with_a(self):
        self.assertEqual(translate("apple"), "appleay")

    def test_word_beginning_with_e(self):
        self.assertEqual(translate("ear"), "earay")

    def test_word_beginning_with_i(self):
        self.assertEqual(translate("igloo"), "iglooay")

    def test_word_beginning_with_o(self):
        self.assertEqual(translate("object"), "objectay")

    def test_word_beginning_with_u(self):
        self.assertEqual(translate("under"), "underay")

    def test_word_beginning_with_a_vowel_and_followed_by_a_qu(self):
        self.assertEqual(translate("equal"), "equalay")

    def test_word_beginning_with_p(self):
        self.assertEqual(translate("pig"), "igpay")

    def test_word_beginning_with_k(self):
        self.assertEqual(translate("koala"), "oalakay")

    def test_word_beginning_with_x(self):
        self.assertEqual(translate("xenon"), "enonxay")

    def test_word_beginning_with_q_without_a_following_u(self):
        self.assertEqual(translate("qat"), "atqay")

    def test_word_beginning_with_ch(self):
        self.assertEqual(translate("chair"), "airchay")

    def test_word_beginning_with_qu(self):
        self.assertEqual(translate("queen"), "eenquay")

    def test_word_beginning_with_qu_and_a_preceding_consonant(self):
        self.assertEqual(translate("square"), "aresquay")

    def test_word_beginning_with_th(self):
        self.assertEqual(translate("therapy"), "erapythay")

    def test_word_beginning_with_thr(self):
        self.assertEqual(translate("thrush"), "ushthray")

    def test_word_beginning_with_sch(self):
        self.assertEqual(translate("school"), "oolschay")

    def test_word_beginning_with_yt(self):
        self.assertEqual(translate("yttria"), "yttriaay")

    def test_word_beginning_with_xr(self):
        self.assertEqual(translate("xray"), "xrayay")

    def test_y_is_treated_like_a_consonant_at_the_beginning_of_a_word(self):
        self.assertEqual(translate("yellow"), "ellowyay")

    def test_y_is_treated_like_a_vowel_at_the_end_of_a_consonant_cluster(self):
        self.assertEqual(translate("rhythm"), "ythmrhay")

    def test_y_as_second_letter_in_two_letter_word(self):
        self.assertEqual(translate("my"), "ymay")

    def test_a_whole_phrase(self):
        self.assertEqual(translate("quick fast run"), "ickquay astfay unray")


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