(define failed? #f)

(define (end-of-tests)
  (if failed?
      (display "TESTS FAILED\n")
      (display "All tests passed\n")))

(define (quick-test func-name checker . tests)
  (if (not (symbol? func-name))
      (error "Need to give a variable name as first argument to test")
      (let ((func (eval func-name)))
	(for-each (lambda (test)
		    (let ((out (apply func (cdr test))))
		      (if (not (checker out (car test)))
			  (error "Failed on input " (cdr test) " - expected " (car test) " but got " out))))
		  tests))))

(define (general-test msg expr . expected)
  (let ((actual (eval expr)))
    (if (not (member actual expected))
	(begin (set! failed? #t)
	       (display "\nTest failed: ")
	       (display expr)
	       (cond ((null? (cdr expected))
		      (display "\nExpected value: ")
		      (display (car expected)))
		     (else
		      (display "\nExpected one out of the following values:\n")
		      (for-each print expected)))
	       (display "\nActual value: ")
	       (display actual)
	       (newline)
	       (display msg)
	       (newline)
	       (newline)))))
