Skip to content

Basic version for testing in the web client #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions evaluation_function/dev_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from .evaluation import evaluation_function

response = r"\\begin{array}{l}\na+b \\text { and more text }\\\\\n\\begin{array}{l}\nq+x \\\\\nc+d\n\\end{array}\n\\end{array}"
answer = "\\begin{array}{l}\na+b \\text { and more text }\\\\\n\\begin{array}{l}\nq+x \\\\\nc+d\n\\end{array}"
params = {
"strict_syntax": False,
"elementary_functions": True,
"is_latex": True,
"text_prototype": True,
}
result = evaluation_function(response, answer, params)
print(result)
20 changes: 14 additions & 6 deletions evaluation_function/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@
from timeit import default_timer as timer

def evaluation_function(response, answer, params, include_test_data=False) -> dict:
"""
Function that allows for various types of comparison of various kinds of expressions.
Supported input parameters:
strict_SI_syntax:
- if set to True, use basic dimensional analysis functionality.
"""

if params.get("text_prototype", False) is True:
response_original = response
if params.get("is_latex", False) is True:
latex_array_start = r"\\begin{array}{l}\n"
latex_array_end = r"\n\\end{array}"
latex_array_newline = r"\\\\\n"
if response.startswith(latex_array_start):
response = response.replace(latex_array_start, "")
response = response.replace(latex_array_end, "")
response = response.replace(latex_array_newline, " ")
result = {"is_correct": True, "response_latex": response_original, "response_simplified": response}
print(result)
return result

if response.lower().startswith("benchmark"):
arg = response.split()
Expand Down
57 changes: 34 additions & 23 deletions evaluation_function/evaluation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,41 +22,52 @@ class TestEvaluationFunction():
"""

# Import tests that makes sure that mathematical expression comparison works as expected
from .symbolic_comparison_evaluation_tests import TestEvaluationFunction as TestSymbolicComparison
# from .symbolic_comparison_evaluation_tests import TestEvaluationFunction as TestSymbolicComparison

# Import tests that makes sure that physical quantities are handled as expected
from .quantity_comparison_evaluation_tests import TestEvaluationFunction as TestQuantities
# from .quantity_comparison_evaluation_tests import TestEvaluationFunction as TestQuantities

# Import tests that corresponds to examples in documentation and examples module
from .example_tests import TestEvaluationFunction as TestExamples
# from .example_tests import TestEvaluationFunction as TestExamples

def test_eval_function_can_handle_latex_input(self):
response = r"\sin x + x^{7}"
answer = "sin(x)+x**7"
#def test_eval_function_can_handle_latex_input(self):
# response = r"\sin x + x^{7}"
# answer = "sin(x)+x**7"
# params = {
# "strict_syntax": False,
# "elementary_functions": True,
# "is_latex": True
# }
# result = evaluation_function(response, answer, params)
# assert result["is_correct"] is True

def test_multiline_latex(self):
response = r"\\begin{array}{l}\na+b \\text { and more text }\\\\\n\\begin{array}{l}\nq+x \\\\\nc+d\n\\end{array}\n\\end{array}"
answer = "\\begin{array}{l}\na+b \\text { and more text }\\\\\n\\begin{array}{l}\nq+x \\\\\nc+d\n\\end{array}"
params = {
"strict_syntax": False,
"elementary_functions": True,
"is_latex": True
"is_latex": True,
"text_prototype": True,
}
result = evaluation_function(response, answer, params)
assert result["is_correct"] is True

def test_incorrect_response_with_custom_feedback(self):
response = "x+1"
answer = "x+2"

response = evaluation_function(response, answer, {"feedback_for_incorrect_response": "Custom feedback"})
print(result)
assert result.get("is_correct", False) is True

assert response["is_correct"] is False
assert response["feedback"] == "Custom feedback"
#def test_incorrect_response_with_custom_feedback(self):
# response = "x+1"
# answer = "x+2"
# response = evaluation_function(response, answer, {"feedback_for_incorrect_response": "Custom feedback"})
# assert response["is_correct"] is False
# assert response["feedback"] == "Custom feedback"

def test_benchmark(self):
response = "BENCHMARK 10"
result = evaluation_function(response, "placeholder", {})
assert result["is_correct"] is True
response = "BENCHMARK 10 FALSE"
result = evaluation_function(response, "placeholder", {})
assert result["is_correct"] is False
#def test_benchmark(self):
# response = "BENCHMARK 10"
# result = evaluation_function(response, "placeholder", {})
# assert result["is_correct"] is True
# response = "BENCHMARK 10 FALSE"
# result = evaluation_function(response, "placeholder", {})
# assert result["is_correct"] is False

if __name__ == "__main__":
pytest.main(['-xk not slow', '--tb=line', '--durations=10', os.path.abspath(__file__)])
Loading