-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_proc.py
71 lines (64 loc) · 1.96 KB
/
test_proc.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
import unittest
import visp
import test_visp
class TestProc(test_visp.TestCase):
def setUp(self):
self.base_env = visp.Env({
'a': visp.Exact(2)
})
def test_lambda(self):
self.assertEvalEqual(
"""((lambda (x y)
(+ x y))
(+ 1 2)
3)""",
"6")
def test_closure(self):
self.assertEvalEqual(
"""((lambda (x)
((lambda (y)
(+ x y))
(+ 1 2)))
1)""",
"4")
def test_returning_closure(self):
self.assertEvalEqual(
"""(((lambda (y)
(lambda ()
y))
6))""",
"6")
self.assertEvalEqual(
"""((lambda (x)
(+ (((lambda (y)
(lambda ()
y))
6))
x))
4)""",
"10")
def test_multiple_stmts_in_body(self):
self.assertEvalEqual(
"""((lambda ()
1
2))""",
"2")
def test_let_over_lambda_over_let_over_lambda(self):
self.assertEvalEqual(
"""(let (((new rev)
(let ((reversed #f))
(list
(lambda (start)
(let ((x start))
(lambda ()
(if reversed
(set! x (- x 1))
(set! x (+ x 1)))
x)))
(lambda ()
(if reversed
(set! reversed #f)
(set! reversed #t)))))))
(let ((c (new 0)))
(list (c) (c) (rev) (c) (c))))""",
"""'(1 2 #t 1 0)""")