(define fail (lambda (f x y) (display "test failed: ") (display f) (newline) (display "expected: ") (display x) (newline) (display "got: ") (display y) (newline) ) ) (define test (lambda (f x) (define y (eval f)) (if (not (equal? x y)) (fail f x y) ) ) ) (test '(eq? #t #t) #t) (test '(eq? #f #f) #t) (test '(eq? #t #f) #f) (test '(eq? #f #t) #f) (test '(eq? () ()) #t) (test '(eq? 1 1) #f) (define x 1) (test '(eq? x x) #t) (define y x) (test '(eq? x y) #f) ; y is pointing at x but isn't the same thing (test '(infinite? -inf) #t) (test '(infinite? +inf) #t) (test '(infinite? 0) #f) (test '(finite? -inf) #f) (test '(finite? +inf) #f) (test '(finite? 0) #t) (test '(null? ()) #t) (test '(null? #f) #f) (test '(null? (list () ())) #f) (test '(and #t) #t) (test '(and #f) #f) (test '(and #t #t) #t) (test '(and #f #t) #f) (test '(and #t #f) #f) (test '(and 0 1 2 3) 3) (test '(and #t 1) 1) (test '(and () "lol") "lol") (test '(and "lol" ()) ()) (test '(or #f #f) #f) (test '(or #f #t) #t) (test '(or #t #f) #t) (test '(or 0 1 2 3) 0) (test '(or () "lol") ()) (test '(or "lol" ()) "lol") (test '(not 0) #f) (test '(not ()) #f) (test '(not "lol") #f) (test '(not #t) #f) (test '(not #f) #t) (test '(car (cons 1 2)) 1) (test '(cdr (cons 1 2)) 2) (test '(car (cons 3 (list 1 2))) 3) (test '(cdr (cons 3 (list 1 2))) (list 1 2)) (test '(max 1 2) 2) (test '(max 2 1) 2) (test '(max -1 -2) -1) (test '(max -2 -1) -1) (test '(min 1 2) 1) (test '(min 2 1) 1) (test '(min -1 -2) -2) (test '(min -2 -1) -2) ;;;; R7RS specifics (test '(eq? #t #true) #t) (test '(eq? #f #false) #t)