Ticket #421: test-optional.scm

File test-optional.scm, 3.7 KB (added by Alan Post, 13 years ago)

test case designed to be placed in chicken-core/tests/

Line 
1(define (test baseline result)
2    (assert (equal? baseline result)))
3
4;;
5;; basic optional arguments with default value.
6;;
7
8(define (foo0 #!optional a0 a1 a2 a3)
9  (list a0 a1 a2 a3))
10
11(define (foo1 a0 #!optional a1 a2 a3)
12  (list a0 a1 a2 a3))
13
14(define (foo2 a0 a1 #!optional a2 a3)
15  (list a0 a1 a2 a3))
16
17(define (foo3 a0 a1 a2 #!optional a3)
18  (list a0 a1 a2 a3))
19
20(test '(#f #f #f #f) (foo0))
21(test '(1  #f #f #f) (foo0 1))
22(test '(1  2  #f #f) (foo0 1 2))
23(test '(1  2   3 #f) (foo0 1 2 3))
24(test '(1  2   3  4) (foo0 1 2 3 4))
25
26;(test '(#f #f #f #f) (foo1)) ; invalid, too few arguments.
27(test '(1  #f #f #f) (foo1 1))
28(test '(1  2  #f #f) (foo1 1 2))
29(test '(1  2   3 #f) (foo1 1 2 3))
30(test '(1  2   3  4) (foo1 1 2 3 4))
31
32;(test '(#f #f #f #f) (foo2)) ; invalid, too few arguments.
33;(test '(1 #f  #f #f) (foo2 0)) ; invalid, too few arguments.
34(test '(1  2  #f #f) (foo2 1 2))
35(test '(1  2  #f #f) (foo2 1 2))
36(test '(1  2   3 #f) (foo2 1 2 3))
37(test '(1  2   3  4) (foo2 1 2 3 4))
38
39;(test '(#f #f #f #f) (foo3)) ; invalid, too few arguments.
40;(test '(1  #f #f #f) (foo3 1)) ; invalid, too few arguments.
41;(test '(1  2  #f #f) (foo3 1 2)) ; invalid, too few arguments.
42(test '(1  2   3 #f) (foo3 1 2 3))
43(test '(1  2   3  4) (foo3 1 2 3 4))
44
45;;
46;; basic optional arguments with manual default value.
47;;
48
49(define (foo0 #!optional (a0 -1) (a1 -2) (a2 -3) (a3 -4))
50  (list a0 a1 a2 a3))
51
52(define (foo1 a0 #!optional (a1 -2) (a2 -3) (a3 -4))
53  (list a0 a1 a2 a3))
54
55(define (foo2 a0 a1 #!optional (a2 -3) (a3 -4))
56  (list a0 a1 a2 a3))
57
58(define (foo3 a0 a1 a2 #!optional (a3 -4))
59  (list a0 a1 a2 a3))
60
61
62(test '(-1 -2 -3 -4) (foo0))
63(test '(1  -2 -3 -4) (foo0 1))
64(test '(1  2  -3 -4) (foo0 1 2))
65(test '(1  2   3 -4) (foo0 1 2 3))
66(test '(1  2   3  4) (foo0 1 2 3 4))
67
68;(test '(-1 -2 -3 -4) (foo1)) ; invalid, too few arguments.
69(test '(1  -2 -3 -4) (foo1 1))
70(test '(1  2  -3 -4) (foo1 1 2))
71(test '(1  2   3 -4) (foo1 1 2 3))
72(test '(1  2   3  4) (foo1 1 2 3 4))
73
74;(test '(-1 -2 -3 -4) (foo2)) ; invalid, too few arguments.
75;(test '(1 -2  -3 -4) (foo2 0)) ; invalid, too few arguments.
76(test '(1  2  -3 -4) (foo2 1 2))
77(test '(1  2  -3 -4) (foo2 1 2))
78(test '(1  2   3 -4) (foo2 1 2 3))
79(test '(1  2   3  4) (foo2 1 2 3 4))
80
81;(test '(-1 -2 -3 -4) (foo3)) ; invalid, too few arguments.
82;(test '(1  -2 -3 -4) (foo3 1)) ; invalid, too few arguments.
83;(test '(1  2  -3 -4) (foo3 1 2)) ; invalid, too few arguments.
84(test '(1  2   3 -4) (foo3 1 2 3))
85(test '(1  2   3  4) (foo3 1 2 3 4))
86
87;;
88;; optional arguments with default value set from previous default.
89;;
90;; NOTE: these currently fail.
91
92(define (foo0 #!optional (a0 -1) (a1 (- a0 1)) (a2 (- a1 1)) (a3 (- a2 1)))
93  (list a0 a1 a2 a3))
94
95(define (foo1 a0 #!optional (a1 -2) (a2 (- a1 1)) (a3 (- a2 1)))
96  (list a0 a1 a2 a3))
97
98(define (foo2 a0 a1 #!optional (a2 -3) (a3 (- a2 1)))
99  (list a0 a1 a2 a3))
100
101(define (foo3 a0 a1 a2 #!optional (a3 -4))
102  (list a0 a1 a2 a3))
103
104
105(test '(-1 -2 -3 -4) (foo0))
106(test '(1  -2 -3 -4) (foo0 1))
107(test '(1  2  -3 -4) (foo0 1 2))
108(test '(1  2   3 -4) (foo0 1 2 3))
109(test '(1  2   3  4) (foo0 1 2 3 4))
110
111;(test '(-1 -2 -3 -4) (foo1)) ; invalid, too few arguments.
112(test '(1  -2 -3 -4) (foo1 1))
113(test '(1  2  -3 -4) (foo1 1 2))
114(test '(1  2   3 -4) (foo1 1 2 3))
115(test '(1  2   3  4) (foo1 1 2 3 4))
116
117;(test '(-1 -2 -3 -4) (foo2)) ; invalid, too few arguments.
118;(test '(1 -2  -3 -4) (foo2 0)) ; invalid, too few arguments.
119(test '(1  2  -3 -4) (foo2 1 2))
120(test '(1  2  -3 -4) (foo2 1 2))
121(test '(1  2   3 -4) (foo2 1 2 3))
122(test '(1  2   3  4) (foo2 1 2 3 4))
123
124;(test '(-1 -2 -3 -4) (foo3)) ; invalid, too few arguments.
125;(test '(1  -2 -3 -4) (foo3 1)) ; invalid, too few arguments.
126;(test '(1  2  -3 -4) (foo3 1 2)) ; invalid, too few arguments.
127(test '(1  2   3 -4) (foo3 1 2 3))
128(test '(1  2   3  4) (foo3 1 2 3 4))