Skip to content

Commit 1593985

Browse files
Merge pull request #218 from lambda-feedback/tr124-restructuring
Made simplified responses in the result more simplified
2 parents 4f0027d + 4a94cf7 commit 1593985

File tree

3 files changed

+39
-21
lines changed

3 files changed

+39
-21
lines changed

app/evaluation.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -256,14 +256,6 @@ def evaluation_function(response, answer, params, include_test_data=False) -> di
256256
parameters.update({key: value})
257257
if "criteria" not in parameters.keys():
258258
parameters.update({"criteria": ",".join(context["default_criteria"])})
259-
try:
260-
preview = context["expression_preview"](response, deepcopy(parameters))["preview"]
261-
except Exception:
262-
evaluation_result.latex = response
263-
evaluation_result.simplified = response
264-
else:
265-
evaluation_result.latex = preview["latex"]
266-
evaluation_result.simplified = preview["sympy"]
267259

268260
reserved_expressions_keys = list(reserved_expressions_strings["learner"].keys())+list(reserved_expressions_strings["task"].keys())
269261
parameters.update(
@@ -301,6 +293,22 @@ def evaluation_function(response, answer, params, include_test_data=False) -> di
301293
return evaluation_result.serialise(include_test_data)
302294
reserved_expressions_parsed = {**reserved_expressions["learner"], **reserved_expressions["task"]}
303295

296+
try:
297+
preview = context["expression_preview"](response, deepcopy(parameters))["preview"]
298+
except Exception:
299+
evaluation_result.latex = response
300+
evaluation_result.simplified = response
301+
else:
302+
evaluation_result.latex = preview["latex"]
303+
parsed_response = reserved_expressions["learner"]["response"]
304+
if isinstance(parsed_response, list) or isinstance(parsed_response, set):
305+
evaluation_result.simplified = ", ".join([str(ex.simplify()) for ex in parsed_response])
306+
else:
307+
try:
308+
evaluation_result.simplified = str(parsed_response.simplify())
309+
except Exception:
310+
evaluation_result.simplified = response
311+
304312
criteria_parser = context["generate_criteria_parser"](reserved_expressions)
305313
criteria = create_criteria_dict(criteria_parser, parameters)
306314

app/evaluation_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class TestEvaluationFunction():
2929
from .tests.physical_quantity_evaluation_tests import TestEvaluationFunction as TestQuantities
3030

3131
# Import tests that corresponds to examples in documentation and examples module
32-
#from .tests.example_tests import TestEvaluationFunction as TestExamples
32+
from .tests.example_tests import TestEvaluationFunction as TestExamples
3333

3434
def test_eval_function_can_handle_latex_input(self):
3535
response = r"\sin x + x^{7}"

app/tests/symbolic_evaluation_tests.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -471,19 +471,29 @@ def test_plus_minus_all_answers_incorrect(self, response, answer):
471471
result = evaluation_function(response, answer, params)
472472
assert result["is_correct"] is False
473473

474-
def test_simplified_in_correct_response(self):
475-
response = "a*x + b"
476-
answer = "b + a*x"
477-
result = evaluation_function(response, answer, {})
478-
assert result["is_correct"] is True
479-
assert result["response_simplified"] == "a*x + b"
480-
481-
def test_simplified_in_wrong_response(self):
482-
response = "a*x + b"
483-
answer = "b + a*x + 8"
474+
@pytest.mark.parametrize(
475+
"response, answer, simplified",
476+
[
477+
(
478+
"b + a*x",
479+
"a*x + b",
480+
"a*x + b"
481+
),
482+
(
483+
"b + a*x + 8",
484+
"a*x + b",
485+
"a*x + b + 8"
486+
),
487+
(
488+
"b + a*x + y - y",
489+
"a*x + b",
490+
"a*x + b"
491+
),
492+
]
493+
)
494+
def test_simplified(self, response, answer, simplified):
484495
result = evaluation_function(response, answer, {})
485-
assert result["is_correct"] is False
486-
assert result["response_simplified"] == "a*x + b"
496+
assert result["response_simplified"] == simplified
487497

488498
@pytest.mark.parametrize(
489499
"response,answer",

0 commit comments

Comments
 (0)