From 68ee26a165654247a53032db8f49c5476ffd7965 Mon Sep 17 00:00:00 2001 From: Marcus Messer Date: Thu, 2 Oct 2025 10:54:27 +0100 Subject: [PATCH 1/3] Added __init__ to tests to enable support of IDE test features --- app/tests/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 app/tests/__init__.py diff --git a/app/tests/__init__.py b/app/tests/__init__.py new file mode 100644 index 0000000..e69de29 From 8e0b63efcaf72c4ff95d847e968a393cf7b237ea Mon Sep 17 00:00:00 2001 From: Marcus Messer Date: Thu, 2 Oct 2025 10:56:59 +0100 Subject: [PATCH 2/3] Added relative_tolerance and absolute_tolerance as alternatives for rtol and atol respectively --- app/evaluation.py | 7 +++++- .../physical_quantity_evaluation_tests.py | 24 +++++++++++++++++++ app/tests/symbolic_evaluation_tests.py | 13 ++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/app/evaluation.py b/app/evaluation.py index a99ee01..891f9af 100644 --- a/app/evaluation.py +++ b/app/evaluation.py @@ -233,6 +233,12 @@ def evaluation_function(response, answer, params, include_test_data=False) -> di - if set to True, use basic dimensional analysis functionality. """ + if "relative_tolerance" in params: + params["rtol"] = params["relative_tolerance"] + + if "absolute_tolerance" in params: + params["atol"] = params["absolute_tolerance"] + evaluation_result = EvaluationResult() evaluation_result.is_correct = False @@ -318,7 +324,6 @@ def evaluation_function(response, answer, params, include_test_data=False) -> di "reserved_expressions": reserved_expressions_parsed, "criteria": criteria, "disabled_evaluation_nodes": parameters.get("disabled_evaluation_nodes", set()), - "evaluation_result": evaluation_result, "parsing_parameters": parsing_parameters, "evaluation_result": evaluation_result, "syntactical_comparison": parameters.get("syntactical_comparison", False), diff --git a/app/tests/physical_quantity_evaluation_tests.py b/app/tests/physical_quantity_evaluation_tests.py index a427ced..28fcc61 100644 --- a/app/tests/physical_quantity_evaluation_tests.py +++ b/app/tests/physical_quantity_evaluation_tests.py @@ -337,6 +337,18 @@ def test_physical_quantity_with_rtol(self): result = evaluation_function(res, ans, params, include_test_data=True) assert result["is_correct"] is True + def test_physical_quantity_with_rel_tol(self): + ans = "7500 m/s" + res = "7504.1 m/s" + params = { + 'relative_tolerance': 0.05, + 'strict_syntax': False, + 'physical_quantity': True, + 'elementary_functions': True, + } + result = evaluation_function(res, ans, params, include_test_data=True) + assert result["is_correct"] is True + def test_physical_quantity_with_atol(self): ans = "7500 m/s" res = "7504.1 m/s" @@ -349,6 +361,18 @@ def test_physical_quantity_with_atol(self): result = evaluation_function(res, ans, params, include_test_data=True) assert result["is_correct"] is True + def test_physical_quantity_with_abs_tol(self): + ans = "7500 m/s" + res = "7504.1 m/s" + params = { + 'absolute_tolerance': 5, + 'strict_syntax': False, + 'physical_quantity': True, + 'elementary_functions': True, + } + result = evaluation_function(res, ans, params, include_test_data=True) + assert result["is_correct"] is True + def test_tolerance_given_as_string(self): ans = "4.52 kg" res = "13.74 kg" diff --git a/app/tests/symbolic_evaluation_tests.py b/app/tests/symbolic_evaluation_tests.py index 33fcbce..2ac4b98 100644 --- a/app/tests/symbolic_evaluation_tests.py +++ b/app/tests/symbolic_evaluation_tests.py @@ -919,6 +919,19 @@ def test_pi_with_rtol(self): result = evaluation_function(response, answer, params) assert result["is_correct"] is True + def test_pi_with_rel_tol(self): + answer = "pi" + response = "3.14" + params = { + "strict_syntax": False, + "relative_tolerance": 0.05, + "symbols": { + "pi": {"aliases": ["Pi", "PI", "π"], "latex": "\\(\\pi\\)"}, + } + } + result = evaluation_function(response, answer, params) + assert result["is_correct"] is True + @pytest.mark.parametrize( "response,outcome", [ From e2bbf258e5880232a43de2762c77d4833b6e8845 Mon Sep 17 00:00:00 2001 From: Marcus Messer Date: Thu, 2 Oct 2025 11:00:01 +0100 Subject: [PATCH 3/3] Updated user docs --- app/docs/user.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/docs/user.md b/app/docs/user.md index 1c0b5a5..a2d887e 100644 --- a/app/docs/user.md +++ b/app/docs/user.md @@ -8,10 +8,10 @@ Note that this function is designed to handle comparisons of mathematical expres ### Optional parameters -There are 15 optional parameters that can be set: `atol`, `complexNumbers`, `convention`, `criteria`, `elementary_functions`, `feedback_for_incorrect_response`, `multiple_answers_criteria`, `physical_quantity`, `plus_minus`/`minus_plus`, `rtol`, `specialFunctions`, `strict_syntax`, `strictness`, `symbol_assumptions`. +There are 15 optional parameters that can be set: `absolute_tolerance`, `complexNumbers`, `convention`, `criteria`, `elementary_functions`, `feedback_for_incorrect_response`, `multiple_answers_criteria`, `physical_quantity`, `plus_minus`/`minus_plus`, `rtol`, `specialFunctions`, `strict_syntax`, `strictness`, `symbol_assumptions`. -#### `atol` -Sets the absolute tolerance, $e_a$, i.e. if the answer, $x$, and response, $\tilde{x}$, are numerical values then the response is considered equal to the answer if $|x-\tilde{x}| \leq e_aBy default `atol` is set to `0`, which means the comparison will be done with as high accuracy as possible. If either the answer or the response aren't numerical expressions this parameter is ignored. +#### `absolute_tolerance` (`atol`) +Sets the absolute tolerance, $e_a$, i.e. if the answer, $x$, and response, $\tilde{x}$, are numerical values then the response is considered equal to the answer if $|x-\tilde{x}| \leq e_aBy default `absolute_tolerance` is set to `0`, which means the comparison will be done with as high accuracy as possible. If either the answer or the response aren't numerical expressions this parameter is ignored. #### `complexNumbers` @@ -77,8 +77,8 @@ When `physical_quantity` the evaluation function will generate feedback based on **TODO:** Generate new flowchart for updated physical quantity feedback generation procedure. -#### `rtol` -Sets the relative tolerance, $e_r$, i.e. if the answer, $x$, and response, $\tilde{x}$, are numerical values then the response is considered equal to the answer if $\left|\frac{x-\tilde{x}}{x}\right| \leq e_r$. By default `rtol` is set to `0`, which means the comparison will be done with as high accuracy as possible. If either the answer or the response aren't numerical expressions this parameter is ignored. +#### `relative_tolerance` (`rtol`) +Sets the relative tolerance, $e_r$, i.e. if the answer, $x$, and response, $\tilde{x}$, are numerical values then the response is considered equal to the answer if $\left|\frac{x-\tilde{x}}{x}\right| \leq e_r$. By default `relative_tolerance` is set to `0`, which means the comparison will be done with as high accuracy as possible. If either the answer or the response aren't numerical expressions this parameter is ignored. #### `strictness`