(module top (lib "eopl.ss" "eopl") ;; top level module. Loads all required pieces. ;; Run the test suite with (run-all). (require "drscheme-init.scm") (require "data-structures.scm") ; for expval constructors (require "lang.scm") ; for scan&parse (require "interp.scm") ; for value-of-program (require "tests.scm") ; for test-list ;; since this is the top-level module, we don't really need to ;; provide anything, but we do so just in case. (provide run run-all) ;; here are some other things that could be provided: ;; (provide (all-defined)) ;; (provide (all-from "interp.scm")) ;; (provide (all-from "lang.scm")) ;;;;;;;;;;;;;;;; interface to test harness ;;;;;;;;;;;;;;;; ;; run : String -> ExpVal ;; Page: 71 (define run (lambda (string) (value-of-program (scan&parse string)))) ;; run-all : () -> unspecified ;; runs all the tests in test-list, comparing the results with ;; equal-answer? (define run-all (lambda () (run-tests! run equal-answer? test-list))) (define equal-answer? (lambda (ans correct-ans) (equal? ans (sloppy->expval correct-ans)))) (define sloppy->expval (lambda (sloppy-val) (cond ((number? sloppy-val) (num-val sloppy-val)) ((boolean? sloppy-val) (bool-val sloppy-val)) ((null? sloppy-val) (emptylist-val)) ;; Added for HW 5 ((pair? sloppy-val) ;; Added for HW 5 (pair-val (sloppy->expval (car sloppy-val)) ;; Added for HW 5 (sloppy->expval (cdr sloppy-val)))) ;; Added for HW 5 (else (eopl:error 'sloppy->expval "Can't convert sloppy value to expval: ~s" sloppy-val))))) ;; run-one : symbol -> expval ;; (run-one sym) runs the test whose name is sym (define run-one (lambda (test-name) (let ((the-test (assoc test-name test-list))) (cond ((assoc test-name test-list) => (lambda (test) (run (cadr test)))) (else (eopl:error 'run-one "no such test: ~s" test-name)))))) ;; (run-all) )