-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
test_meow.py
130 lines (103 loc) · 3.2 KB
/
test_meow.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env python
"""
Unit tests for meow.py
"""
import re
import unittest
import meow
class TestIt(unittest.TestCase):
def sanity_check(self, word, out):
self.assertEqual(len(word), len(out))
# Check pattern
if len(word) > 4:
found = re.match("m[e]+[o]+w", out, re.IGNORECASE)
self.assertTrue(found)
# Check caps
for i in range(len(word)):
self.assertEqual(word[i].isupper(), out[i].isupper())
def test_1_letter_word(self):
word = "I"
out = meow.meow(word)
self.sanity_check(word, out)
self.assertEqual(out, "M")
def test_2_letter_word(self):
word = "on"
out = meow.meow(word)
self.sanity_check(word, out)
self.assertEqual(out, "me")
def test_3_letter_word(self):
word = "The"
out = meow.meow(word)
self.sanity_check(word, out)
self.assertEqual(out, "Mew")
def test_4_letter_word(self):
word = "book"
out = meow.meow(word)
self.sanity_check(word, out)
self.assertEqual(out, "meow")
def test_capify_1(self):
word = "meow"
reference = "Book"
out = meow.capify(word, reference)
self.assertEqual(out, "Meow")
def test_capify_2(self):
word = "meow"
reference = "BOOK"
out = meow.capify(word, reference)
self.assertEqual(out, "MEOW")
def test_capify_3(self):
word = "meow"
reference = "book"
out = meow.capify(word, reference)
self.assertEqual(out, "meow")
def test_capify_4(self):
word = "meow"
reference = "BoOk"
out = meow.capify(word, reference)
self.assertEqual(out, "MeOw")
def test_upper_4_letter_word(self):
word = "BOOK"
out = meow.meow(word)
self.sanity_check(word, out)
self.assertEqual(out, "MEOW")
def test_capped_4_letter_word(self):
word = "Book"
out = meow.meow(word)
self.sanity_check(word, out)
self.assertEqual(out, "Meow")
def test_mixcapped_4_letter_word(self):
word = "BooK"
out = meow.meow(word)
self.sanity_check(word, out)
self.assertEqual(out, "MeoW")
def test_5_letter_word(self):
word = "clock"
out = meow.meow(word)
self.sanity_check(word, out)
def test_6_letter_word(self):
word = "whales"
out = meow.meow(word)
self.sanity_check(word, out)
def test_13_letter_word(self):
word = "Extraordinary"
out = meow.meow(word)
self.sanity_check(word, out)
def test_line(self):
line = "On the bus"
out = meow.meow_meow(line, meow.meow)
self.assertEqual(out, "Me mew mew")
def test_is_word_1(self):
thing = "word"
out = meow.is_word(thing)
self.assertTrue(out)
def test_is_word_2(self):
thing = ";"
out = meow.is_word(thing)
self.assertFalse(out)
def test_line_punctuation(self):
line = "On the bus? On the bus."
out = meow.meow_meow(line, meow.meow)
self.assertEqual(out, "Me mew mew? Me mew mew.")
if __name__ == "__main__":
unittest.main()
# End of file