-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cl
executable file
·133 lines (109 loc) · 3.77 KB
/
test.cl
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env crisp
(import 'test)
;; definition tests
(defun definition-test (result expected)
"Variable definition test"
(defvar testname (format "{0} == {1}" result expected))
(if (= result expected)
(pass-test testname)
(fail-test testname "Variables not equal.")))
(run-test-suite 'definition-test
'(( () (list) )))
(defun addition-test (left right expected)
"Addition test"
(defvar result (+ left right))
(defvar testname (format "{0} + {1} == {2}?" left right expected))
(if (= result expected)
(pass-test testname)
(fail-test testname (format "got {0}, expected {1}." result expected))))
(run-test-suite 'addition-test
'((1 1 2)
(1 -1 0)
(-1 -1 -2)
(2 2 4)
("a" 1 "a1")))
(defun subtraction-test (left right expected)
"Subtraction test"
(defvar result (- left right))
(defvar testname (format "{0} - {1} == {2}?" left right expected))
(if (= result expected)
(pass-test testname)
(fail-test testname (format "got {0}, expected {1}." result expected))))
(run-test-suite 'subtraction-test
'((1 1 0)
(1 -1 2)
(-1 -1 0)
(2 2 0)))
(defun multiplication-test (left right expected)
"Multiplication test"
(defvar result (* left right))
(defvar testname (format "{0}*{1} == {2}?" left right expected))
(if (= result expected)
(pass-test testname)
(fail-test testname (format "got {0}, expected {1}." result expected))))
(run-test-suite 'multiplication-test
'((1 1 1)
(1 -1 -1)
(-1 -1 1)
(2 2 4)))
(defun thread-test ()
"Test threading."
(defvar testname "basic threading")
(defvar expectation 3)
(defun foo ()
"foo"
expectation)
(defvar id (thread 'foo))
(defvar result (join id))
(if (= result expectation)
(pass-test testname)
(fail-test testname (format "Join result not expected. Got {0}, expected {1}" result expectation))))
(thread-test)
(defun default-value-test (args expectation)
"Default value test"
(defun f (a b c) (1 2)
"doc"
(+ (+ a b) c))
(defvar result (eval (insert 'f args)))
(defvar testname (format "default value: {0} == {1} ?" result expectation))
(if (= result expectation)
(pass-test testname)
(fail-test testname "error")))
(run-test-suite 'default-value-test
'(
( (list 3) 6 )
( (list 2 1) 5 )
( (list 1 1 2) 4 )
))
(defun simple-callback (type)
"returns arg"
type)
(defun callback-test (f args expectation)
"calls F on ARGS, catching exceptions and checking against RESULT"
(defvar result (catch "DivideByZeroError" simple-callback ("DivideByZeroError")
(catch "ArgumentError" simple-callback ("ArgumentError")
(apply 'f 'args))))
(if (= result expectation)
(pass-test "throw-catch test")
(fail-test "throw-catch test" "reasons")))
(run-test-suite 'callback-test
'(
('divide (list 1 2) 0)
('divide (list 1 0) "DivideByZeroError")
('throw (list "DivideByZeroError") "DivideByZeroError")
))
(defun vector-maths-test (args expectation)
"Vector maths test"
(import 'vector)
(defvar result (apply '* args))
(defvar testname (format "default value: {0} == {1} ?" result expectation))
(if (= result expectation)
(pass-test testname)
(fail-test testname "error")))
(run-test-suite 'vector-maths-test
'(
( (quote (2 6)) 12 )
( (quote (2 1)) 2 )
( (quote (1 2)) 2 )
))
(print "All tests passed!")