Beispiel #1
0
 def test_compare_by_sentence_paragraph_str_eq_submission_str(self):
     answer_paragraph = Paragraph([Sentence([BasicWord('a')])])
     submission_str = str(answer_paragraph)
     comparitor = ParagraphComparison(answer_paragraph, submission_str)
     comparison = comparitor.compare_by_sentences()
     expected = {
         'error_count': 0,
         'hint_paragraph': submission_str,
         'missing_sentences': 0
     }
     self.assertEqual(comparison, expected)
Beispiel #2
0
    def test_compare_by_sentence_commas_are_counted_as_sentences(self):
        answer = Paragraph(
            [Sentence([BasicWord(wd), Punctuation.PERIOD]) for wd in 'ABC'])
        submission = 'A, B. C,'
        hint_paragraph = '<bold>A,</bold> B. <bold>C,</bold>'

        comparitor = ParagraphComparison(answer, submission)
        hints = comparitor.compare_by_sentences()
        expected = {
            'error_count': 2,
            'hint_paragraph': hint_paragraph,
            'missing_sentences': 0
        }
        self.assertEqual(hints, expected)
Beispiel #3
0
    def test_compare_by_sentence_allows_periods_to_replace_exclamation_points(
            self):
        answer = Paragraph([
            Sentence([BasicWord('a'), Punctuation.PERIOD]),
            Sentence([BasicWord('b'), Punctuation.PERIOD])
        ])
        submission = 'a! b!'

        comparitor = ParagraphComparison(answer, submission)
        hints = comparitor.compare_by_sentences()
        expected = {
            'error_count': 0,
            'hint_paragraph': submission,
            'missing_sentences': 0
        }
        self.assertEqual(hints, expected)
Beispiel #4
0
    def test_compare_by_sentence_answer_has_less_sentences(self):
        answer = Paragraph([
            Sentence([BasicWord('a'), Punctuation.PERIOD]),
            Sentence([BasicWord('b'), Punctuation.PERIOD])
        ])
        submission = 'a. c. b.'
        hint_paragraph = 'a. <bold>c.</bold> <bold>b.</bold>'

        comparitor = ParagraphComparison(answer, submission)
        hints = comparitor.compare_by_sentences()
        expected = {
            'error_count': 2,
            'hint_paragraph': hint_paragraph,
            'missing_sentences': -1
        }
        self.assertEqual(hints, expected)
Beispiel #5
0
    def test_compare_by_sentence_will_find_the_final_sentence_with_missing_punctuation(
            self):
        answer = Paragraph([
            Sentence([BasicWord('a'), Punctuation.PERIOD]),
            Sentence([BasicWord('b'), Punctuation.PERIOD])
        ])
        submission = 'a. b'
        hint_paragraph = 'a. <bold>b</bold>'

        comparitor = ParagraphComparison(answer, submission)
        hints = comparitor.compare_by_sentences()
        expected = {
            'error_count': 1,
            'hint_paragraph': hint_paragraph,
            'missing_sentences': 0
        }
        self.assertEqual(hints, expected)
Beispiel #6
0
    def test_compare_by_sentence_can_identify_period_comma_exclamation_question(
            self):
        answer = Paragraph([
            Sentence([BasicWord('a'), Punctuation.PERIOD]),
            Sentence([BasicWord('b'), Punctuation.EXCLAMATION]),
            Sentence([BasicWord('c'), Punctuation.QUESTION]),
            Sentence([BasicWord('d'), Punctuation.COMMA])
        ])
        submission = 'a, b, c, d,'
        hint_paragraph = '<bold>a,</bold> <bold>b,</bold> <bold>c,</bold> d,'

        comparitor = ParagraphComparison(answer, submission)
        hints = comparitor.compare_by_sentences()
        expected = {
            'error_count': 3,
            'hint_paragraph': hint_paragraph,
            'missing_sentences': 0
        }
        self.assertEqual(hints, expected)
Beispiel #7
0
    def test_compare_by_sentence_one_sentence_different_by_internals(self):
        answer = Paragraph([
            Sentence([BasicWord('Hello'), Punctuation.PERIOD]),
            Sentence([
                BasicWord('I'),
                BasicWord('am'),
                BasicWord('man'), Punctuation.PERIOD
            ])
        ])
        submission = 'Hello. I am mans.'
        hint_paragraph = 'Hello. <bold>I am mans.</bold>'

        comparitor = ParagraphComparison(answer, submission)
        hints = comparitor.compare_by_sentences()
        expected = {
            'error_count': 1,
            'hint_paragraph': hint_paragraph,
            'missing_sentences': 0
        }
        self.assertEqual(hints, expected)