Skip to content

Commit 4825aeb

Browse files
authored
Fix/strict syntax default (#256)
* Made strict_syntax false by default * Added test for strict_syntax rejecting implicit multiplication and updated default to False * Fixed broken test
1 parent ff7ca73 commit 4825aeb

5 files changed

Lines changed: 25 additions & 5 deletions

File tree

app/docs/user.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ If `strict_syntax` is set to true then the answer and response must have `*` or
240240

241241
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.
242242

243-
By default `strict_syntax` is set to true.
243+
By default `strict_syntax` is set to false.
244244

245245
#### `symbol_assumptions`
246246

app/evaluation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def evaluation_function(response, answer, params, include_test_data=False) -> di
288288
)
289289

290290
# FIXME: Move this into expression_utilities
291-
if params.get("strict_syntax", True):
291+
if params.get("strict_syntax", False):
292292
if "^" in response:
293293
evaluation_result.add_feedback(("NOTATION_WARNING_EXPONENT", symbolic_comparison_internal_messages("NOTATION_WARNING_EXPONENT")(dict())))
294294
if "!" in response:

app/evaluation_test.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,26 @@ def test_e_latex(self, response, is_latex, is_correct):
192192

193193

194194

195+
@pytest.mark.parametrize("params, is_correct", [
196+
({}, True),
197+
({"atol": 0.0, "rtol": 0.0, "strict_syntax": False, "physical_quantity": False, "elementary_functions": False}, True),
198+
({"atol": 0.0, "rtol": 0.0, "strict_syntax": False, "physical_quantity": False, "elementary_functions": True}, True),
199+
({"atol": 0.0, "rtol": 0.0, "strict_syntax": True, "physical_quantity": False, "elementary_functions": False}, False),
200+
({"atol": 0.0, "rtol": 0.0, "strict_syntax": True, "physical_quantity": False, "elementary_functions": True}, False),
201+
])
202+
def test_strict_syntax_rejects_implicit_multiplication(self, params, is_correct):
203+
response = "-2M0/3"
204+
answer = "-2M0/3"
205+
if is_correct:
206+
result = evaluation_function(response, answer, params)
207+
assert result["is_correct"] is True
208+
else:
209+
# strict_syntax=True prevents implicit multiplication, so -2M0/3 cannot be
210+
# parsed. Answer parse failures are raised as exceptions (not returned as
211+
# is_correct=False) because they indicate a task misconfiguration.
212+
with pytest.raises(Exception):
213+
evaluation_function(response, answer, params)
214+
195215
def test_mu_preview_evaluate(self):
196216
response = "10 μA"
197217
params = Params(is_latex=False, elementary_functions=False, strict_syntax=False, physical_quantity=True)

app/tests/symbolic_evaluation_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def test_invalid_author_expression(self):
227227
answer = "3x"
228228
e = None
229229
with pytest.raises(Exception) as e:
230-
evaluation_function(response, answer, {})
230+
evaluation_function(response, answer, {"strict_syntax": True})
231231
assert e is not None
232232

233233
@pytest.mark.parametrize(

app/utility/expression_utilities.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"complexNumbers": False,
1010
"convention": "equal_precedence",
1111
"elementary_functions": False,
12-
"strict_syntax": True,
12+
"strict_syntax": False,
1313
"multiple_answers_criteria": "all",
1414
}
1515

@@ -685,7 +685,7 @@ def create_sympy_parsing_params(params, unsplittable_symbols=tuple(), symbol_ass
685685

686686
symbol_dict.update(sympy_symbols(unsplittable_symbols))
687687

688-
strict_syntax = params.get("strict_syntax", True)
688+
strict_syntax = params.get("strict_syntax", False)
689689

690690
parsing_params = {
691691
"unsplittable_symbols": unsplittable_symbols,

0 commit comments

Comments
 (0)