Debian Codegraph @

ext/scheme/test.scm

raw
1 ;;;
2 ;;; Test scheme.*
3 ;;;
4
5 (use gauche.test)
6
7 (test-start "extension scheme modules")
8
9 ;;;
10 ;;; scheme.list (SRFI-1)
11 ;;;
12
13 (test-section "scheme.list")
14 (use scheme.list)
15 (test-module 'scheme.list)
16
17 (define Apply apply) ;avoid inline expansion
18
19 (test* "xcons" '(a . b) (xcons 'b 'a))
20 (test* "cons*" (test-error) (Apply cons* '())) ; use apply to avoid compile error during inlining
21 (test* "cons*" 'o (cons* 'o))
22 (test* "cons*" '(1 2 3 . 4) (cons* 1 2 3 4))
23 (test* "make-list" 5 (length (make-list 5)))
24 (test* "make-list" '() (make-list 0))
25 (test* "make-list" '(m m m m m) (make-list 5 'm))
26 (test* "list-tabulate" '(0 1 2 3 4) (list-tabulate 5 values))
27 (test* "list-tabulate" '(#\0 #\1 #\2 #\3 #\4)
28 (list-tabulate 5 (^i (integer->char (+ i 48)))))
29 (test* "list-tabulate" '(0 2 4 6) (list-tabulate 4 (^i (* i 2))))
30 (test* "list-copy" '(1 2 3) (list-copy '(1 2 3)))
31 (test* "list-copy" '() (list-copy '()))
32 (test* "list-copy" '(1 . 2) (list-copy '(1 . 2)))
33 (test* "list-copy" '(1 2 . 3) (list-copy '(1 2 . 3)))
34 (test* "list-copy" '(1 2 3)
35 (let ((x (list 1 2 3)))
36 (set-car! (list-copy x) 0)
37 x))
38 (test* "list-copy" '(1 2 . 3)
39 (let ((x '(1 2 . 3)))
40 (set-cdr! (cdr (list-copy x)) 0)
41 x))
42 (test* "circular-list" 'a
43 (list-ref (circular-list 'a 'b) 4))
44 (test* "proper-list?" #t (proper-list? '(1 2 4)))
45 (test* "proper-list?" #t (proper-list? '()))
46 (test* "proper-list?" #f (proper-list? 2))
47 (test* "proper-list?" #f (proper-list? '(3 . 1)))
48 (test* "proper-list?" #f (proper-list? (circular-list 1 2)))
49 (test* "proper-list?" #f (proper-list? (cons 0 (circular-list 1 2))))
50 (test* "circular-list?" #t (circular-list? (circular-list 1 2)))
51 (test* "circular-list?" #f (circular-list? '()))
52 (test* "circular-list?" #f (circular-list? '(1 . 2)))
53 (test* "circular-list?" #t (circular-list? (cons 1 (circular-list 2 3))))
54 (test* "dotted-list?" #t (dotted-list? '(1 . 2)))
55 (test* "dotted-list?" #t (dotted-list? 3))
56 (test* "dotted-list?" #f (dotted-list? '(1 2 3)))
57 (test* "dotted-list?" #f (dotted-list? (circular-list 1 2 3)))
58 (test* "dotted-list?" #f (dotted-list? (cons 0 (circular-list 1 2 3))))
59 (test* "dotted-list?" #f (dotted-list? '()))
60 (test* "null-list?" #t (null-list? '()))
61 (test* "null-list?" #f (null-list? '(1)))
62 (test* "not-pair?" #f (not-pair? '(1)))
63 (test* "not-pair?" #t (not-pair? '()))
64 (test* "list=" #t (list= eq?))
65 (test* "list=" #t (list= eq? '(a)))
66 (test* "list=" #t (list= eq? '(a) '(a)))
67 (test* "list=" #f (list= eq? '(a) '(a b)))
68 (test* "list=" #t (list= eq? '(a b) '(a b) '(a b)))
69 (test* "list=" #f (list= eq? '(a b) '(a b) '(a b c)))
70 (test* "list=" #f (list= eq? '(a b) '(a b) '(a)))
71 (test* "list=" #t (list= char-ci=? '(#\a #\b #\z) '(#\A #\B #\Z)))
72 (test* "list=" #f (list= char-ci=? '(#\a #\b #\z) '(#\A #\B)))
73 (test* "first" 1 (first '(1 2 3 4 5 6 7 8 9 10)))
74 (test* "second" 2 (second '(1 2 3 4 5 6 7 8 9 10)))
75 (test* "third" 3 (third '(1 2 3 4 5 6 7 8 9 10)))
76 (test* "fourth" 4 (fourth '(1 2 3 4 5 6 7 8 9 10)))
77 (test* "fifth" 5 (fifth '(1 2 3 4 5 6 7 8 9 10)))
78 (test* "sixth" 6 (sixth '(1 2 3 4 5 6 7 8 9 10)))
79 (test* "seventh" 7 (seventh '(1 2 3 4 5 6 7 8 9 10)))
80 (test* "eighth" 8 (eighth '(1 2 3 4 5 6 7 8 9 10)))
81 (test* "ninth" 9 (ninth '(1 2 3 4 5 6 7 8 9 10)))
82 (test* "tenth" 10 (tenth '(1 2 3 4 5 6 7 8 9 10)))
83 (test* "car+cdr" '(a (b c))
84 (call-with-values (^[] (car+cdr '(a b c))) list))
85 (test* "last" 'c (last '(a b c)))
86 (test* "last-pair" '(c) (last-pair '(a b c)))
87 (test* "length+" '(5 #f)
88 (list (length+ '(1 2 3 4 5))
89 (length+ (circular-list 1 2 3 4 5))))
90 (test* "zip" '((one 1 odd) (two 2 even) (three 3 odd))
91 (zip '(one two three) '(1 2 3)
92 '(odd even odd even odd even)))
93 (test* "zip" '((1) (2) (3)) (zip '(1 2 3)))
94 (test* "zip" '((3 #f) (1 #t) (4 #f) (1 #t))
95 (zip '(3 1 4 1) (circular-list #f #t)))
96 (test* "zip" '() (zip '(a b) '() '(c d)))
97 (define unzip-data '((1 2 3 4 5 6 7 8)
98 (a b c d e)
99 (#\a #\b #\c #\d #\e)
100 ("a" "b" "c" "d" "e")))
101 (test* "unzip1" '(1 a #\a "a") (unzip1 unzip-data))
102 (test* "unzip2" '((1 a #\a "a") (2 b #\b "b"))
103 (call-with-values (^[] (unzip2 unzip-data)) list))
104 (test* "unzip3" '((1 a #\a "a") (2 b #\b "b") (3 c #\c "c"))
105 (call-with-values (^[] (unzip3 unzip-data)) list))
106 (test* "unzip4" '((1 a #\a "a") (2 b #\b "b") (3 c #\c "c") (4 d #\d "d"))
107 (call-with-values (^[] (unzip4 unzip-data)) list))
108 (test* "unzip5"
109 '((1 a #\a "a") (2 b #\b "b") (3 c #\c "c") (4 d #\d "d") (5 e #\e "e"))
110 (call-with-values (^[] (unzip5 unzip-data)) list))
111 (test* "pair-fold" '(5 4 3 2 1)
112 (pair-fold (^[p t] (set-cdr! p t) p) '()
113 (list 1 2 3 4 5)))
114 (test* "pair-fold-right" '((a b c) (b c) (c))
115 (pair-fold-right cons '() '(a b c)))
116 (test* "unfold" '(1 4 9 16 25 36 49 64 81 100)
117 (unfold (^x (> x 10))
118 (^x (* x x))
119 (^x (+ x 1))
120 1))
121 (test* "unfold-right" '(1 4 9 16 25 36 49 64 81 100)
122 (unfold-right zero?
123 (^x (* x x))
124 (^x (- x 1))
125 10))
126 (test* "map" '(4 1 5 1)
127 (map + '(3 1 4 1) (circular-list 1 0)))
128 (test* "for-each" '#(0 2 2 4 4)
129 (rlet1 v (make-vector 5)
130 (for-each (^[i n] (vector-set! v i (+ i n)))
131 '(0 1 2 3 4)
132 (circular-list 0 1))))
133 (test* "map!" '(4 1 5 1)
134 (map! + (list 3 1 4 1) (circular-list 1 0)))
135 (test* "map-in-order" '(4 1 5 1)
136 (map-in-order + '(3 1 4 1) (circular-list 1 0)))
137 (test* "pair-for-each" '((c) (b c) (a b c))
138 (rlet1 r '()
139 (pair-for-each (^l (set! r (cons l r))) '(a b c))))
140 (test* "partition!" '((one four five) (2 3 6))
141 (values->list (partition! symbol? (list 'one 2 3 'four 'five 6))))
142 (test* "take-while" '(2 18)
143 (take-while even? '(2 18 3 10 22 9)))
144 (test* "take-while!" '(2 18)
145 (take-while! even? (list 2 18 3 10 22 9)))
146 (test* "drop-while" '(3 10 22 9)
147 (drop-while even? '(3 10 22 9)))
148 (test* "span" '((2 18) (3 10 22 9))
149 (values->list (span even? '(2 18 3 10 22 9))))
150 (test* "break" '((2 18) (3 10 22 9))
151 (values->list (break odd? '(2 18 3 10 22 9))))
152 (test* "span!" '((2 18) (3 10 22 9))
153 (values->list (span! even? (list 2 18 3 10 22 9))))
154 (test* "break!" '((2 18) (3 10 22 9))
155 (values->list (break! odd? (list 2 18 3 10 22 9))))
156 (test* "any" #t
157 (any integer? '(a 3 b 2.8)))
158 (test* "any" #f
159 (any integer? '(a 3.1 b 2.8)))
160 (test* "any" #t
161 (any < '(3 1 4 1 5) '(2 7 1 8 2)))
162 (test* "every" #f
163 (every integer? '(a 3 b 2.8)))
164 (test* "every" #t
165 (every integer? '(2.0 3.0 8.0 -1.0)))
166 (test* "every" #t
167 (every <= '(1 2 3 4 5) '(2 3 3 5 5)))
168 (test* "list-index" 2
169 (list-index even? '(3 1 4 1 5 9)))
170 (test* "list-index" 1
171 (list-index < '(3 1 4 1 5 9) '(2 7 1)))
172 (test* "list-index" #f
173 (list-index = '(3 1 4 1 5 9) '(2 7 1)))
174 ;; TODO: lset stuff
175
176 (test* "lset=" #t (lset= char-ci=? '(#\a #\B #\c) '(#\C #\A #\b)))
177 (test* "lset=" #f (lset= char-ci=? '(#\a #\B #\c #\d) '(#\C #\A #\b)))
178 (test* "lset=" #f (lset= char-ci=? '(#\a #\B #\c) '(#\C #\d #\A #\b)))
179
180 ;; This tests the argument order of '=' predicate
181 (test* "lset= (order)" #t
182 (lset= (^[x y] (assume (char<=? x y)) (char-ci=? x y))
183 '(#\A #\B #\C) '(#\c #\b #\a)))
184
185 (test* "lset<=" #t (lset<= char-ci=? '(#\a #\B #\c) '(#\C #\A #\b)))
186 (test* "lset<=" #f (lset<= char-ci=? '(#\a #\B #\c #\d) '(#\C #\A #\b)))
187 (test* "lset<=" #t (lset<= char-ci=? '(#\a #\B #\c) '(#\C #\d #\A #\b)))
188
189
190 ;;;
191 ;;; scheme.vector (SRFI-133)
192 ;;;
193
194 (test-section "scheme.vector")
195
196 (use scheme.vector)
197 (test-module 'scheme.vector)
198
199 (use compat.chibi-test)
200 (use srfi.11)
201
202 (chibi-test
203 (include "../../test/include/vectors-test.scm"))
204
205 ;;;
206 ;;; scheme.charset (SRFI-14)
207 ;;;
208
209 (test-section "scheme.charset")
210 (use scheme.charset)
211 (test-module 'scheme.charset)
212
213 ;; built-in char-set features are tested in test/char.scm
214
215 ;; Test samples taken from Olin Shivers' test suite,
216 ;; http://srfi.schemers.org/srfi-14/srfi-14-tests.scm
217 ;; TODO: This doesn't test characters beyond ASCII. See char-set.euc.scm.
218 (define (vowel? c) (member c '(#\a #\e #\i #\o #\u)))
219
220 (test* "char-set?" #f (char-set? 5))
221 (test* "char-set?" #t (char-set? (char-set #\a #\e #\i #\o #\u)))
222 (test* "char-set=" #t (char-set=))
223 (test* "char-set=" #t (char-set= (char-set)))
224 (test* "char-set=" #t (char-set= (char-set #\a #\e #\i #\o #\u)
225 (string->char-set "ioeauaiii")))
226 (test* "char-set=" #f (char-set= (char-set #\e #\i #\o #\u)
227 (string->char-set "ioeauaiii")))
228 (test* "char-set<=" #t (char-set<=))
229 (test* "char-set<=" #t (char-set<= (char-set)))
230 (test* "char-set<=" #t (char-set<= (char-set #\a #\e #\i #\o #\u)
231 (string->char-set "ioeauaiii")))
232 (test* "char-set<=" #t (char-set<= (char-set #\e #\i #\o #\u)
233 (string->char-set "ioeauaiii")))
234
235 (test* "char-set-hash" #t
236 (<= 0 (char-set-hash char-set:graphic 100) 99))
237 (test* "char-set-fold" #t
238 (= 4 (char-set-fold (^[c i] (+ i 1)) 0
239 (char-set #\e #\i #\o #\u #\e #\e))))
240 (test* "char-set-unfold" #t
241 (char-set= (string->char-set "eiaou2468013579999")
242 (char-set-unfold null? car cdr
243 '(#\a #\e #\i #\o #\u #\u #\u)
244 char-set:ascii-digit)))
245 (test* "char-set-unfold (default)" #t
246 (char-set= (string->char-set "aeiou")
247 (char-set-unfold null? car cdr
248 '(#\a #\e #\i #\o #\u #\u #\u))))
249 (test* "char-set-unfold!" #t
250
251 (char-set= (string->char-set "eiaou246801357999")
252 (char-set-unfold! null? car cdr '(#\a #\e #\i #\o #\u)
253 (string->char-set "0123456789"))))
254 (test* "char-set-unfold!" #f
255 (char-set= (string->char-set "eiaou246801357")
256 (char-set-unfold! null? car cdr '(#\a #\e #\i #\o #\u)
257 (string->char-set "0123456789"))))
258 (test* "char-set-for-each" #t
259 (let ([cs (string->char-set "0123456789")])
260 (char-set-for-each (^c (set! cs (char-set-delete cs c)))
261 (string->char-set "02468000"))
262 (char-set= cs (string->char-set "97531"))))
263 (test* "char-set-for-each" #t
264 (not (let ([cs (string->char-set "0123456789")])
265 (char-set-for-each (^c (set! cs (char-set-delete cs c)))
266 (string->char-set "02468"))
267 (char-set= cs (string->char-set "7531")))))
268 (test* "char-set-map" #t
269 (char-set= (char-set-map char-upcase (string->char-set "aeiou"))
270 (string->char-set "IOUAEEEE")))
271 (test* "char-set-map" #f
272 (char-set= (char-set-map char-upcase (string->char-set "aeiou"))
273 (string->char-set "OUAEEEE")))
274 (test* "char-set-copy" #t
275 (char-set= (char-set-copy (string->char-set "aeiou"))
276 (string->char-set "aeiou")))
277 (test* "string->char-set" #t
278 (char-set= (char-set #\x #\y) (string->char-set "xy")))
279 (test* "string->char-set" #t
280 (not (char-set= (char-set #\x #\y #\z) (string->char-set "xy"))))
281 (test* "list->char-set" #t
282 (char-set= (string->char-set "xy") (list->char-set '(#\x #\y))))
283 (test* "list->char-set" #f
284
285 (char-set= (string->char-set "axy") (list->char-set '(#\x #\y))))
286 (test* "list->char-set" #t
287
288 (char-set= (string->char-set "xy12345")
289 (list->char-set '(#\x #\y) (string->char-set "12345"))))
290 (test* "list->char-set" #f
291 (char-set= (string->char-set "y12345")
292 (list->char-set '(#\x #\y) (string->char-set "12345"))))
293 (test* "list->char-set!" #t
294 (char-set= (string->char-set "xy12345")
295 (list->char-set! '(#\x #\y) (string->char-set "12345"))))
296 (test* "list->char-set!" #f
297 (char-set= (string->char-set "y12345")
298 (list->char-set! '(#\x #\y) (string->char-set "12345"))))
299 (test* "char-set-filter" #t
300 (char-set= (string->char-set "aeiou12345")
301 (char-set-filter vowel? char-set:ascii
302 (string->char-set "12345"))))
303 (test* "char-set-filter" #f
304 (char-set= (string->char-set "aeou12345")
305 (char-set-filter vowel? char-set:ascii
306 (string->char-set "12345"))))
307 (test* "char-set-filter!" #t
308 (char-set= (string->char-set "aeiou12345")
309 (char-set-filter! vowel? char-set:ascii
310 (string->char-set "12345"))))
311 (test* "char-set-filter!" #f
312 (char-set= (string->char-set "aeou12345")
313 (char-set-filter! vowel? char-set:ascii
314 (string->char-set "12345"))))
315 (test* "ucs-range->char-set" #t
316 (char-set= (string->char-set "abcdef12345")
317 (ucs-range->char-set 97 103 #t
318 (string->char-set "12345"))))
319 (test* "ucs-range->char-set" #f
320 (char-set= (string->char-set "abcef12345")
321 (ucs-range->char-set 97 103 #t
322 (string->char-set "12345"))))
323 (test* "ucs-range->char-set!" #t
324 (char-set= (string->char-set "abcdef12345")
325 (ucs-range->char-set! 97 103 #t
326 (string->char-set "12345"))))
327 (test* "ucs-range->char-set!" #f
328 (char-set= (string->char-set "abcef12345")
329 (ucs-range->char-set! 97 103 #t
330 (string->char-set "12345"))))
331 (test* "integer-range->char-set" #t
332 (char-set= (string->char-set "abcdef12345")
333 (integer-range->char-set 97 103 #t
334 (string->char-set "12345"))))
335 (test* "integer-range->char-set" #f
336 (char-set= (string->char-set "abcef12345")
337 (integer-range->char-set 97 103 #t
338 (string->char-set "12345"))))
339 (test* "integer-range->char-set!" #t
340 (char-set= (string->char-set "abcdef12345")
341 (integer-range->char-set! 97 103 #t
342 (string->char-set "12345"))))
343 (test* "integer-range->char-set!" #f
344 (char-set= (string->char-set "abcef12345")
345 (integer-range->char-set! 97 103 #t
346 (string->char-set "12345"))))
347
348 (test* "->char-set" #t
349 (char-set= (->char-set #\x)
350 (->char-set "x")
351 (->char-set (char-set #\x))))
352 (test* "->char-set" #f
353 (char-set= (->char-set #\x)
354 (->char-set "y")
355 (->char-set (char-set #\x))))
356 (test* "->char-set" #t
357 (char-set= (->char-set "abc")
358 (->char-set '#(#\c #\a #\b #\a))))
359 (test* "char-set-size" 10
360 (char-set-size (char-set-intersection char-set:ascii char-set:digit)))
361 (test* "char-set-count" 5
362 (char-set-count vowel? char-set:ascii))
363 (test* "char-set->list" #t
364 (equal? '(#\x) (char-set->list (char-set #\x))))
365 (test* "char-set->list" #f
366 (equal? '(#\X) (char-set->list (char-set #\x))))
367 (test* "char-set->string" #t
368 (equal? "x" (char-set->string (char-set #\x))))
369 (test* "char-set->string" #f
370 (equal? "X" (char-set->string (char-set #\x))))
371 (test* "char-set-contains?" #t
372 (char-set-contains? (->char-set "xyz") #\x))
373 (test* "char-set-contains?" #f
374 (char-set-contains? (->char-set "xyz") #\a))
375 (test* "char-set-complement (ascii, nohit)" #f
376 (char-set-contains? (char-set-complement (char-set #\a)) #\a))
377 (test* "char-set-complement (ascii, hit)" #t
378 (char-set-contains? (char-set-complement (char-set #\a)) #\b))
379 (test* "char-set-complement (~#x80, nohit)" #f
380 (char-set-contains? (char-set-complement (char-set (integer->char #x80)))
381 (integer->char #x80)))
382 (test* "char-set-complement (~#x80, hit)" #t
383 (char-set-contains? (char-set-complement (char-set (integer->char #x80)))
384 (integer->char #x81)))
385 (test* "char-set-complement (~~#x80, hit)" #t
386 (char-set-contains? (char-set-complement
387 (char-set-complement
388 (char-set (integer->char #x80))))
389 (integer->char #x80)))
390 (test* "char-set-complement (~~#x80, nohit)" #f
391 (char-set-contains? (char-set-complement
392 (char-set-complement
393 (char-set (integer->char #x80))))
394 (integer->char #x81)))
395 (test* "char-set-complement (~#x82, nohit)" #f
396 (char-set-contains? (char-set-complement (char-set (integer->char #x82)))
397 (integer->char #x82)))
398 (test* "char-set-complement (~#x82, hit-upper)" #t
399 (char-set-contains? (char-set-complement (char-set (integer->char #x82)))
400 (integer->char #x83)))
401 (test* "char-set-complement (~#x82, hit-lower)" #t
402 (char-set-contains? (char-set-complement (char-set (integer->char #x82)))
403 (integer->char #x81)))
404 (test* "char-set-complement (~~#x82, hit)" #t
405 (char-set-contains? (char-set-complement
406 (char-set-complement
407 (char-set (integer->char #x82))))
408 (integer->char #x82)))
409 (test* "char-set-complement (~~#x82, nohit-upper)" #f
410 (char-set-contains? (char-set-complement
411 (char-set-complement
412 (char-set (integer->char #x82))))
413 (integer->char #x83)))
414 (test* "char-set-complement (~~#x82, nohit-lower)" #f
415 (char-set-contains? (char-set-complement
416 (char-set-complement
417 (char-set (integer->char #x82))))
418 (integer->char #x81)))
419 (test* "char-set-complement (~empty)" #t
420 (char-set-contains? (char-set-complement (char-set))
421 (integer->char #x80)))
422 (test* "char-set-complement (~~empty)" #f
423 (char-set-contains? (char-set-complement (char-set-complement (char-set)))
424 (integer->char #x80)))
425 (test* "char-set-every" #t
426 (char-set-every char-lower-case? (->char-set "abcd")))
427 (test* "char-set-every" #f
428 (char-set-every char-lower-case? (->char-set "abcD")))
429 (test* "char-set-any" #t
430 (char-set-any char-lower-case? (->char-set "abcd")))
431 (test* "char-set-any" #f
432 (char-set-any char-lower-case? (->char-set "ABCD")))
433 (test* "char-set iterators" #t
434 (char-set= (->char-set "ABCD")
435 (let ([cs (->char-set "abcd")])
436 (let lp ([cur (char-set-cursor cs)] [ans '()])
437 (if (end-of-char-set? cur) (list->char-set ans)
438 (lp (char-set-cursor-next cs cur)
439 (cons (char-upcase (char-set-ref cs cur)) ans)))))))
440 (test* "char-set-adjoin" #t
441 (char-set= (char-set-adjoin (->char-set "123") #\x #\a)
442 (->char-set "123xa")))
443 (test* "char-set-adjoin" #f
444 (char-set= (char-set-adjoin (->char-set "123") #\x #\a)
445 (->char-set "123x")))
446 (test* "char-set-adjoin!" #t
447 (char-set= (char-set-adjoin! (->char-set "123") #\x #\a)
448 (->char-set "123xa")))
449 (test* "char-set-adjoin!" #f
450 (char-set= (char-set-adjoin! (->char-set "123") #\x #\a)
451 (->char-set "123x")))
452 (test* "char-set-delete" #t
453 (char-set= (char-set-delete (->char-set "123") #\2 #\a #\2)
454 (->char-set "13")))
455 (test* "char-set-delete" #f
456 (char-set= (char-set-delete (->char-set "123") #\2 #\a #\2)
457 (->char-set "13a")))
458 (test* "char-set-delete" #t
459 (char-set= (char-set-adjoin (char-set-delete char-set:full #\;) #\;)
460 char-set:full))
461 (test* "char-set-delete!" #t
462 (char-set= (char-set-delete! (->char-set "123") #\2 #\a #\2)
463 (->char-set "13")))
464 (test* "char-set-delete!" #f
465 (char-set= (char-set-delete! (->char-set "123") #\2 #\a #\2)
466 (->char-set "13a")))
467 (test* "char-set-delete!" #[\x81\x83\x84\x86]
468 (char-set-delete! (->char-set '(#\x81 #\x82 #\x83 #\x84 #\x85 #\x86 #\x87))
469 #\x82 #\x87 #\x85)
470 char-set=)
471 (test* "char-set-intersection" #t
472 (char-set= (char-set-intersection char-set:hex-digit (char-set-complement char-set:digit))
473 (->char-set "abcdefABCDEF")))
474 (test* "char-set-intersection!" #t
475 (char-set= (char-set-intersection! (char-set-complement! (->char-set "0123456789"))
476 char-set:hex-digit)
477 (->char-set "abcdefABCDEF")))
478 (test* "char-set-union" #t
479 (char-set= (char-set-union char-set:hex-digit
480 (->char-set "abcdefghijkl"))
481 (->char-set "abcdefABCDEFghijkl0123456789")))
482 (test* "char-set-union!" #t
483 (char-set= (char-set-union! (->char-set "abcdefghijkl")
484 char-set:hex-digit)
485 (->char-set "abcdefABCDEFghijkl0123456789")))
486 (test* "char-set-union!" #[\x81-\x89]
487 (char-set-union! (->char-set '(#\x81 #\x83 #\x84 #\x86 #\x87))
488 (->char-set '(#\x82 #\x85 #\x86 #\x88 #\x89)))
489 char-set=)
490 (test* "char-set-difference" #t
491 (char-set= (char-set-difference (->char-set "abcdefghijklmn")
492 char-set:hex-digit)
493 (->char-set "ghijklmn")))
494 (test* "char-set-difference!" #t
495 (char-set= (char-set-difference! (->char-set "abcdefghijklmn")
496 char-set:hex-digit)
497 (->char-set "ghijklmn")))
498 (test* "char-set-xor" #t
499 (char-set= (char-set-xor (->char-set "0123456789")
500 char-set:hex-digit)
501 (->char-set "abcdefABCDEF")))
502 (test* "char-set-xor!" #t
503 (char-set= (char-set-xor! (->char-set "0123456789")
504 char-set:hex-digit)
505 (->char-set "abcdefABCDEF")))
506 (test* "char-set-diff+intersection" #t
507 (call-with-values (^[] (char-set-diff+intersection char-set:hex-digit
508 char-set:letter))
509 (^[d i]
510 (and (char-set= d (->char-set "0123456789"))
511 (char-set= i (->char-set "abcdefABCDEF"))))))
512 (test* "char-set-diff+intersection!" #t
513 (call-with-values (^[]
514 (char-set-diff+intersection! (char-set-copy char-set:hex-digit)
515 (char-set-copy char-set:letter)))
516 (^[d i]
517 (and (char-set= d (->char-set "0123456789"))
518 (char-set= i (->char-set "abcdefABCDEF"))))))
519
520 (test* "char-set object-apply" '(#t #f)
521 (list (#[a-z] #\a) (#[a-z] #\A)))
522
523 ;; https://github.com/shirok/Gauche/pull/500
524 (test* "CharSetAdd large flag bug" #t
525 (char-set= (char-set-intersection
526 (char-set-union (string->char-set "_")
527 char-set:letter+digit)
528 char-set:full)
529 (char-set-intersection
530 (char-set-union char-set:letter+digit
531 (string->char-set "_"))
532 char-set:full)))
533
534 ;;;
535 ;;; scheme.flonum (SRFI-144)
536 ;;;
537
538 (test-section "scheme.flonum")
539 (use scheme.flonum)
540 (test-module 'scheme.flonum)
541
542 (define-module scheme-flonum-test
543
544 (define-module srfi.144 (extend scheme.flonum))
545 (define-module tests.scheme.test
546 (use gauche.test)
547 (export test test/one-of test/unspec-or-exn test/approx test/approx-1ulp)
548 (define (f=? a b)
549 (cond [(flonum? a)
550 (and (flonum? b)
551 (cond [(nan? a) (nan? b)]
552 [(negative-zero? a) (negative-zero? b)]
553 [else (eqv? a b)]))]
554 [(list? a)
555 (and (list? b) (= (length a) (length b))
556 (every f=? a b))]
557 [else (equal? a b)]))
558 (define-syntax test
559 (syntax-rules ()
560 [(_ expr expected)
561 (test* #"~'expr" expected expr f=?)]))
562 (define-syntax test/one-of
563 (syntax-rules ()
564 [(_ expr expected-list)
565 (test* #"~'expr" expected-list expr
566 (^[elis r] (any (cut f=? <> r) elis)))]))
567 (define-syntax test/unspec-or-exn
568 (syntax-rules ()
569 [(_ expr _)
570 (test* #"~'expr (error)" (test-error) expr)]))
571 (define-syntax test/approx-1ulp
572 (syntax-rules ()
573 [(_ expr expected)
574 (test* #"~'expr (approx 1ulp)" expected expr
575 (^[x y]
576 (if (list? x)
577 (and (list? y) (every approx=? x y))
578 (approx=? x y))))]))
579 ;; NB: MinGW's bessel function jn has greater errors and we need
580 ;; to relax approx check.
581 (define rel-tolerance
582 (cond-expand
583 [gauche.os.windows 5e-7]
584 [else 1e-9]))
585 (define-syntax test/approx
586 (syntax-rules ()
587 [(_ expr expected)
588 (test* #"~'expr (approx)" expected expr
589 (cut approx=? <> <> rel-tolerance 1e-15))])))
590 (use scheme.base)
591 (include "../../test/include/srfi-144-tests.scm")
592 (with-module tests.scheme.flonum
593 (run-flonum-tests)))
594
595 (test-end)