Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make all assertions curried

To make it easier to compose them.
  • Loading branch information...
commit a4a41157df59e89aa87b4379de2bbcaa3aaae07d 1 parent feeb9fa
@ferrous26 authored
Showing with 55 additions and 32 deletions.
  1. +55 −32 minitest.scm
View
87 minitest.scm
@@ -21,48 +21,48 @@
;; ASSERTIONS
(define assert
- (lambda (expr name msg)
- (begin
- (set! test-count (+ 1 test-count))
- (if (expr)
- (display (pass-token))
- (begin
- (display fail-token)
- (set! fails (append fails (list (cons test-count (cons name msg))))))))))
+ (lambda (name) (lambda (msg) (lambda (expr)
+ (begin
+ (set! test-count (+ 1 test-count))
+ (if (expr)
+ (display (pass-token))
+ (begin
+ (display fail-token)
+ (set! fails (append fails (list (cons test-count (cons name msg))))))))))))
-(define refute (lambda (expr name msg) (assert (not (expr)) name msg)))
+(define refute (lambda (name) (lambda (msg) (lambda (expr)
+ (((assert name) msg) (lambda () (not (expr))))))))
(define assert-equal
- (lambda (expected actual name)
- (assert (lambda () (equal? expected actual))
- name
- (list "Expected" actual "to be equal to" expected))))
+ (lambda (name) (lambda (expected) (lambda (actual)
+ (((assert name)
+ (list "Expected" actual "to be equal to" expected))
+ (lambda () (equal? expected actual)))))))
(define refute-equal
- (lambda (expected actual name)
- (assert (lambda () (not (equal? expected actual)))
- name
- (list "Expected" actual "to NOT be equal to" expected))))
-
+ (lambda (name) (lambda (expected) (lambda (actual)
+ (((assert name)
+ (list "Expected" actual "to NOT be equal to" expected))
+ (lambda () (not (equal? expected actual))))))))
(define assert-empty
- (lambda (collection name)
- (lambda ()
- (cond
- ((string? collection) (= 0 (string-length collection)))
- (else (null? collection))))
- name
- (list "Expected" collection "to be empty")))
+ (lambda (name) (lambda (collection)
+ (((assert name)
+ (list "Expected" collection "to be empty"))
+ (lambda ()
+ (cond
+ ((string? collection) (= 0 (string-length collection)))
+ (else (null? collection))))))))
(define refute-empty
- (lambda (collection name)
- (lambda ()
- (not (cond
- ((string? collection) (= 0 (string-length collection)))
- (else (null? collection)))))
- name
- (list "Expected" collection "to NOT be empty")))
+ (lambda (name) (lambda (collection)
+ (((assert name)
+ (list "Expected" collection "to NOT be empty"))
+ (lambda ()
+ (not (cond
+ ((string? collection) (= 0 (string-length collection)))
+ (else (null? collection)))))))))
;; Default display mechanism
@@ -95,3 +95,26 @@
fails)
(newline))))
+
+
+(((assert "failed assertion") "my first message") (lambda () (= 0 1)))
+(((assert "successful assertion") "my second message") (lambda () (= 0 0)))
+(((refute "successful refutation") "my third message") (lambda () (= 0 1)))
+(((refute "failed refutation") "my fourth message") (lambda () (= 0 0)))
+
+(((assert-equal "equal numbers") 42) 42)
+(((assert-equal "unequal symbols") 'cake) 'pie)
+(((refute-equal "equal symbols") 'cow) 'cow)
+(((refute-equal "unequal numbers") 7) 13)
+
+((assert-empty "empty list") '())
+((assert-empty "empty string") "")
+((assert-empty "non-empty list") '(a))
+((assert-empty "non-empty string") "a")
+
+((refute-empty "empty list") '())
+((refute-empty "empty string") "")
+((refute-empty "non-empty list") '(b))
+((refute-empty "non-empty string") "b")
+
+(display-test-results)
Please sign in to comment.
Something went wrong with that request. Please try again.