-
Notifications
You must be signed in to change notification settings - Fork 8
/
tester.scm
46 lines (40 loc) · 1.14 KB
/
tester.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
;last change 2005-04-24
(require (lib "defmacro.ss"))
(define *failed* 0)
(define-macro test
(lambda ee
`(begin
,@(let loop ((ee ee) (r '()))
(if (null? ee) (reverse r)
(loop (cddr ee)
(cons `(test-each ,(car ee) ,(cadr ee))
r)))))))
(define-macro test-each
(lambda (expr expected-answer)
`(begin
(display "Trying ")
(write ',expr)
(newline)
(display " --> ")
(let ((__actual-answer ,expr))
(write __actual-answer)
(display " ... ")
(if (equal? __actual-answer ',expected-answer)
(display "OK")
(begin
(set! *failed* (+ *failed* 1))
(display "FAILED!!!")
(newline)
(display " ;;; expected ")
(write ',expected-answer))))
(newline))))
(define bottomline
(lambda ()
(newline)
(if (= *failed* 0)
(display "All tests succeeded! :-) :-) :-)")
(begin (display *failed*)
(display " test")
(if (> *failed* 1) (display "s"))
(display " failed! :-( :-( :-(")))
(newline)))