-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevaluation_tests.py
More file actions
executable file
·136 lines (115 loc) · 4.55 KB
/
evaluation_tests.py
File metadata and controls
executable file
·136 lines (115 loc) · 4.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import pytest
import os
from .preview import preview_function
from .utility.preview_utilities import Params
from .evaluation import evaluation_function
class TestEvaluationFunction():
"""
TestCase Class used to test the algorithm.
---
Tests are used here to check that the algorithm written
is working as it should.
These tests are organised in classes to ensure that the same
calling conventions can be used for tests using unittest and
tests using pytest.
Read the docs on how to use unittest and pytest here:
https://docs.python.org/3/library/unittest.html
https://docs.pytest.org/en/7.2.x/
Use evaluation_function() to call the evaluation function.
"""
# Import tests that makes sure that mathematical expression comparison works as expected
from .tests.symbolic_evaluation_tests import TestEvaluationFunction as TestSymbolicComparison
# Import tests that makes sure that physical quantities are handled as expected
from .tests.physical_quantity_evaluation_tests import TestEvaluationFunction as TestQuantities
# Import tests that corresponds to examples in documentation and examples module
from .tests.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"
params = {
"strict_syntax": False,
"elementary_functions": True,
"is_latex": True
}
result = evaluation_function(response, answer, params)
assert result["is_correct"] is True
def test_eval_function_preserves_order_in_latex_input(self):
response = r"c + a + b"
answer = "c + a + b"
params = {
"strict_syntax": False,
"elementary_functions": True,
"is_latex": True
}
result = evaluation_function(response, answer, params)
assert result["is_correct"] is True
def test_AERO40007_1_6_instance_2024_25(self):
params = {
"strict_syntax": False,
"elementary_functions": True,
"rtol": 0.01,
}
response = "231*16.4/1000*14=4"
answer = "53"
result = evaluation_function(response, answer, params)
assert result["is_correct"] is False
assert "response = answer_EQUALITY_NOT_EXPRESSION" in result["tags"]
def test_CHEM40002_1_5_instance_2024_25(self):
params = {
"strict_syntax": False,
"elementary_functions": True,
"complexNumbers": True,
"symbols": {
"I": {"aliases": ["i"], "latex": r"I"},
},
}
response = "6 exp(5pi/6*I)"
answer = "6(cos(5pi/6)+isin(5pi/6))"
result = evaluation_function(response, answer, params)
assert result["is_correct"] is True
def test_physical_qualities_no_tolerance(self):
params = {
"atol": 0.0,
"rtol": 0.0,
"strict_syntax": False,
"physical_quantity": True,
"elementary_functions": True,
}
response = "0.6 Nm"
answer = "0.5 Nm"
result = evaluation_function(response, answer, params)
assert result["is_correct"] is False
def test_physical_qualities_correct_feedback(self):
params = {
"atol": 0.0,
"rtol": 0.0,
"strict_syntax": False,
"physical_quantity": True,
"elementary_functions": True,
}
response = "0.6 Nm"
answer = "0.6 Nm"
result = evaluation_function(response, answer, params)
assert result["is_correct"] is True
assert result["feedback"] == "Response matches answer."
def test_euler_preview_evaluate(self):
response = "ER_2"
params = Params(is_latex=True, elementary_functions=False, strict_syntax=False)
result = preview_function(response, params)
assert "preview" in result.keys()
preview = result["preview"]
assert preview["latex"] == "ER_2"
assert preview["sympy"] == "E*R_2"
params = {
"atol": 0.0,
"rtol": 0.0,
"strict_syntax": False,
"physical_quantity": False,
"elementary_functions": False,
}
response = preview["sympy"]
answer = "E*R_2"
result = evaluation_function(response, answer, params)
assert result["is_correct"] is True
if __name__ == "__main__":
pytest.main(['-xk not slow', '--tb=short', '--durations=10', os.path.abspath(__file__)])