From cf3be4c0e20d88dbb6ae1482495d8408c931b136 Mon Sep 17 00:00:00 2001 From: Danny Yoo Date: Mon, 21 Feb 2011 15:50:48 -0500 Subject: [PATCH] added test case module --- test-find-toplevel-variables.rkt | 46 ++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 test-find-toplevel-variables.rkt diff --git a/test-find-toplevel-variables.rkt b/test-find-toplevel-variables.rkt new file mode 100644 index 0000000..b4c72de --- /dev/null +++ b/test-find-toplevel-variables.rkt @@ -0,0 +1,46 @@ +#lang racket +(require "find-toplevel-variables.rkt" + "parse.rkt") + +;; test-find-toplevel-variables +(define-syntax (test stx) + (syntax-case stx () + [(_ s exp) + (with-syntax ([stx stx]) + (syntax/loc #'stx + (let ([results (find-toplevel-variables (parse s))]) + (unless (equal? results exp) + (raise-syntax-error #f (format "Expected ~s, got ~s" exp results) + #'stx)))))])) + + +(test '(define (factorial n) + (if (= n 0) + 1 + (* (factorial (- n 1)) + n))) + + '(* - = factorial)) + +(test '(begin + (define (factorial n) + (fact-iter n 1)) + (define (fact-iter n acc) + (if (= n 0) + acc + (fact-iter (- n 1) (* acc n))))) + '(* - = fact-iter factorial)) + +(test '(define (gauss n) + (if (= n 0) + 0 + (+ (gauss (- n 1)) + n))) + '(+ - = gauss)) + +(test '(define (fib n) + (if (< n 2) + 1 + (+ (fib (- n 1)) + (fib (- n 2))))) + '(+ - < fib)) \ No newline at end of file