Exemplo n.º 1
0
    def test_float_matcher_grade_neither_rtol_nor_atol(self):
        matcher = FloatMatcher(
            None, "", dict_to_struct({
                "type": "float",
                "value": "20.1",
            }))
        self.assertEqual(matcher.grade(""), 0)
        self.assertEqual(matcher.grade("abcd"), 0)

        self.assertEqual(matcher.grade(20000), 1)
        self.assertEqual(matcher.grade(-2), 1)
Exemplo n.º 2
0
    def test_float_matcher_grade_neither_rtol_nor_atol(self):
        matcher = FloatMatcher(None, "",
                               dict_to_struct(
                                   {"type": "float",
                                    "value": "20.1",
                                    }))
        self.assertEqual(matcher.grade(""), 0)
        self.assertEqual(matcher.grade("abcd"), 0)

        self.assertEqual(matcher.grade(20000), 1)
        self.assertEqual(matcher.grade(-2), 1)
Exemplo n.º 3
0
    def test_float_matcher_grade_inf(self):
        matcher = FloatMatcher(None, "",
                               dict_to_struct(
                                   {"type": "float",
                                    "value": "inf",
                                    "rtol": 0.01
                                    }))

        self.assertEqual(matcher.grade(float("nan")), 0)
        self.assertEqual(matcher.grade(float("inf")), 1)
        self.assertEqual(matcher.grade(float("20.5")), 0)
Exemplo n.º 4
0
    def test_float_matcher_grade_atol(self):
        matcher = FloatMatcher(None, "",
                               dict_to_struct(
                                   {"type": "float",
                                    "value": "1",
                                    "atol": 0.01
                                    }))
        self.assertEqual(matcher.grade(""), 0)
        self.assertEqual(matcher.grade(0), 0)
        self.assertEqual(matcher.grade("abcd"), 0)

        self.assertEqual(matcher.grade(1), 1)
        self.assertEqual(matcher.grade(1.005), 1)
        self.assertEqual(matcher.grade(1.02), 0)

        self.assertEqual(matcher.grade(float("nan")), 0)
        self.assertEqual(matcher.grade(float("inf")), 0)
Exemplo n.º 5
0
    def test_float_matcher_grade_rtol(self):
        matcher = FloatMatcher(None, "",
                               dict_to_struct(
                                   {"type": "float",
                                    "value": "100.1",
                                    "rtol": 0.01
                                    }))
        self.assertEqual(matcher.grade(""), 0)
        self.assertEqual(matcher.grade(0), 0)
        self.assertEqual(matcher.grade("abcd"), 0)

        self.assertEqual(matcher.grade(100), 1)
        self.assertEqual(matcher.grade(100.9), 1)
        self.assertEqual(matcher.grade(101.11), 0)
        self.assertEqual(matcher.correct_answer_text(), str(100.1))

        self.assertEqual(matcher.grade(float("nan")), 0)
        self.assertEqual(matcher.grade(float("inf")), 0)