Repository navigation
Expand file tree
/
Copy pathtest_expression.py
More file actions
65 lines (61 loc) · 1.71 KB
/
Copy pathtest_expression.py
File metadata and controls
65 lines (61 loc) · 1.71 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
import pytest
from app.expression import (
evaluate_expression,
BinaryOperation,
UnitaryOpNode,
UnaryOperation,
BinaryOpNode,
BaseNode,
)
@pytest.mark.parametrize(
"expression,expected_result",
[
(BaseNode(lhs=1), 1),
(
BinaryOpNode(
op=BinaryOperation.ADD, lhs=BaseNode(lhs=1), rhs=BaseNode(lhs=1)
),
2,
),
(
BinaryOpNode(
op=BinaryOperation.ADD,
lhs=BinaryOpNode(
op=BinaryOperation.MULTIPLY,
lhs=BaseNode(lhs=2),
rhs=BaseNode(lhs=2),
),
rhs=BaseNode(lhs=2),
),
6,
),
(
BinaryOpNode(
op=BinaryOperation.POW, lhs=BaseNode(lhs=3), rhs=BaseNode(lhs=2)
),
9,
),
(UnitaryOpNode(op=UnaryOperation.MINUS, lhs=BaseNode(lhs=1)), -1),
],
)
def test_expressions(expression, expected_result):
assert evaluate_expression(expression) == expected_result
# @pytest.mark.parametrize(
# "expression,expected_result,expected_precision",
# [
# (UnitaryOpNode(op=UnaryOperation.SQRT, lhs=BaseNode(lhs=2)), 1.4142, 1e-3),
# (
# BinaryOpNode(
# op=BinaryOperation.SQRT,
# lhs=BaseNode(lhs=2),
# rhs=BaseNode(lhs=0.0000001),
# ),
# 1.41421356237,
# 1e-7,
# ),
# ],
# )
# def test_sqrt_expressions(expression, expected_result, expected_precision):
# assert evaluate_expression(expression) == pytest.approx(
# expected_result, expected_precision
# )