From: Ramakrishnan Muthukrishnan Date: Mon, 2 Jan 2012 08:58:32 +0000 (+0530) Subject: bunch of simple tests. X-Git-Url: https://git.rkrishnan.org/running.html?a=commitdiff_plain;h=668247dae385316beb9dad1d89b567a1d448878e;p=sicp.git bunch of simple tests. --- diff --git a/src/sicp/metacircular2-test.rkt b/src/sicp/metacircular2-test.rkt index 7138ec2..563b0ec 100644 --- a/src/sicp/metacircular2-test.rkt +++ b/src/sicp/metacircular2-test.rkt @@ -1,4 +1,40 @@ #lang racket (require "metacircular2.rkt" - rackunit) \ No newline at end of file + rackunit) + +(require rackunit/text-ui) + +(define metacircular2-tests + (test-suite "test suite for meta circular evaluator" + (let ([env1 (make-environment)]) + (check-equal? (eval '(+ 1 1) env1) 2 "simple addition") + (check-equal? (eval '(- 2 1) env1) 1 "simple subtraction") + (check-equal? (eval '(quote x) env1) 'x "quote") + (eval '(define x 20) env1) + (check-equal? (eval 'x env1) 20 "definition of identifiers with simple values") + (eval '(set! x 42) env1) + (check-equal? (eval 'x env1) 42 "set!") + (eval '(define (square x) (* x x)) env1) + (check-equal? (eval '(square 10) env1) 100 "simple function definition") + (eval '(define (square x) (let ([s (* x x)]) s)) env1) + (check-equal? (eval '(square 20) env1) 400 "different way to define square") + (eval '(define (absolute x) + (cond ((> x 0) x) + ((= x 0) (display 'zero) 0) + (else (- x)))) + env1) + (check-equal? (eval '(absolute -2) env1) 2 "conditionals") + (check-equal? (eval '(absolute 2) env1) 2 "conditionals") + (eval '(define (foo) (let ((x 42) (y 100)) (list x y))) env1) + (check-equal? (eval '(foo) env1) '(42 100) "simple let") + (check-equal? (eval '(let* ((x 3) + (y (+ x 2)) + (z (+ x y 5))) + (* x z)) + env1) + 39 + "let* test")))) + + +(run-tests metacircular2-tests) \ No newline at end of file