コード例 #1
0
    def test_normal(self):
        self.assertEqual(
            grammar_check.number_of_errors(
                "They help you stay in touch with family in a couple \
different ways they excercise your mind and hands and help you learn and make things easier."
            ), ([
                ('excercise', 'exercise')
            ], "They help you stay in touch with family in a couple different \
ways they exercise your mind and hands and help you learn and make things easier."
                ), "grammar_checck.py doesn't return expected answer.")
コード例 #2
0
ファイル: grade.py プロジェクト: brandonmiles/project-iga
    def grade_grammar(self, text):
        """
        Returns a grade based on grammar and spelling in the given essay

        Parameters
        ----------
        text : str
            The raw text that will be checked for grammar and spelling mistakes

        Returns
        -------
        tuple of int, str, str
            A tuple containing points(integer), corrected_text(string), debug(string), and feedback(string).
            Points is the number of points lost in this section, being between 0 and rubric['grammar'].
            Corrected_text is the given after being corrected for grammar and spelling mistakes. It is recommended that
            this is used in place of the original text when grading the other sections.
            Debug will contain the number of grammar and spelling mistakes in the text, followed by a list of pairs,
            where each pair contains the mistake and the suggested correction.
            Feedback will contain a pre-written string based on the number of points being taken off.
            See feedback.py for more info.
        """
        points = 0
        debug, output = "", ""

        # Need corrected text for other functions, so always run
        corrections, corrected_text = grammar_check.number_of_errors(text)
        if self.__rubric['grammar'] is not None:
            mistakes = len(corrections)
            if self.__weights['allowed_mistakes'] is not None:
                mistakes = max(mistakes - self.__weights['allowed_mistakes'], 0)

            points = min(self.__weights['grammar'] * mistakes, self.__rubric['grammar'])
            debug += "Errors: " + str(len(corrections)) + "\n"
            debug += str(corrections) + "\n"
            output += feedback.grammar_feedback(round(points * 3 / self.__rubric['grammar']))

        return points, corrected_text, debug, output
コード例 #3
0
 def test_incorrect_word(self):
     self.assertEqual(
         grammar_check.number_of_errors("exrcise"),
         ([("exrcise", "exercise")], "exercise"),
         "grammar_check.py give incorrect return for a single correct word."
     )
コード例 #4
0
 def test_empty_str(self):
     self.assertEqual(grammar_check.number_of_errors(""), ([], ""),
                      "grammar_check.py can't handle empty strings")
コード例 #5
0
 def test_pass_not_str(self):
     with self.assertRaises(TypeError):
         grammar_check.number_of_errors([
             "A", "quick", "brown", "fox", "jumped", "over", "the", "lazy",
             "dog"
         ])