示例#1
0
    def test_nested_funct(self):
        string = '''
		(define (get2)
		(define (plus1 y)(+ 1 y))
		( plus1 1 ))
		(get2)'''
        self.assertEqual(next(Program(string).run()), 2)
示例#2
0
    def test_func_as_args(self):
        string = '''
			(define (f x) (+ x x))
			(define (g x) (* x x))
			(define (ff f  g x) (f (g x)))
			(ff f g 3)
		'''
        self.assertEqual(next(Program(string).run()), 18)
示例#3
0
    def test_if_funct(self):
        string = '''
		(define (comp x)
			(if (= x 1) 1)
			(if (= x 2) 2)
			(if (= x 3) 3)
		)
		(comp 3)
		'''
        self.assertEqual(next(Program(string).run()), 3)
示例#4
0
    def test_strange_brackets_indent(self):
        string = '''
		(define (square x)	(* x x))
		(square     (3))
		'''
        self.assertEqual(next(Program(string).run()), 9)
示例#5
0
    def test_recursion_funct(self):
        string = '''
		(define (fact x) (if (= x 1) 1 (* x (fact (- x 1)))))
		(fact 4)
		'''
        self.assertEqual(next(Program(string).run()), 24)
示例#6
0
 def test_plus(self):
     string = "(+ 3 4 16)"
     self.assertEqual(next(Program(string).run()), 23)
示例#7
0
    def test_nested_if_funct(self):
        string = '''
		(define (comp x)(if (= x 1) (5) (if (= x 2) 3 4)))
		(comp 2)
		'''
        self.assertEqual(next(Program(string).run()), 3)
示例#8
0
    def test_neg_compare_funct(self):
        string = '''
		(define (Pos x) (if (< 0 x) 1 -1))
		(Pos -1)
		'''
        self.assertEqual(next(Program(string).run()), -1)
示例#9
0
    def test_multi_arg_funct(self):
        string = '''
		(define (product_ x y)(* x y))
		(product_ 3 4)
		'''
        self.assertEqual(next(Program(string).run()), 12)
示例#10
0
    def test_functions(self):
        string = '''
		(define (square x)(* x x))
		(square 3)
		'''
        self.assertEqual(next(Program(string).run()), 9)
示例#11
0
    def test_constant(self):
        string = '''
		(define pi 3.14)
		(+ pi 4)
		'''
        self.assertEqual(next(Program(string).run()), 7.14)
示例#12
0
 def test_nested_if(self):
     string = "(if (< 5 (* 3 2)) 5 6)"
     self.assertEqual(next(Program(string).run()), 5)
示例#13
0
 def test_minus(self):
     string = "(- 6 4)"
     self.assertEqual(next(Program(string).run()), 2)
示例#14
0
from pyLisch import node
from pyLisch.program import Program

programStr = '''

(define (f x) (+ x x))
(define (g x) (* x x))
(define (ff f g x) (f (g x)))
(ff f g 3)
'''

program = Program(programStr)

for i in program.run():
    print(i)