Skip to content

Commit

Permalink
Add test criteria for test_set_parser_vars function
Browse files Browse the repository at this point in the history
  • Loading branch information
ptmcg committed Dec 19, 2022
1 parent 833bc4c commit 57356fa
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions test/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,20 +236,29 @@ def test_customize_max_expression_depth(
assert basic_arithmetic_parser.evaluate(input_string) == expected_value

def test_set_parser_vars(self, basic_arithmetic_parser):
res = []
x2_res = []
y_res = []
observed_x = []
expected_x2 = []
expected_y = []
observed_y = []
for x in range(10):
basic_arithmetic_parser["x"] = x
res.append(basic_arithmetic_parser.evaluate("y = x²"))
x2_res.append(basic_arithmetic_parser.evaluate("x²"))
y_res.append(basic_arithmetic_parser.evaluate("y = x²"))
expected_x2.append(x * x)
expected_y.append(basic_arithmetic_parser["y"])
observed_x.append(basic_arithmetic_parser["x"])
observed_y.append(basic_arithmetic_parser["y"])

print(res)
print(x2_res)
print(y_res)
print(observed_x)
print(expected_x2)
print(expected_y)
print(observed_y)
print(basic_arithmetic_parser.vars())

assert res == expected_x2 == expected_y
assert list(range(10)) == observed_x
assert x2_res == expected_x2
assert observed_y == expected_x2

with pytest.raises(NameError):
z_value = basic_arithmetic_parser["z"]
Expand Down

0 comments on commit 57356fa

Please sign in to comment.