-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_eval.py
38 lines (28 loc) · 1.05 KB
/
test_eval.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
import unittest
import eval
from larktypes import String
from roots import *
from symbol import *
class TestEval(unittest.TestCase):
def teststring(self):
self.assertEqual(eval.ac_eval(String('ab'), {}), String('ab'))
def testint(self):
self.assertEqual(eval.ac_eval(1, {}), 1)
def testfloat(self):
self.assertEqual(eval.ac_eval(0.5, {}), 0.5)
def testvarref(self):
self.assertEqual(eval.ac_eval(Symbol('a'), {Symbol('a'): 42}), 42)
def testquote(self):
self.assertEqual(eval.ac_eval([Symbol('quote'), [Symbol('a'), nil]], {}),
Symbol('a'))
def testif(self):
self.assertEqual(eval.ac_eval([Symbol('if'), nil], {}), nil)
self.assertEqual(eval.ac_eval(list(Symbol('if'), t, 1, 2), {}), 1)
def testfncall(self):
# (fn (a) (if a 1 2))
fun = list(Symbol('fn'), list(Symbol('a')),
list(Symbol('if'), Symbol('a'), 1, 2))
self.assertEqual(eval.ac_eval(list(fun, nil), {}), 2)
self.assertEqual(eval.ac_eval(list(fun, String('x')), {}), 1)
if __name__ == '__main__':
unittest.main()