-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_let.py
51 lines (45 loc) · 1.51 KB
/
test_let.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
import unittest
import test_visp
class TestLet(test_visp.TestCase):
def test_single_let(self):
self.assertEvalEqual(
"""(let ((x 1) (y 2))
(+ x y))""",
"3")
def test_nested_let(self):
self.assertEvalEqual(
"""(let ((x 2))
(let ((y 3))
(+ x y)))""",
"5")
def test_shadow_let(self):
self.assertEvalEqual(
"""(let ((x 2))
(let ((x 3))
(+ x x)))""",
"6")
def test_let_lambda(self):
self.assertEvalEqual(
"""(let ((f (lambda (x)
(let ((succ (lambda (x) (+ x 1)))
(pred (lambda (x) (- x 1))))
(list (pred x) x (succ x))))))
(f 2))""",
"'(1 2 3)")
def test_let_over_lambda(self):
self.assertEvalEqual(
"""(let ((make-counter (lambda (y)
(let ((x y))
(lambda ()
x)))))
(let ((c1 (make-counter 1))
(c2 (make-counter 2)))
(list (c1) (c1) (c2) (c2))))""",
"""'(1 1 2 2)""")
def test_let_multiple_stmts_in_body(self):
self.assertEvalEqual(
"""(let ((x 1) (y 2))
(set! x 2)
(set! y 3)
(list x y))""",
"""(quote (2 3))""")