示例#1
0
 def test_compare_sentences_missing_punctuation(self):
     sentence = Sentence([Verb('go').capitalize(), Punctuation.PERIOD])
     submission_str = 'Go'
     answer = compare_sentences(sentence, submission_str)
     expected = {
         'hint_sentence': 'Go <bold>MISSING</bold>',
         'error_count': 1
     }
     self.assertEqual(answer, expected)
示例#2
0
 def test_compare_sentences_two_words_in_wrong_place(self):
     sentence = Sentence([Noun('a'), Noun('b'), Noun('c'), Noun('d')])
     submission_str = 'a c d b'
     answer = compare_sentences(sentence, submission_str)
     expected = {
         'hint_sentence': 'a <bold>c</bold> <bold>d</bold> b',
         'error_count': 2
     }
     self.assertEqual(answer, expected)
示例#3
0
 def test_compare_sentences(self):
     sentence = Sentence([
         Noun('dog').definite().capitalize(),
         Verb('play').third_person(), Punctuation.PERIOD
     ])
     submission_str = 'The dog plays.'
     answer = compare_sentences(sentence, submission_str)
     expected = {'hint_sentence': submission_str, 'error_count': 0}
     self.assertEqual(answer, expected)
示例#4
0
 def test_compare_sentences_LIMITATION_two_separate_words_in_wrong_place_is_handled_incorrectly(
         self):
     sentence = Sentence([Noun('a'), Noun('b'), Noun('c'), Noun('d')])
     submission_str = 'd a c b'
     answer = compare_sentences(sentence, submission_str)
     expected = {
         'hint_sentence': '<bold>d</bold> a c <bold>b</bold>',
         'error_count': 2
     }
     self.assertEqual(answer, expected)
示例#5
0
 def test_compare_sentences_repeating_words_no_errors(self):
     sentence = Sentence([
         Noun('dog').plural().capitalize(),
         Verb('dog'),
         Noun('dog').definite(), Punctuation.PERIOD
     ])
     submission_str = 'Dogs dog the dog.'
     answer = compare_sentences(sentence, submission_str)
     expected = {'hint_sentence': submission_str, 'error_count': 0}
     self.assertEqual(answer, expected)
示例#6
0
 def test_compare_sentences_two_extra_words_together(self):
     sentence = Sentence(
         [Noun('a'), Verb('b'), Pronoun.HE, Punctuation.PERIOD])
     submission_str = 'a b he c c.'
     answer = compare_sentences(sentence, submission_str)
     expected = {
         'hint_sentence': 'a b he <bold>c</bold> <bold>c</bold>.',
         'error_count': 2
     }
     self.assertEqual(answer, expected)
示例#7
0
 def test_compare_sentences_extra_word_middle(self):
     sentence = Sentence(
         [Noun('a'), Verb('b'), Pronoun.HE, Punctuation.PERIOD])
     submission_str = 'a b c he.'
     answer = compare_sentences(sentence, submission_str)
     expected = {
         'hint_sentence': 'a b <bold>c</bold> he.',
         'error_count': 1
     }
     self.assertEqual(answer, expected)
示例#8
0
 def test_compare_sentences_missing_word_start_of_sentence(self):
     sentence = Sentence(
         [Noun('a'), Verb('b'), Pronoun.HE, Punctuation.PERIOD])
     submission_str = 'b he.'
     answer = compare_sentences(sentence, submission_str)
     expected = {
         'hint_sentence': '<bold>MISSING</bold> b he.',
         'error_count': 1
     }
     self.assertEqual(answer, expected)
示例#9
0
 def test_compare_sentences_does_not_double_count_error_for_wrong_word_and_wrong_order(
         self):
     sentence = Sentence(
         [Noun('dog').indefinite(),
          Verb('play').third_person()])
     submission_str = 'play dog'
     answer = compare_sentences(sentence, submission_str)
     expected = {
         'hint_sentence': '<bold>play</bold> <bold>dog</bold>',
         'error_count': 2
     }
     self.assertEqual(answer, expected)
示例#10
0
 def test_compare_sentences_with_error_basic(self):
     sentence = Sentence([
         Noun('dog').definite().capitalize(),
         Verb('play').third_person(), Punctuation.PERIOD
     ])
     submission_str = 'A dog played.'
     answer = compare_sentences(sentence, submission_str)
     expected = {
         'hint_sentence': "<bold>A dog</bold> <bold>played</bold>.",
         'error_count': 2
     }
     self.assertEqual(answer, expected)
示例#11
0
 def test_compare_sentences_missing_words_and_wrong_order(self):
     sentence = Sentence(
         [Noun('a'),
          Noun('b'),
          Noun('c'),
          Noun('d'), Punctuation.PERIOD])
     submission_str = 'a d c.'
     answer = compare_sentences(sentence, submission_str)
     expected = {
         'hint_sentence': 'a <bold>MISSING</bold> <bold>d</bold> c.',
         'error_count': 2
     }
     self.assertEqual(answer, expected)
示例#12
0
 def test_compare_sentences_extra_words_and_wrong_order(self):
     sentence = Sentence([
         Noun('dog').definite().capitalize(),
         Verb('play').third_person(),
         BasicWord.preposition('with'),
         Noun('cat').indefinite(), Punctuation.PERIOD
     ])
     submission_str = 'extra The dog extra with extra a cat extra plays extra.'
     answer = compare_sentences(sentence, submission_str)
     extra = '<bold>extra</bold>'
     expected_hint = f'{extra} The dog {extra} <bold>with</bold> {extra} <bold>a cat</bold> {extra} plays {extra}.'
     expected = {'hint_sentence': expected_hint, 'error_count': 7}
     self.assertEqual(answer, expected)
示例#13
0
 def test_compare_sentences_exclamation_can_switch_to_period(self):
     sentence = Sentence([Verb('go').capitalize(), Punctuation.EXCLAMATION])
     submission_str = 'Go.'
     answer = compare_sentences(sentence, submission_str)
     expected = {'hint_sentence': 'Go.', 'error_count': 0}
     self.assertEqual(answer, expected)