-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample_tests.py
79 lines (66 loc) · 1.48 KB
/
sample_tests.py
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
import pytest
from src.index import calculate
@pytest.mark.parametrize("expr, expected", [
('1', 1),
('+ 1 1', 2),
('- 1 1', 0),
('* 1 1', 1),
('/ 1 1', 1)
])
def test_basic(expr, expected):
assert expected == calculate(expr)
@pytest.mark.parametrize("expr, expected", [
('/ 1 1', 1),
('/ 0 1', 0),
('/ 4 2', 2),
('/ 3 2', 1),
('/ 1 2', 0)
])
def test_integer_division(expr, expected):
assert expected == calculate(expr)
@pytest.mark.parametrize('env', [
{
'x': 1,
}
])
@pytest.mark.parametrize("expr, expected", [
('x', 1),
('+ x -1', 0),
])
def test_variable(expr, expected, env):
assert expected == calculate(expr, env)
@pytest.mark.parametrize('env', [
{
'x': 1,
}
])
@pytest.mark.parametrize("expr, expected", [
('= x 0 x', 0),
('= x 0 + x x', 0)
])
def test_reassignment(expr, expected, env):
assert expected == calculate(expr, env)
@pytest.mark.parametrize('env', [
{
'x': 1,
'y': 0,
'z': -1
}
])
@pytest.mark.parametrize("expr, expected", [
(' + x (= y 1000 (= y 10 + x y)) z y', 11),
])
def test_variable_shadowing(expr, expected, env):
assert expected == calculate(expr, env)
@pytest.mark.parametrize('env', [
{
'x': 1,
'y': 0,
'z': -1
}
])
@pytest.mark.parametrize("expr, expected", [
('+ x ( = x (+ x 1) x )', 3),
])
def test_self_assignment(expr, expected, env):
assert expected == calculate(expr, env)