-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_check_syllables.py
150 lines (139 loc) · 7.68 KB
/
test_check_syllables.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import unittest
import poetry_functions
class TestCountLines(unittest.TestCase):
''' Example unittest test method for count_lines'''
def test_check_syllables_1(self):
''' Test check_syllables with all strings having correct number of
syllables.'''
word_to_phonemes = {'NEXT': ['N', 'EH1', 'K', 'S', 'T'],
'GAP': ['G', 'AE1', 'P'],
'BEFORE': ['B', 'IH0', 'F', 'AO1', 'R'],
'LEADS': ['L', 'IY1', 'D', 'Z'],
'WITH': ['W', 'IH1', 'DH'],
'LINE': ['L', 'AY1', 'N'],
'THEN': ['DH', 'EH1', 'N'],
'THE': ['DH', 'AH0'],
'A': ['AH0'],
'FIRST': ['F', 'ER1', 'S', 'T'],
'ENDS': ['EH1', 'N', 'D', 'Z'],
'POEM': ['P', 'OW1', 'AH0', 'M'],
'OFF': ['AO1', 'F']}
poem_lines = ['The first line leads off,',
'With a gap before the next.', 'Then the poem ends.']
pattern = ([5, 7, 5], ['*', '*', '*'])
actual = poetry_functions.check_syllables(poem_lines, pattern, word_to_phonemes)
expected = []
self.assertEqual(actual, expected)
def test_check_syllables_2(self):
''' Test check_syllables with no syllable requirement per line.'''
word_to_phonemes = {'NEXT': ['N', 'EH1', 'K', 'S', 'T'],
'GAP': ['G', 'AE1', 'P'],
'BEFORE': ['B', 'IH0', 'F', 'AO1', 'R'],
'LEADS': ['L', 'IY1', 'D', 'Z'],
'WITH': ['W', 'IH1', 'DH'],
'LINE': ['L', 'AY1', 'N'],
'THEN': ['DH', 'EH1', 'N'],
'THE': ['DH', 'AH0'],
'A': ['AH0'],
'FIRST': ['F', 'ER1', 'S', 'T'],
'ENDS': ['EH1', 'N', 'D', 'Z'],
'POEM': ['P', 'OW1', 'AH0', 'M'],
'OFF': ['AO1', 'F']}
pattern = ([0, 0, 0], ['*', '*', '*'])
poem_lines = ['First line,\n', 'Before line,\n', 'Ends line\n']
actual = poetry_functions.check_syllables(poem_lines, pattern, word_to_phonemes)
expected = []
self.assertEqual(actual, expected)
def test_check_syllables_3(self):
''' Test check_syllables with one no syllable requirement and
two lines that have syllable requirements.'''
word_to_phonemes = {'NEXT': ['N', 'EH1', 'K', 'S', 'T'],
'GAP': ['G', 'AE1', 'P'],
'BEFORE': ['B', 'IH0', 'F', 'AO1', 'R'],
'LEADS': ['L', 'IY1', 'D', 'Z'],
'WITH': ['W', 'IH1', 'DH'],
'LINE': ['L', 'AY1', 'N'],
'THEN': ['DH', 'EH1', 'N'],
'THE': ['DH', 'AH0'],
'A': ['AH0'],
'FIRST': ['F', 'ER1', 'S', 'T'],
'ENDS': ['EH1', 'N', 'D', 'Z'],
'POEM': ['P', 'OW1', 'AH0', 'M'],
'OFF': ['AO1', 'F']}
pattern = ([2, 0, 2], ['*', '*', '*'])
poem_lines = ['First line,\n', 'Before line,\n', 'Ends line\n']
actual = poetry_functions.check_syllables(poem_lines, pattern, word_to_phonemes)
expected = []
self.assertEqual(actual, expected)
def test_check_syllables_4(self):
''' Test check_syllables with one string that doesn't match the syllable
pattern.'''
word_to_phonemes = {'NEXT': ['N', 'EH1', 'K', 'S', 'T'],
'GAP': ['G', 'AE1', 'P'],
'BEFORE': ['B', 'IH0', 'F', 'AO1', 'R'],
'LEADS': ['L', 'IY1', 'D', 'Z'],
'WITH': ['W', 'IH1', 'DH'],
'LINE': ['L', 'AY1', 'N'],
'THEN': ['DH', 'EH1', 'N'],
'THE': ['DH', 'AH0'],
'A': ['AH0'],
'FIRST': ['F', 'ER1', 'S', 'T'],
'ENDS': ['EH1', 'N', 'D', 'Z'],
'POEM': ['P', 'OW1', 'AH0', 'M'],
'OFF': ['AO1', 'F']}
poem_lines = ['The first line leads off,',
'With a gap before the next.', 'Then the poem ends.']
pattern = ([5, 3, 5], ['*', '*', '*'])
actual = poetry_functions.check_syllables(poem_lines, pattern, word_to_phonemes)
expected = ['With a gap before the next.']
self.assertEqual(actual, expected)
def test_check_syllables_5(self):
''' Test check_syllables with three string that doesn't match the syllable
pattern.'''
word_to_phonemes = {'NEXT': ['N', 'EH1', 'K', 'S', 'T'],
'GAP': ['G', 'AE1', 'P'],
'BEFORE': ['B', 'IH0', 'F', 'AO1', 'R'],
'LEADS': ['L', 'IY1', 'D', 'Z'],
'WITH': ['W', 'IH1', 'DH'],
'LINE': ['L', 'AY1', 'N'],
'THEN': ['DH', 'EH1', 'N'],
'THE': ['DH', 'AH0'],
'A': ['AH0'],
'FIRST': ['F', 'ER1', 'S', 'T'],
'ENDS': ['EH1', 'N', 'D', 'Z'],
'POEM': ['P', 'OW1', 'AH0', 'M'],
'OFF': ['AO1', 'F']}
poem_lines = ['The first line leads off,',
'With a gap before the next.', 'Then the poem ends.']
pattern = ([3, 3, 3], ['*', '*', '*'])
actual = poetry_functions.check_syllables(poem_lines, pattern, word_to_phonemes)
expected = ['The first line leads off,',
'With a gap before the next.', 'Then the poem ends.']
self.assertEqual(actual, expected)
def test_check_syllables_6(self):
''' Test check_syllables with five string that doesn't match the
syllable pattern.'''
word_to_phonemes = {'NEXT': ['N', 'EH1', 'K', 'S', 'T'],
'GAP': ['G', 'AE1', 'P'],
'BEFORE': ['B', 'IH0', 'F', 'AO1', 'R'],
'LEADS': ['L', 'IY1', 'D', 'Z'],
'WITH': ['W', 'IH1', 'DH'],
'LINE': ['L', 'AY1', 'N'],
'THEN': ['DH', 'EH1', 'N'],
'THE': ['DH', 'AH0'],
'A': ['AH0'],
'FIRST': ['F', 'ER1', 'S', 'T'],
'ENDS': ['EH1', 'N', 'D', 'Z'],
'POEM': ['P', 'OW1', 'AH0', 'M'],
'OFF': ['AO1', 'F']}
poem_lines = ['The first line leads off,',
'With a gap before the next.', 'Then the poem ends.',
'With a gap before the next.', 'Then the poem ends.']
pattern = ([3, 3, 3, 3, 3], ['*', '*', '*'])
actual = poetry_functions.check_syllables(poem_lines, pattern, word_to_phonemes)
expected = ['The first line leads off,',
'With a gap before the next.', 'Then the poem ends.',
'With a gap before the next.', 'Then the poem ends.']
self.assertEqual(actual, expected)
if __name__ == '__main__':
unittest.main(exit=False)