Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/feedback/symbolic_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"MULTIPLE_ANSWER_FAIL_RESPONSE": "At least one response was incorrect.",
"MULTIPLE_ANSWER_FAIL_ANSWERS": "At least one answer is missing in the response.",
"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.",
"NOTATION_WARNING": "Note that `^` cannot be used to denote exponentiation, use `**` instead.",
"NOTATION_WARNING_EXPONENT": "Note that `^` cannot be used to denote exponentiation, use `**` instead.",
"NOTATION_WARNING_FACTORIAL": "Note that `!` cannot be used to denote factorial, use `factorial(...)` instead.",
"EXPRESSION_NOT_EQUALITY": "The response was an expression but was expected to be an equality.",
"EQUALITY_NOT_EXPRESSION": "The response was an equality but was expected to be an expression.",
"WITHIN_TOLERANCE": "", # "The difference between the response the answer is within specified error tolerance.",
Expand Down
4 changes: 3 additions & 1 deletion app/symbolic_comparison_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ def symbolic_comparison(response, answer, params, eval_response) -> dict:

if params.get("strict_syntax", True):
if "^" in response:
eval_response.add_feedback(("NOTATION_WARNING", symbolic_comparison_internal_messages["NOTATION_WARNING"]))
eval_response.add_feedback(("NOTATION_WARNING_EXPONENT", symbolic_comparison_internal_messages["NOTATION_WARNING_EXPONENT"]))
if "!" in response:
eval_response.add_feedback(("NOTATION_WARNING_FACTORIAL", symbolic_comparison_internal_messages["NOTATION_WARNING_FACTORIAL"]))

# Safely try to parse answer and response into symbolic expressions
try:
Expand Down
7 changes: 4 additions & 3 deletions app/symbolic_comparison_evaluation_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,12 +647,13 @@ def test_numerical_comparison(self, description, response, answer, tolerance, ou
assert result["is_correct"] is outcome

def test_warning_inappropriate_symbol(self):
answer = '2**4'
response = '2^4'
answer = 'factorial(2**4)'
response = '2^4!'
params = {'strict_syntax': True}
result = evaluation_function(response, answer, params, include_test_data=True)
assert result["is_correct"] is False
assert "NOTATION_WARNING" in result["tags"]
assert "NOTATION_WARNING_EXPONENT" in result["tags"]
assert "NOTATION_WARNING_FACTORIAL" in result["tags"]

@pytest.mark.parametrize(
"response,answer",
Expand Down