Skip to content

Commit 146fde7

Browse files
Added feedback when using ! when strict_syntax is set to true
1 parent 064f8d1 commit 146fde7

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

app/evaluation.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ def check_equality(response, answer, params, eval_response) -> dict:
107107

108108
if params.get("strict_syntax", True):
109109
if "^" in response:
110-
eval_response.add_feedback(("NOTATION_WARNING", symbolic_equal_internal_messages["NOTATION_WARNING"]))
110+
eval_response.add_feedback(("NOTATION_WARNING_EXPONENT", symbolic_equal_internal_messages["NOTATION_WARNING_EXPONENT"]))
111+
if "!" in response:
112+
eval_response.add_feedback(("NOTATION_WARNING_FACTORIAL", symbolic_equal_internal_messages["NOTATION_WARNING_FACTORIAL"]))
111113

112114
# Safely try to parse answer and response into symbolic expressions
113115
try:

app/evaluation_tests.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -615,12 +615,13 @@ def test_numerical_comparison(self, description, response, answer, tolerance, ou
615615
assert result["is_correct"] is outcome
616616

617617
def test_warning_inappropriate_symbol(self):
618-
answer = '2**4'
619-
response = '2^4'
618+
answer = 'factorial(2**4)'
619+
response = '2^4!'
620620
params = {'strict_syntax': True}
621621
result = evaluation_function(response, answer, params, include_test_data=True)
622622
assert result["is_correct"] is False
623-
assert "NOTATION_WARNING" in result["tags"]
623+
assert "NOTATION_WARNING_EXPONENT" in result["tags"]
624+
assert "NOTATION_WARNING_FACTORIAL" in result["tags"]
624625

625626
@pytest.mark.parametrize(
626627
"response,answer",

app/feedback/symbolic_equal.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"MULTIPLE_ANSWER_FAIL_RESPONSE": "At least one response was incorrect.",
77
"MULTIPLE_ANSWER_FAIL_ANSWERS": "At least one answer is missing in the response.",
88
"PARSE_ERROR": lambda x: f"`{x}` could not be parsed as a valid mathematical expression. Ensure that correct codes for input symbols are used, correct notation is used, that the expression is unambiguous and that all parentheses are closed.",
9-
"NOTATION_WARNING": "Note that `^` cannot be used to denote exponentiation, use `**` instead.",
9+
"NOTATION_WARNING_EXPONENT": "Note that `^` cannot be used to denote exponentiation, use `**` instead.",
10+
"NOTATION_WARNING_FACTORIAL": "Note that `!` cannot be used to denote factorial, use `factorial(...)` instead.",
1011
"EXPRESSION_NOT_EQUALITY": "The response was an expression but was expected to be an equality.",
1112
"EQUALITY_NOT_EXPRESSION": "The response was an equality but was expected to be an expression.",
1213
"WITHIN_TOLERANCE": "", # "The difference between the response the answer is within specified error tolerance.",

0 commit comments

Comments
 (0)