Commit 06efd40b by Peter Baratta

Comment capitalization

parent 2b9d78df
...@@ -452,9 +452,12 @@ class FormulaResponseTest(ResponseTest): ...@@ -452,9 +452,12 @@ class FormulaResponseTest(ResponseTest):
# Expect such a large answer to be marked incorrect # Expect such a large answer to be marked incorrect
input_formula = "x*1e999" input_formula = "x*1e999"
self.assert_grade(problem, input_formula, "incorrect") self.assert_grade(problem, input_formula, "incorrect")
# Expect such a large negative answer to be marked incorrect
input_formula = "-x*1e999"
self.assert_grade(problem, input_formula, "incorrect")
def test_grade_nan(self): def test_grade_nan(self):
# attempt to produce a value which causes the student's answer to be # Attempt to produce a value which causes the student's answer to be
# evaluated to nan. See if this is resolved correctly. # evaluated to nan. See if this is resolved correctly.
sample_dict = {'x': (1, 2)} sample_dict = {'x': (1, 2)}
...@@ -465,7 +468,7 @@ class FormulaResponseTest(ResponseTest): ...@@ -465,7 +468,7 @@ class FormulaResponseTest(ResponseTest):
tolerance="1%", tolerance="1%",
answer="x") answer="x")
# Expect an incorrect answer (+ nan) to be marked incorrect # Expect an incorrect answer (+ nan) to be marked incorrect
# right now this evaluates to 'nan' for a given x (Python implementation-dependent) # Right now this evaluates to 'nan' for a given x (Python implementation-dependent)
input_formula = "10*x + 0*1e999" input_formula = "10*x + 0*1e999"
self.assert_grade(problem, input_formula, "incorrect") self.assert_grade(problem, input_formula, "incorrect")
# Expect an correct answer (+ nan) to be marked incorrect # Expect an correct answer (+ nan) to be marked incorrect
...@@ -756,18 +759,19 @@ class NumericalResponseTest(ResponseTest): ...@@ -756,18 +759,19 @@ class NumericalResponseTest(ResponseTest):
answer=4, answer=4,
tolerance="10%") tolerance="10%")
correct_responses = [] correct_responses = []
incorrect_responses = ["1e999"] incorrect_responses = ["1e999", "-1e999"]
self.assert_multiple_grade(problem, correct_responses, incorrect_responses) self.assert_multiple_grade(problem, correct_responses, incorrect_responses)
def test_grade_nan(self): def test_grade_nan(self):
# attempt to produce a value which causes the student's answer to be # Attempt to produce a value which causes the student's answer to be
# evaluated to nan. See if this is resolved correctly. # evaluated to nan. See if this is resolved correctly.
problem = self.build_problem(question_text="What is 2 + 2 approximately?", problem = self.build_problem(question_text="What is 2 + 2 approximately?",
explanation="The answer is 4", explanation="The answer is 4",
answer=4, answer=4,
tolerance="10%") tolerance="10%")
correct_responses = [] correct_responses = []
# right now these evaluate to 'nan' # Right now these evaluate to `nan`
# `4 + nan` should be incorrect
incorrect_responses = ["0*1e999", "4 + 0*1e999"] incorrect_responses = ["0*1e999", "4 + 0*1e999"]
self.assert_multiple_grade(problem, correct_responses, incorrect_responses) self.assert_multiple_grade(problem, correct_responses, incorrect_responses)
......
...@@ -23,7 +23,9 @@ def compare_with_tolerance(v1, v2, tol): ...@@ -23,7 +23,9 @@ def compare_with_tolerance(v1, v2, tol):
tolerance = evaluator(dict(), dict(), tol) tolerance = evaluator(dict(), dict(), tol)
if isinf(v1) or isinf(v2): if isinf(v1) or isinf(v2):
# because the other numerical comparison does not work with infinities # If an input is infinite, we can end up with `abs(v1-v2)` and
# `tolerance` both equal to infinity. Then, below we would have
# `inf <= inf` which is a fail. Instead, compare directly.
return v1 == v2 return v1 == v2
else: else:
return abs(v1 - v2) <= tolerance return abs(v1 - v2) <= tolerance
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment