Exemple #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)
Exemple #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)
Exemple #3
0
    def test_compare_by_words_extra_sentence_MINOR_ISSUE_WITH_PUNCTUATION(
            self):
        answer = Paragraph(
            [Sentence([Verb('go', 'went'), Punctuation.PERIOD])])
        submission = "go. now. please!"
        hint_paragraph = "go. <bold>now</bold> <bold>.</bold> <bold>please</bold> <bold>!</bold>"

        comparitor = ParagraphComparison(answer, submission)
        hints = comparitor.compare_by_words()
        expected = {
            'error_count': 4,
            'hint_paragraph': hint_paragraph,
            'missing_sentences': -2
        }
        self.assertEqual(hints, expected)
Exemple #4
0
    def test_compare_by_words_pronoun_errors_subject_object(self):
        answer = Paragraph([
            Sentence([Pronoun.I.capitalize(), Pronoun.ME, Punctuation.PERIOD])
        ])
        submission = 'Me I.'
        hint_paragraph = '<bold>Me</bold> <bold>I</bold>.'

        comparitor = ParagraphComparison(answer, submission)
        hints = comparitor.compare_by_words()
        expected = {
            'error_count': 2,
            'hint_paragraph': hint_paragraph,
            'missing_sentences': 0
        }
        self.assertEqual(hints, expected)
Exemple #5
0
    def test_compare_by_words_extra_word_errors(self):
        answer = Paragraph([
            Sentence([Verb('go', 'went'), Punctuation.PERIOD]),
            Sentence([Verb('play'), Punctuation.PERIOD])
        ])
        submission = "I go. play it."
        hint_paragraph = "<bold>I</bold> go. play <bold>it</bold>."

        comparitor = ParagraphComparison(answer, submission)
        hints = comparitor.compare_by_words()
        expected = {
            'error_count': 2,
            'hint_paragraph': hint_paragraph,
            'missing_sentences': 0
        }
        self.assertEqual(hints, expected)
Exemple #6
0
    def test_compare_by_word_punctuation_allows_period_and_exclamation_point_to_be_switched(
            self):
        answer = Paragraph([
            Sentence([Verb('go', 'went'), Punctuation.PERIOD]),
            Sentence([Verb('go', 'went'), Punctuation.EXCLAMATION])
        ])
        submission = "go! go."

        comparitor = ParagraphComparison(answer, submission)
        hints = comparitor.compare_by_words()
        expected = {
            'error_count': 0,
            'hint_paragraph': submission,
            'missing_sentences': 0
        }
        self.assertEqual(hints, expected)
Exemple #7
0
    def test_compare_by_words_noun_errors(self):
        answer = Paragraph([
            Sentence([Noun('dog').definite(), Punctuation.PERIOD]),
            Sentence([Noun('cat').plural(), Punctuation.PERIOD])
        ])
        submission = 'a dog. The cats.'
        hint_paragraph = '<bold>a dog</bold>. <bold>The cats</bold>.'

        comparitor = ParagraphComparison(answer, submission)
        hints = comparitor.compare_by_words()
        expected = {
            'error_count': 2,
            'hint_paragraph': hint_paragraph,
            'missing_sentences': 0
        }
        self.assertEqual(hints, expected)
Exemple #8
0
    def test_compare_by_words_no_errors(self):
        answer = Paragraph([
            Sentence([BasicWord('a'), Punctuation.PERIOD]),
            Sentence([BasicWord('b'), Punctuation.PERIOD])
        ])
        submission = 'a. b.'
        hint_paragraph = 'a. b.'

        comparitor = ParagraphComparison(answer, submission)
        hints = comparitor.compare_by_words()
        expected = {
            'error_count': 0,
            'hint_paragraph': hint_paragraph,
            'missing_sentences': 0
        }
        self.assertEqual(hints, expected)
Exemple #9
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)
Exemple #10
0
    def test_init(self):
        answer_paragraph = Paragraph([Sentence([BasicWord('a')])])
        submission_str = 'b'

        comparitor = ParagraphComparison(answer_paragraph, submission_str)
        self.assertEqual(comparitor.answer, answer_paragraph)
        self.assertEqual(comparitor.submission, 'b')
Exemple #11
0
    def test_compare_by_words_punctuation_errors(self):
        answer = Paragraph([
            Sentence([Verb('go', 'went'), Punctuation.PERIOD]),
            Sentence([Verb('play'), Punctuation.PERIOD])
        ])
        submission = "go, play "
        hint_paragraph = "go<bold>,</bold> play <bold>MISSING</bold>"

        comparitor = ParagraphComparison(answer, submission)
        hints = comparitor.compare_by_words()
        expected = {
            'error_count': 2,
            'hint_paragraph': hint_paragraph,
            'missing_sentences': 0
        }
        self.assertEqual(hints, expected)
Exemple #12
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)
Exemple #13
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)
Exemple #14
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)
Exemple #15
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)
Exemple #16
0
    def test_compare_by_words_word_order_errors(self):
        answer = Paragraph([
            Sentence([Pronoun.I,
                      Verb('go', 'went'), Punctuation.PERIOD]),
            Sentence([
                Noun('cat'),
                Verb('play'),
                BasicWord('with'), Pronoun.HIM, Punctuation.PERIOD
            ])
        ])
        submission = "go I. cat with him play."
        hint_paragraph = "<bold>go</bold> I. cat <bold>with</bold> <bold>him</bold> play."

        comparitor = ParagraphComparison(answer, submission)
        hints = comparitor.compare_by_words()
        expected = {
            'error_count': 3,
            'hint_paragraph': hint_paragraph,
            'missing_sentences': 0
        }
        self.assertEqual(hints, expected)
Exemple #17
0
 def _get_comparitor(self):
     answer_paragraph = create_answer_paragraph(self._submission,
                                                self._original)
     comparison = ParagraphComparison(answer_paragraph, self._submission)
     return comparison