-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_integration.py
More file actions
78 lines (68 loc) · 2.04 KB
/
Copy pathtest_integration.py
File metadata and controls
78 lines (68 loc) · 2.04 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
import pytest
from typing_extensions import Any
import lisp
from lisp import Lisper, Reader
STRUCTURES = {
'addition': ("(+ 1 2)", 3),
'subtraction': ("(- 10 11)", -1),
'multiplication': ("(* 3 4)", 12),
'division': ("(/ 10 2)", 5)
}
def assert_eval_eq(test, expected):
l = Lisper()
r = Reader(l)
actual : Any = l.eval(r.get_sexpr(test))
# should not be bear int, should be a lisp.Number
assert actual.v == expected
def test_lisp_():
l = Lisper()
assert l
def test_reader_():
l = Lisper()
r = Reader(l)
assert r
def test_addition():
t_c = STRUCTURES['addition']
expected = t_c[1]
l = Lisper()
r = Reader(l)
result = l.eval(r.get_sexpr(t_c[0]))
# should not be bear int, should be a lisp.Number
assert type(result) != type(expected)
assert isinstance(result, lisp.NumberObject)
assert result.v == expected
def test_subtraction():
t_c = STRUCTURES['subtraction']
expected = t_c[1]
l = Lisper()
r = Reader(l)
result = l.eval(r.get_sexpr(t_c[0]))
# should not be bear int, should be a lisp.Number
assert type(result) != type(expected)
assert isinstance(result, lisp.NumberObject)
assert result.v == expected
def test_multiplication():
t_c = STRUCTURES['multiplication']
expected = t_c[1]
l = Lisper()
r = Reader(l)
result = l.eval(r.get_sexpr(t_c[0]))
# should not be bear int, should be a lisp.Number
assert type(result) != type(expected)
assert isinstance(result, lisp.NumberObject)
assert result.v == expected
def test_division():
t_c = STRUCTURES['division']
expected = t_c[1]
l = Lisper()
r = Reader(l)
result = l.eval(r.get_sexpr(t_c[0]))
# should not be bear int, should be a lisp.Number
assert type(result) != type(expected)
assert isinstance(result, lisp.NumberObject)
assert result.v == expected
def test_exponentiation():
assert_eval_eq("(+ (+ 1 2) 3)", 6)
# that fails, it is inverted
assert_eval_eq("(- 2 (+ 3 4))", -5)
assert_eval_eq("(- 4 2)", 2)