Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed potential bug when either atol or rtol was zero but not the other #138

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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