3 (require "metacircular2-lazy.rkt"
6 (require rackunit/text-ui)
8 (define metacircular2-tests
9 (test-suite "test suite for meta circular evaluator"
10 (let ([env1 (make-environment)])
12 (check-equal? (eval '(+ 1 1) env1) 2 "simple addition")
13 (check-equal? (eval '(- 2 1) env1) 1 "simple subtraction")
14 (check-equal? (eval '(quote x) env1) 'x "quote")
15 (eval '(define x 20) env1)
16 (check-equal? (eval 'x env1) 20 "definition of identifiers with simple values")
17 (eval '(set! x 42) env1)
18 (check-equal? (eval 'x env1) 42 "set!")
19 (eval '(define (square x) (* x x)) env1)
20 (check-equal? (eval '(square 10) env1) 100 "simple function definition")
21 (eval '(define (square x) (let ([s (* x x)]) s)) env1)
22 (check-equal? (eval '(square 20) env1) 400 "different way to define square")
23 (eval '(define (absolute x)
25 ((= x 0) (display 'zero) 0)
28 (check-equal? (eval '(absolute -2) env1) 2 "conditionals")
29 (check-equal? (eval '(absolute 2) env1) 2 "conditionals")
30 (eval '(define (foo) (let ((x 42) (y 100)) (list x y))) env1)
31 (check-equal? (eval '(foo) env1) '(42 100) "simple let")
32 (check-equal? (eval '(let* ((x 3)
50 (check-equal? (eval '(f 2) env1) false "internal definitions")
51 (check-equal? (eval '(f 3) env1) true "internal definitions")
65 (check-equal? (eval '(f1 2) env1) true "internal definitions")
66 (check-equal? (eval '(f1 3) env1) false "internal definitions")
67 (eval '(define (fib n)
73 (fib-iter (+ a b) a (- count 1)))))
75 (check-equal? (eval '(fib 10) env1) 55 "named let")
76 (eval '(define (factorial n)
79 (* (factorial (- n 1)) n)))
81 (check-equal? (eval '(factorial 10) env1) 3628800 "factorial test")
82 (check-equal? (eval '(unless true "true" "false") env1) "false" "unless test 1")
83 (check-equal? (eval '(unless false "true" "false") env1) "true" "unless test 2"))))
85 (eval '(define (try a b) (if (= a 0) 1 b)) env1)
86 (check-equal? (eval '(try 0 (/ 1 0)) env1) 1 "lazy test1"))))
88 (run-tests metacircular2-tests)