-
Notifications
You must be signed in to change notification settings - Fork 4
/
number-test.ss
60 lines (51 loc) · 2.11 KB
/
number-test.ss
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#lang scheme/base
(require "number.ss"
"test-base.ss")
; Tests ------------------------------------------
(define/provide-test-suite number-tests
(test-case "number+false?"
(check-false (number+false? "dave") "string")
(check-true (number+false? #f) "false")
(check-true (number+false? 123.456) "real")
(check-true (number+false? 123) "integer"))
(test-case "integer+false?"
(check-false (integer+false? "dave") "string")
(check-true (integer+false? #f) "false")
(check-false (integer+false? 123.456) "real")
(check-true (integer+false? 123) "integer"))
(test-case "natural?"
(check-false (natural? #f) "false")
(check-false (natural? -1) "negative")
(check-true (natural? 0) "zero")
(check-true (natural? 1) "positive")
(check-false (natural? 1.5) "inexact")
(check-false (natural? (/ 1 2)) "exact"))
(test-case "natural+false?"
(check-true (natural+false? #f) "false")
(check-false (natural+false? -1) "negative")
(check-true (natural+false? 0) "zero")
(check-true (natural+false? 1) "positive")
(check-false (natural+false? 1.5) "inexact")
(check-false (natural+false? (/ 1 2)) "exact"))
(test-case "round-to"
; Positives:
(check-equal? (round-to 123.456 0) 123.0)
(check-equal? (round-to 123.456 1) 123.5)
(check-equal? (round-to 123.456 2) 123.46)
(check-equal? (round-to 123.456 3) 123.456)
(check-equal? (round-to 123.456 4) 123.456)
; Negatives:
(check-equal? (round-to 654.321 0) 654.0)
(check-equal? (round-to 654.321 -1) 650.0)
(check-equal? (round-to 654.321 -2) 700.0)
(check-equal? (round-to 654.321 -3) 1000.0)
(check-equal? (round-to 654.321 -4) 00000.0))
(test-case "reprovided identifiers from convert.ss"
(for-each (lambda (proc)
(check-pred procedure? proc))
(list number+false->string+false
string+false->number+false
number+false->symbol+false
symbol+false->number+false
natural->hex-string
hex-string->natural))))