diff --git a/app/docs/user.md b/app/docs/user.md index 032baea..83c929b 100644 --- a/app/docs/user.md +++ b/app/docs/user.md @@ -240,7 +240,7 @@ If `strict_syntax` is set to true then the answer and response must have `*` or If `strict_syntax` is set to false, then `*` can be omitted and `^` used instead of `**`. In this case it is also recommended to list any multicharacter symbols expected to appear in the response as input symbols. -By default `strict_syntax` is set to true. +By default `strict_syntax` is set to false. #### `symbol_assumptions` diff --git a/app/evaluation.py b/app/evaluation.py index 891f9af..b391fcb 100644 --- a/app/evaluation.py +++ b/app/evaluation.py @@ -288,7 +288,7 @@ def evaluation_function(response, answer, params, include_test_data=False) -> di ) # FIXME: Move this into expression_utilities - if params.get("strict_syntax", True): + if params.get("strict_syntax", False): if "^" in response: evaluation_result.add_feedback(("NOTATION_WARNING_EXPONENT", symbolic_comparison_internal_messages("NOTATION_WARNING_EXPONENT")(dict()))) if "!" in response: diff --git a/app/evaluation_test.py b/app/evaluation_test.py index bd05396..bdae7b2 100755 --- a/app/evaluation_test.py +++ b/app/evaluation_test.py @@ -192,6 +192,26 @@ def test_e_latex(self, response, is_latex, is_correct): + @pytest.mark.parametrize("params, is_correct", [ + ({}, True), + ({"atol": 0.0, "rtol": 0.0, "strict_syntax": False, "physical_quantity": False, "elementary_functions": False}, True), + ({"atol": 0.0, "rtol": 0.0, "strict_syntax": False, "physical_quantity": False, "elementary_functions": True}, True), + ({"atol": 0.0, "rtol": 0.0, "strict_syntax": True, "physical_quantity": False, "elementary_functions": False}, False), + ({"atol": 0.0, "rtol": 0.0, "strict_syntax": True, "physical_quantity": False, "elementary_functions": True}, False), + ]) + def test_strict_syntax_rejects_implicit_multiplication(self, params, is_correct): + response = "-2M0/3" + answer = "-2M0/3" + if is_correct: + result = evaluation_function(response, answer, params) + assert result["is_correct"] is True + else: + # strict_syntax=True prevents implicit multiplication, so -2M0/3 cannot be + # parsed. Answer parse failures are raised as exceptions (not returned as + # is_correct=False) because they indicate a task misconfiguration. + with pytest.raises(Exception): + evaluation_function(response, answer, params) + def test_mu_preview_evaluate(self): response = "10 μA" params = Params(is_latex=False, elementary_functions=False, strict_syntax=False, physical_quantity=True) diff --git a/app/tests/symbolic_evaluation_test.py b/app/tests/symbolic_evaluation_test.py index 10c4bc1..ce7f943 100644 --- a/app/tests/symbolic_evaluation_test.py +++ b/app/tests/symbolic_evaluation_test.py @@ -227,7 +227,7 @@ def test_invalid_author_expression(self): answer = "3x" e = None with pytest.raises(Exception) as e: - evaluation_function(response, answer, {}) + evaluation_function(response, answer, {"strict_syntax": True}) assert e is not None @pytest.mark.parametrize( diff --git a/app/utility/expression_utilities.py b/app/utility/expression_utilities.py index 008e9b5..876edb5 100644 --- a/app/utility/expression_utilities.py +++ b/app/utility/expression_utilities.py @@ -9,7 +9,7 @@ "complexNumbers": False, "convention": "equal_precedence", "elementary_functions": False, - "strict_syntax": True, + "strict_syntax": False, "multiple_answers_criteria": "all", } @@ -685,7 +685,7 @@ def create_sympy_parsing_params(params, unsplittable_symbols=tuple(), symbol_ass symbol_dict.update(sympy_symbols(unsplittable_symbols)) - strict_syntax = params.get("strict_syntax", True) + strict_syntax = params.get("strict_syntax", False) parsing_params = { "unsplittable_symbols": unsplittable_symbols,