def test_multi_no_syllable_requirement(self): """Test check_syllable_counts with no syllable requirements and multiple lines each with multiple words. Multiple lines are being tested in this case.""" pattern = ([0, 0, 0], ['A', 'B', 'A']) word_to_phonemes = { 'THE': ['DH', 'AH0'], 'FIRST': ['F', 'ER1', 'S', 'T'], 'LINE': ['L', 'AY1', 'N'], 'LEADS': ['L', 'IY1', 'D', 'Z'], 'OFF': ['AO1', 'F'], 'WITH': ['W', 'IH1', 'DH'], 'A': ['AH0'], 'GAP': ['G', 'AE1', 'P'], 'BEFORE': ['B', 'IH0', 'F', 'AO1', 'R'], 'NEXT': ['N', 'EH1', 'K', 'S', 'T'], 'THEN': ['DH', 'EH1', 'N'], 'POEM': ['P', 'OW1', 'AH0', 'M'], 'ENDS': ['EH1', 'N', 'D', 'Z'] } poem_lines = [ 'The first line leads off,', 'With a gap before the next.', 'Then the poem ends.' ] actual = poetry_functions.check_syllable_counts( poem_lines, pattern, word_to_phonemes) expected = [] self.assertEqual(actual, expected)
def check_poem(poem_lines, pattern, word_to_phonemes, form_name): """ (list of str, poetry pattern, pronunciation dictionary, str) -> NoneType Check whether the poem in poem_lines has the right number of lines to match for form given in pattern, and print a message if it doesn't. If it does, then check whether the lines in the poem have the right number of syllables and report the lines that don't; also check whether the lines of the poem have the correct rhyming scheme and report the lines that should rhyme but don't. """ if len(poem_lines) != len(pattern[0]): print("\n== The poem doesn't have the right number of lines. == \n") else: problem_lines = poetry_functions.check_syllable_counts( poem_lines, pattern, word_to_phonemes) if len(problem_lines) == 0: print('\nThe poem has the right number of syllables ' 'on each line.\n') else: print('\n== The poem is not a {}. These lines don\'t have the ' 'right number of syllables: == '.format(form_name)) print('\n'.join(problem_lines) + '\n') problem_rhymes = poetry_functions.check_rhyme_scheme( poem_lines, pattern, word_to_phonemes) if len(problem_rhymes) == 0: print('The poem follows the rhyme scheme.\n') else: print('\n== The poem is not a {}. These lines should rhyme' " but don't: ==".format(form_name)) for lines in problem_rhymes: print('\n'.join(lines) + '\n')
def test_multi_no_syllable_requirement(self): """Test check_syllable_counts with no syllable requirements and multiple lines each with multiple words. Multiple lines are being tested in this case.""" pattern = ([0, 0, 0], ['A', 'B', 'A']) word_to_phonemes = {'THE': ['DH', 'AH0'], 'FIRST': ['F', 'ER1', 'S', 'T'], 'LINE': ['L', 'AY1', 'N'], 'LEADS': ['L', 'IY1', 'D', 'Z'], 'OFF': ['AO1', 'F'], 'WITH': ['W', 'IH1', 'DH'], 'A': ['AH0'], 'GAP': ['G', 'AE1', 'P'], 'BEFORE': ['B', 'IH0', 'F', 'AO1', 'R'], 'NEXT': ['N', 'EH1', 'K', 'S', 'T'], 'THEN': ['DH', 'EH1', 'N'], 'POEM': ['P', 'OW1', 'AH0', 'M'], 'ENDS': ['EH1', 'N', 'D', 'Z'] } poem_lines = ['The first line leads off,', 'With a gap before the next.', 'Then the poem ends.'] actual = poetry_functions.check_syllable_counts(poem_lines, pattern, word_to_phonemes) expected = [] self.assertEqual(actual, expected)
def test_line_with_internal_punctuation(self): """Test check_syllable_counts with a single line that contains various punctuation inside of the line, but not inside of words.""" pattern = ([8], ['A']) word_to_phonemes = {'POEM': ['P', 'OW1', 'AH0', 'M']} poem_lines = ['....!!!!Poem$$ poem -- + poem poem!!.. ! $ @'] actual = poetry_functions.check_syllable_counts(poem_lines, pattern, word_to_phonemes) expected = [] self.assertEqual(actual, expected)
def test_single_syllable_requirment_match(self): """Test check_syllable_counts with a single syllable requirement. Since pattern[0] only has 1 value, there must only be 1 line in poem_lines. In this test there is only 1 word. The word has the correct number of syllables.""" pattern = ([2], ['A']) word_to_phonemes = {'POEM': ['P', 'OW1', 'AH0', 'M']} poem_lines = ['Poem'] actual = poetry_functions.check_syllable_counts(poem_lines, pattern, word_to_phonemes) expected = [] self.assertEqual(actual, expected)
def test_single_word_with_single_surrounding_punctuation(self): """Test check_syllable_counts with a single word that has a single exclamation mark punctuation at the beginning and end.""" pattern = ([2], ['A']) word_to_phonemes = {'POEM': ['P', 'OW1', 'AH0', 'M']} poem_lines = ['!Poem!'] actual = poetry_functions.check_syllable_counts(poem_lines, pattern, word_to_phonemes) expected = [] self.assertEqual(actual, expected)
def test_check_syllable_counts_one_line_poem(self): """ Test check_syllable_counts on a one line poem. """ poem_lines = ['How now brown cow.'] pattern = ([4], ['A']) actual = poetry_functions.check_syllable_counts( poem_lines, pattern, pronunciation_dict) expected = [] self.assertEqual(actual, expected, 'one-line poem')
def test_single_word_with_multiple_surrounding_punctuation(self): """Test check_syllable_counts with a single word that is surrounded by multiple punctuation characters.""" pattern = ([2], ['A']) word_to_phonemes = {'POEM': ['P', 'OW1', 'AH0', 'M']} poem_lines = ['....!!!!Poem!!!!....'] actual = poetry_functions.check_syllable_counts(poem_lines, pattern, word_to_phonemes) expected = [] self.assertEqual(actual, expected)
def test_check_syllable_counts_one_line_poem(self): """ Test check_syllable_counts on a one line poem. """ poem_lines = ['How now brown cow.'] pattern = ([4], ['A']) actual = poetry_functions.check_syllable_counts(poem_lines, pattern, pronunciation_dict) expected = [] self.assertEqual(actual, expected, 'one-line poem')
def test_line_with_internal_punctuation(self): """Test check_syllable_counts with a single line that contains various punctuation inside of the line, but not inside of words.""" pattern = ([8], ['A']) word_to_phonemes = {'POEM': ['P', 'OW1', 'AH0', 'M']} poem_lines = ['....!!!!Poem$$ poem -- + poem poem!!.. ! $ @'] actual = poetry_functions.check_syllable_counts( poem_lines, pattern, word_to_phonemes) expected = [] self.assertEqual(actual, expected)
def test_single_word_with_single_surrounding_punctuation(self): """Test check_syllable_counts with a single word that has a single exclamation mark punctuation at the beginning and end.""" pattern = ([2], ['A']) word_to_phonemes = {'POEM': ['P', 'OW1', 'AH0', 'M']} poem_lines = ['!Poem!'] actual = poetry_functions.check_syllable_counts( poem_lines, pattern, word_to_phonemes) expected = [] self.assertEqual(actual, expected)
def test_single_syllable_requirment_match(self): """Test check_syllable_counts with a single syllable requirement. Since pattern[0] only has 1 value, there must only be 1 line in poem_lines. In this test there is only 1 word. The word has the correct number of syllables.""" pattern = ([2], ['A']) word_to_phonemes = {'POEM': ['P', 'OW1', 'AH0', 'M']} poem_lines = ['Poem'] actual = poetry_functions.check_syllable_counts( poem_lines, pattern, word_to_phonemes) expected = [] self.assertEqual(actual, expected)
def test_single_syllable_requirement_no_match(self): """Test check_syllable_counts with a single syllable requirement. Since pattern[0] only has 1 value, there must only be 1 line in poem_lines. In this test there is only 1 word. The word does not have the correct number of syllables.""" pattern = ([1], ['A']) word_to_phonemes = {'BEFORE': ['B', 'IH0', 'F', 'AO1', 'R']} poem_lines = ['Before'] actual = poetry_functions.check_syllable_counts(poem_lines, pattern, word_to_phonemes) expected = ['Before'] self.assertEqual(actual, expected)
def test_check_syllable_counts_empty_poem(self): """ Test check_syllable_counts on an empty poem. """ poem_lines = [] pattern = ([], []) actual = poetry_functions.check_syllable_counts( poem_lines, pattern, pronunciation_dict) expected = [] self.assertEqual(actual, expected, 'empty poem')
def test_single_syllable_requirement_no_match(self): """Test check_syllable_counts with a single syllable requirement. Since pattern[0] only has 1 value, there must only be 1 line in poem_lines. In this test there is only 1 word. The word does not have the correct number of syllables.""" pattern = ([1], ['A']) word_to_phonemes = {'BEFORE': ['B', 'IH0', 'F', 'AO1', 'R']} poem_lines = ['Before'] actual = poetry_functions.check_syllable_counts( poem_lines, pattern, word_to_phonemes) expected = ['Before'] self.assertEqual(actual, expected)
def test_multi_syllable_requirement_match(self): """Test check_syllable_counts with multiple syllable requirements. Since pattern[0] has 3 values, there must only be 3 lines in poem_lines. The number of words in each line is not being tested. The syllables in the lines of poem_lines match up with those in pattern[0].""" pattern = ([2, 1, 2], ['A', 'B', 'C']) word_to_phonemes = {'BEFORE': ['B', 'IH0', 'F', 'AO1', 'R'], 'NEXT': ['N', 'EH1', 'K', 'S', 'T'], 'POEM': ['P', 'OW1', 'AH0', 'M']} poem_lines = ['Before,', 'next,', 'poem!!!'] actual = poetry_functions.check_syllable_counts(poem_lines, pattern, word_to_phonemes) expected = [] self.assertEqual(actual, expected)
def test_single_word_with_multiple_surrounding_punctuation(self): """Test check_syllable_counts with a single word that is surrounded by multiple punctuation characters.""" pattern = ([2], ['A']) word_to_phonemes = {'POEM': ['P', 'OW1', 'AH0', 'M']} poem_lines = ['....!!!!Poem!!!!....'] actual = poetry_functions.check_syllable_counts( poem_lines, pattern, word_to_phonemes) expected = [] self.assertEqual(actual, expected)
def test_check_syllable_counts_three_line_poem_with_all_specified(self): """ Test check_syllable_counts on a three-line poem with all specified \ number of syllable. """ poem_lines = ['How', 'now', 'brown cow.'] pattern = ([1, 1, 2], ['A', 'A', 'A']) actual = poetry_functions.check_syllable_counts( poem_lines, pattern, pronunciation_dict) expected = [] self.assertEqual(actual, expected, 'three-line poem all specified')
def test_check_syllable_counts_one_line_poem_with_no_specified(self): """ Test check_syllable_counts on a one-line poem with no specified \ number of syllable. """ poem_lines = ['How now brown cow.'] pattern = ([0], ['A']) actual = poetry_functions.check_syllable_counts( poem_lines, pattern, pronunciation_dict) expected = [] self.assertEqual(actual, expected, 'one-line poem no specified')
def test_multiple_lines_single_word(self): """Test with multiple lines made of single words. The syllable requirements are not being tested.""" pattern = ([2, 2, 1], ['A', 'B', 'C']) word_to_phonemes = {'POEM': ['P', 'OW1', 'AH0', 'M'], 'THE': ['DH', 'AH0'], 'ENDS': ['EH1', 'N', 'D', 'Z']} poem_lines = ['The', 'poem', 'ends!'] actual = poetry_functions.check_syllable_counts(poem_lines, pattern, word_to_phonemes) expected = ['The'] self.assertEqual(actual, expected)
def test_multi_syllable_requirement_match(self): """Test check_syllable_counts with multiple syllable requirements. Since pattern[0] has 3 values, there must only be 3 lines in poem_lines. The number of words in each line is not being tested. The syllables in the lines of poem_lines match up with those in pattern[0].""" pattern = ([2, 1, 2], ['A', 'B', 'C']) word_to_phonemes = { 'BEFORE': ['B', 'IH0', 'F', 'AO1', 'R'], 'NEXT': ['N', 'EH1', 'K', 'S', 'T'], 'POEM': ['P', 'OW1', 'AH0', 'M'] } poem_lines = ['Before,', 'next,', 'poem!!!'] actual = poetry_functions.check_syllable_counts( poem_lines, pattern, word_to_phonemes) expected = [] self.assertEqual(actual, expected)
def test_multiple_lines_single_word(self): """Test with multiple lines made of single words. The syllable requirements are not being tested.""" pattern = ([2, 2, 1], ['A', 'B', 'C']) word_to_phonemes = { 'POEM': ['P', 'OW1', 'AH0', 'M'], 'THE': ['DH', 'AH0'], 'ENDS': ['EH1', 'N', 'D', 'Z'] } poem_lines = ['The', 'poem', 'ends!'] actual = poetry_functions.check_syllable_counts( poem_lines, pattern, word_to_phonemes) expected = ['The'] self.assertEqual(actual, expected)
def test_single_no_syllable_requirement(self): """Test check_syllable_counts with no syllable requirements and multiple lines each with multiple words.""" pattern = ([0], ['A']) word_to_phonemes = {'THE': ['DH', 'AH0'], 'FIRST': ['F', 'ER1', 'S', 'T'], 'LINE': ['L', 'AY1', 'N'], 'LEADS': ['L', 'IY1', 'D', 'Z'], 'OFF': ['AO1', 'F'], 'GAP': ['G', 'AE1', 'P'], } poem_lines = ['The first line leads off the gap,'] actual = poetry_functions.check_syllable_counts(poem_lines, pattern, word_to_phonemes) expected = [] self.assertEqual(actual, expected)
def test_single_no_syllable_requirement(self): """Test check_syllable_counts with no syllable requirements and multiple lines each with multiple words.""" pattern = ([0], ['A']) word_to_phonemes = { 'THE': ['DH', 'AH0'], 'FIRST': ['F', 'ER1', 'S', 'T'], 'LINE': ['L', 'AY1', 'N'], 'LEADS': ['L', 'IY1', 'D', 'Z'], 'OFF': ['AO1', 'F'], 'GAP': ['G', 'AE1', 'P'], } poem_lines = ['The first line leads off the gap,'] actual = poetry_functions.check_syllable_counts( poem_lines, pattern, word_to_phonemes) expected = [] self.assertEqual(actual, expected)
'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'] } # Type check poetry_functions.check_syllable_counts result = poetry_functions.check_syllable_counts(poem_lines, pattern, word_to_phonemes) assert isinstance(result, list), \ '''poetry_functions.check_syllable_counts should return a list,''' \ ''' but returned {0}.'''.format(type(result)) for item in result: assert isinstance(item, str), \ '''poetry_functions.check_syllable_counts should return a list''' \ ''' of str, but returned a list of {0}.'''.format(type(item)) # Type check poetry_functions.check_rhyme_scheme result = poetry_functions.check_rhyme_scheme(poem_lines, pattern, word_to_phonemes) assert isinstance(result, list), \ '''poetry_functions.check_rhyme_scheme should return a list of''' \ ''' list of str, but returned {0}.'''.format(type(result)) for item in result: