Skip to content

Instantly share code, notes, and snippets.

@axiixc
Created March 7, 2012 05:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save axiixc/1991308 to your computer and use it in GitHub Desktop.
Save axiixc/1991308 to your computer and use it in GitHub Desktop.
Attempting to learn Scheme, and what better way than by writing code to test my other code :P
(define test-base
(lambda (passed? result message)
(if passed?
(begin
(display " passed: ")
(display message)
)
(begin
(display " failed: ")
(display message)
(display "\n got: ")
(display result)
)
)
(newline)
passed?
)
)
(define-syntax test-define-unary
(syntax-rules ()
((_ name operation)
(define name (lambda (o m) (test-base (operation o) o m))))))
(define-syntax test-define-comparison
(syntax-rules ()
((_ name comparison)
(define name (lambda (o e m) (test-base (comparison o e) o m))))))
(test-define-unary test-true? (lambda (v) (not (eqv? #f v))))
(test-define-unary test-false? (lambda (v) (eqv? #f v)))
(test-define-unary test-null? null?)
;;; (test-true? #t "(true? #t) => #t")
;;; => passed: (true? #t) => #t
(test-define-comparison test-eqv? eqv?)
(test-define-comparison test=? =)
(test-define-comparison test-char=? char=?)
(test-define-comparison test-string=? string=?)
;;; (test-eqv? (+ 1 9) 10 "(1+9) eqv? 10 => #t")
;;; => passed: (1+9) eqv? 10 => #t
;;; (test-eqv? (make10) 10 "(make10) eqv? 10 => #t")
;;; => failed: (make10) eqv? 10 => #t
;;; got: 2042
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment