Created
November 7, 2012 11:41
-
-
Save k-ohtani-is-deleting/4031012 to your computer and use it in GitHub Desktop.
my_gauche_unit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (assert-true actual message) | |
(if actual #t (raise message))) | |
(assert-true #t "would returns #t") | |
(assert-true #f "would throws error") | |
(define (assert-equals expected actual determiner) | |
(assert-true (determiner expected actual) | |
(string-append "expected " (x->string expected) ", but got " (x->string actual)))) | |
(assert-equals 1 1 =) ; => #t | |
(assert-equals 1 2 =) ; throws error | |
(define (list-equals? expected actual) | |
(cond ((and (null? expected) (null? actual)) #t) | |
((and (null? expected) (not (null? actual))) #f) | |
((and (not (null? expected)) (null? actual)) #f) | |
((= (car expected) (car actual)) | |
(list-equals? (cdr expected) (cdr actual))) | |
(else #f))) | |
(define (assert-list-equals expected actual) | |
(assert-equals expected actual list-equals?)) | |
(assert-list-equals (list 1 4 9 16 25) (map (lambda (x) (* x x)) (list 1 2 3 4 5))) ; => #t | |
(assert-list-equals (list 1 4 8 16 25) (map (lambda (x) (* x x)) (list 1 2 3 4 5))) ; throws error | |
(define (assert f expected actual) | |
(assert-true (f expected actual) | |
(string-append "expected " (x->string expected) ", but got " (x->string actual)))) ; TODO: メッセージがいけてないのはたぶん仕方ない | |
(assert = 1 2) | |
(assert = 1 1) | |
(assert > 1 2) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment