Skip to content

Commit

Permalink
Merge pull request #138 from lambda-feedback/tr112-atol-rtol-zero-beh…
Browse files Browse the repository at this point in the history
…aviour

Fixed potential bug when either atol or rtol was zero but not the other
  • Loading branch information
KarlLundengaard committed Oct 19, 2023
2 parents a2dd059 + e1ba05b commit 355d668
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/symbolic_comparison_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,15 @@ def replace_pi(expr):
return expr.subs(pi_symbol, float(pi))
ans = replace_pi(ans)
res = replace_pi(res)
if "atol" in params.keys():
if float(params.get("atol", 0)) > 0:
try:
absolute_error = abs(float(ans-res))
error_below_atol = bool(absolute_error < float(params["atol"]))
except TypeError:
error_below_atol = None
else:
error_below_atol = True
if "rtol" in params.keys():
if float(params.get("rtol", 0)) > 0:
try:
relative_error = abs(float((ans-res)/ans))
error_below_rtol = bool(relative_error < float(params["rtol"]))
Expand Down
14 changes: 11 additions & 3 deletions app/symbolic_comparison_evaluation_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,8 @@ def test_empty_input_symbols_codes_and_alternatives(self):
),
(
"Incorrect response, symbolic comparison set with atol=0",
"sqrt(3)+5",
"6.73",
"sqrt(3)+5",
{"atol": 0},
[],
False
Expand Down Expand Up @@ -594,8 +594,8 @@ def test_empty_input_symbols_codes_and_alternatives(self):
),
(
"Incorrect response, symbolic comparison set with atol=0 and rtol=0",
"sqrt(3)+5",
"6.73",
"sqrt(3)+5",
{"rtol": 0, "atol": 0},
[],
False
Expand All @@ -608,6 +608,14 @@ def test_empty_input_symbols_codes_and_alternatives(self):
["WITHIN_TOLERANCE"],
True
),
(
"Correct response, tolerance specified with atol != 0 and rtol = 0",
"6.73",
"sqrt(3)+5",
{"atol": 0.005, "rtol": 0},
["WITHIN_TOLERANCE"],
True
),
(
"Incorrect response, tolerance specified with atol",
"6.7",
Expand Down Expand Up @@ -667,7 +675,7 @@ def test_empty_input_symbols_codes_and_alternatives(self):
]
)
def test_numerical_comparison_problem(self, description, response, answer, tolerance, tags, outcome):
params = {"numerical": True}
params = {"elementary_functions": True}
params.update(tolerance)
result = evaluation_function(response, answer, params, include_test_data=True)
assert result["is_correct"] is outcome
Expand Down

0 comments on commit 355d668

Please sign in to comment.