-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-init.rkt
30 lines (27 loc) · 954 Bytes
/
test-init.rkt
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
;; This file is deprecated
#lang racket
(print-struct #t)
(provide run-test)
(define (apply-safely proc args)
(with-handlers ([(lambda (exn) #t)
(lambda (exn)
(cons #f (or (and (exn? exn) (exn-message exn)) exn)))])
(let ([actual (apply proc args)])
(cons #t actual))))
(define-syntax (run-test stx)
(syntax-case stx ()
[(_ name expr expected-ans)
(syntax-case #'expr ()
[(op args ...)
#'(let* ((result (apply-safely op (list args ...)))
(thrown? (car result))
(ans (cdr result)))
(printf "test: ~a~%" name)
(printf "evaluating ~a~%" (quote expr))
(printf "expected answer: ~a~%" expected-ans)
(printf "actual answer: ~a~%" ans)
(printf "~a => ~a ~%" (quote expr) ans)
(printf "expection raised? : ~a~%" (not thrown?))
(printf "pass? : ~a~%" (eqv? ans expected-ans))
(printf "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%")
)])]))