-
Notifications
You must be signed in to change notification settings - Fork 2
/
common.rkt
46 lines (36 loc) · 1.12 KB
/
common.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#lang racket
(define (log . vars)
(display vars)
(display #\newline))
(define (assert-true value1 value2 predicate error-message)
(if (predicate value1 value2)
(log "OK")
(and
(printf "~a ~a ~a ~a" "ERROR!" value1 error-message value2)
(display #\newline)))
)
(define (assert message value1 value2)
(display (mk-string (list "\t" message " ")))
(assert-true value1 value2 equal? "did NOT equal")
)
(define (assert-simple value1 value2)
(assert "" value1 value2))
(define (assert-equals value1 value2)
(assert-simple value1 value2))
(define (assert-not message value1 value2)
(display (mk-string (list "\t" message " ")))
(assert-true value1 value2 (lambda(x y) (not (equal? x y))) "did equal"))
(define (mk-string xs)
(define (concat-with-space x y)
(string-append (string-append x " ") y))
(fold-left xs concat-with-space ""))
(define (fold-left xs f seed)
(if (null? xs)
seed
(f seed (fold-left (cdr xs) f (car xs)))))
(define (test name f)
(display name)
(display #\newline)
(f)
)
(provide log assert-true assert-simple assert-equals assert assert-not test)