nendo 0.6.8 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/srfi-1-test.nnd DELETED
@@ -1,684 +0,0 @@
1
- ;;-*- mode: nendo; syntax: scheme -*-;;
2
- ; Test suite for SRFI-1
3
- ; 2003-12-29 / lth
4
- ;
5
- ; $Id: srfi-1-test.sps 5842 2008-12-11 23:04:51Z will $
6
- ;
7
- ; Note: In Larceny, we require that the procedures designated as
8
- ; "linear update" variants in the spec (eg append!) side-effect their
9
- ; arguments, and there are tests here that check that side-effecting
10
- ; occurs.
11
- ;
12
- ; For linear update we only require that the cells of the result are
13
- ; taken from the cells of the input. We could be stricter and require
14
- ; that the cells of the results are the cells of the input with only
15
- ; the CDR changed, ie, values are never moved from one cell to another.
16
- ;
17
- ;; Subsequently modified for nendo: Kiyoka Nishiyama
18
-
19
- (load "srfi-1")
20
-
21
- (define (writeln . xs)
22
- (for-each display xs)
23
- (newline))
24
-
25
- (define (fail token . more)
26
- (error (sprintf "Error: test failed: %s" token))
27
- #f)
28
-
29
- ;; ad-hoc let-values macro. When Nendo surpports srfi-11, replace this code with it. ( Kiyoka Nishiyama )
30
- (define let-values
31
- (macro (vars body)
32
- (let1 lr (car vars)
33
- `(receive
34
- ,(first lr)
35
- ,(second lr)
36
- ,body))))
37
-
38
- ; Test cases are ordered as in the spec. R5RS procedures are left out.
39
-
40
- (or (equal? (xcons 1 2) '(2 . 1))
41
- (fail 'xcons:1))
42
-
43
- (or (equal? (cons* 1) 1)
44
- (fail 'cons*:1))
45
- (or (equal? (cons* 1 2 3 4 5) '(1 2 3 4 . 5))
46
- (fail 'cons*:2))
47
-
48
- (or (equal? (make-list 5 #t) '(#t #t #t #t #t))
49
- (fail 'make-list:1))
50
- (or (equal? (make-list 0 #f) '())
51
- (fail 'make-list:2))
52
- (or (equal? (length (make-list 3)) 3)
53
- (fail 'make-list:3))
54
-
55
- (or (equal? (list-tabulate 5 (lambda (x) x)) '(0 1 2 3 4))
56
- (fail 'list-tabulate:1))
57
- (or (equal? (list-tabulate 0 (lambda (x) (error "FOO!"))) '())
58
- (fail 'list-tabluate:2))
59
-
60
- (or (let* ((c (list 1 2 3 4 5))
61
- (cp (list-copy c)))
62
- (equal? c cp))
63
- (fail 'list-copy:1))
64
-
65
- (or (equal? (list-copy '(1 2 3 . 4)) '(1 2 3 . 4))
66
- (fail 'list-copy:2))
67
-
68
- (or (not (list? (circular-list 1 2 3)))
69
- (fail 'circular-list:1))
70
- (or (let* ((a (list 'a))
71
- (b (list 'b))
72
- (c (list 'c))
73
- (x (circular-list a b c)))
74
- (and (eq? a (car x))
75
- (eq? b (cadr x))
76
- (eq? c (caddr x))
77
- (eq? a (cadddr x))))
78
- (fail 'circular-list:2))
79
-
80
- (or (equal? (iota 0) '())
81
- (fail 'iota:1))
82
- (or (equal? (iota 5 2 3) '(2 5 8 11 14))
83
- (fail 'iota:2))
84
- (or (equal? (iota 5 2) '(2 3 4 5 6))
85
- (fail 'iota:3))
86
-
87
- (or (proper-list? '(1 2 3 4 5))
88
- (fail 'proper-list?:1))
89
- (or (proper-list? '())
90
- (fail 'proper-list?:2))
91
- (or (not (proper-list? '(1 2 . 3)))
92
- (fail 'proper-list?:3))
93
- (or (not (proper-list? (circular-list 1 2 3)))
94
- (fail 'proper-list:4))
95
-
96
- (or (not (circular-list? '(1 2 3 4 5)))
97
- (fail 'circular-list?:1))
98
- (or (not (circular-list? '()))
99
- (fail 'circular-list?:2))
100
- (or (not (circular-list? '(1 2 . 3)))
101
- (fail 'circular-list?:3))
102
- (or (circular-list? (circular-list 1 2 3))
103
- (fail 'circular-list:4))
104
-
105
- (or (not (dotted-list? '(1 2 3 4 5)))
106
- (fail 'dotted-list?:1))
107
- (or (not (dotted-list? '()))
108
- (fail 'dotted-list?:2))
109
- (or (dotted-list? '(1 2 . 3))
110
- (fail 'dotted-list?:3))
111
- (or (not (dotted-list? (circular-list 1 2 3)))
112
- (fail 'dotted-list:4))
113
-
114
- (or (null-list? '())
115
- (fail 'null-list?:1))
116
- (or (not (null-list? '(1 2)))
117
- (fail 'null-list?:2))
118
- (or (not (null-list? (circular-list 1 2)))
119
- (fail 'null-list?:3))
120
-
121
- (or (not-pair? 1)
122
- (fail 'not-pair:1))
123
- (or (not (not-pair? (cons 1 2)))
124
- (fail 'not-pair:2))
125
-
126
- (or (list= = '(1 2 3) '(1 2 3) '(1 2 3))
127
- (fail 'list=:1))
128
- (or (not (list= = '(1 2 3) '(1 2 3) '(1 4 3)))
129
- (fail 'list=:2))
130
- ; Checks that l0 is not being used when testing l2, cf spec
131
- (or (list= (lambda (a b) (not (eq? a b))) '(#f #f #f) '(#t #t #t) '(#f #f #f))
132
- (fail 'list=:3))
133
- (or (list= =)
134
- (fail 'list=:4))
135
-
136
- (or (= (first '(1 2 3 4 5 6 7 8 9 10)) 1) (fail 'first))
137
- (or (= (second '(1 2 3 4 5 6 7 8 9 10)) 2) (fail 'second))
138
- (or (= (third '(1 2 3 4 5 6 7 8 9 10)) 3) (fail 'third))
139
- (or (= (fourth '(1 2 3 4 5 6 7 8 9 10)) 4) (fail 'fourth))
140
- (or (= (fifth '(1 2 3 4 5 6 7 8 9 10)) 5) (fail 'fifth))
141
- (or (= (sixth '(1 2 3 4 5 6 7 8 9 10)) 6) (fail 'sixth))
142
- (or (= (seventh '(1 2 3 4 5 6 7 8 9 10)) 7) (fail 'seventh))
143
- (or (= (eighth '(1 2 3 4 5 6 7 8 9 10)) 8) (fail 'eighth))
144
- (or (= (ninth '(1 2 3 4 5 6 7 8 9 10)) 9) (fail 'ninth))
145
- (or (= (tenth '(1 2 3 4 5 6 7 8 9 10)) 10) (fail 'tenth))
146
-
147
- (let-values (((a b) (car+cdr '(1 . 2))))
148
- (or (and (= a 1) (= b 2))
149
- (fail 'car+cdr:1)))
150
-
151
- (or (equal? '(1 2 3) (take '(1 2 3 4 5 6) 3))
152
- (fail 'take:1))
153
- (or (equal? '(1) (take '(1) 1))
154
- (fail 'take:2))
155
-
156
- (or (let ((x (list 1 2 3 4 5 6)))
157
- (eq? (cdddr x) (drop x 3)))
158
- (fail 'drop:1))
159
- (or (let ((x (list 1 2 3)))
160
- (eq? x (drop x 0)))
161
- (fail 'drop:2))
162
-
163
- (or (equal? '(4 5 6) (take-right '(1 2 3 4 5 6) 3))
164
- (fail 'take-right:1))
165
- (or (null? (take-right '(1 2 3 4 5 6) 0))
166
- (fail 'take-right:2))
167
- (or (equal? '(2 3 . 4) (take-right '(1 2 3 . 4) 2))
168
- (fail 'take-right:3))
169
- (or (equal? 4 (take-right '(1 2 3 . 4) 0))
170
- (fail 'take-right:4))
171
-
172
- (or (equal? '(1 2 3) (drop-right '(1 2 3 4 5 6) 3))
173
- (fail 'drop-right:1))
174
- (or (equal? '(1 2 3) (drop-right '(1 2 3) 0))
175
- (fail 'drop-right:2))
176
- (or (equal? '(1 2 3) (drop-right '(1 2 3 . 4) 0))
177
- (fail 'drop-right:3))
178
-
179
- (or (let ((x (list 1 2 3 4 5 6)))
180
- (let ((y (take! x 3)))
181
- (and (eq? x y)
182
- (eq? (cdr x) (cdr y))
183
- (eq? (cddr x) (cddr y))
184
- (equal? y '(1 2 3)))))
185
- (fail 'take!:1))
186
-
187
- (or (let ((x (list 1 2 3 4 5 6)))
188
- (let ((y (drop-right! x 3)))
189
- (and (eq? x y)
190
- (eq? (cdr x) (cdr y))
191
- (eq? (cddr x) (cddr y))
192
- (equal? y '(1 2 3)))))
193
- (fail 'drop-right!:1))
194
-
195
- (or (let-values (((a b) (split-at '(1 2 3 4 5 6) 2)))
196
- (and (equal? a '(1 2))
197
- (equal? b '(3 4 5 6))))
198
- (fail 'split-at:1))
199
-
200
- (or (let* ((x (list 1 2 3 4 5 6))
201
- (y (cddr x)))
202
- (let-values (((a b) (split-at! x 2)))
203
- (and (equal? a '(1 2))
204
- (eq? a x)
205
- (equal? b '(3 4 5 6))
206
- (eq? b y))))
207
- (fail 'split-at!:1))
208
-
209
- (or (eq? 37 (last '(1 2 3 37)))
210
- (fail 'last:1))
211
-
212
- (or (not (length+ (circular-list 1 2 3)))
213
- (fail 'length+:1))
214
- (or (equal? 4 (length+ '(1 2 3 4)))
215
- (fail 'length+:2))
216
-
217
- (or (let ((x (list 1 2))
218
- (y (list 3 4))
219
- (z (list 5 6)))
220
- (let ((r (append! x y '() z)))
221
- (and (equal? r '(1 2 3 4 5 6))
222
- (eq? r x)
223
- (eq? (cdr r) (cdr x))
224
- (eq? (cddr r) y)
225
- (eq? (cdddr r) (cdr y))
226
- (eq? (cddddr r) z)
227
- (eq? (cdr (cddddr r)) (cdr z)))))
228
- (fail 'append!:1))
229
-
230
- (or (equal? (concatenate '((1 2 3) (4 5 6) () (7 8 9))) '(1 2 3 4 5 6 7 8 9))
231
- (fail 'concatenate:1))
232
-
233
- (or (equal? (concatenate! `(,(list 1 2 3) ,(list 4 5 6) () ,(list 7 8 9)))
234
- '(1 2 3 4 5 6 7 8 9))
235
- (fail 'concatenate!:1))
236
-
237
- (or (equal? (append-reverse '(3 2 1) '(4 5 6)) '(1 2 3 4 5 6))
238
- (fail 'append-reverse:1))
239
-
240
- (or (equal? (append-reverse! (list 3 2 1) (list 4 5 6)) '(1 2 3 4 5 6))
241
- (fail 'append-reverse!:1))
242
-
243
- (or (equal? (zip '(1 2 3) '(4 5 6)) '((1 4) (2 5) (3 6)))
244
- (fail 'zip:1))
245
- (or (equal? (zip '() '() '() '()) '())
246
- (fail 'zip:2))
247
- (or (equal? (zip '(1) (circular-list 1 2)) '((1 1)))
248
- (fail 'zip:3))
249
-
250
- (or (equal? '(1 2 3 4 5) (unzip1 '((1) (2) (3) (4) (5))))
251
- (fail 'unzip1:1))
252
-
253
- (or (let-values (((a b) (unzip2 '((10 11) (20 21) (30 31)))))
254
- (and (equal? a '(10 20 30))
255
- (equal? b '(11 21 31))))
256
- (fail 'unzip2:1))
257
-
258
- (or (let-values (((a b c) (unzip3 '((10 11 12) (20 21 22) (30 31 32)))))
259
- (and (equal? a '(10 20 30))
260
- (equal? b '(11 21 31))
261
- (equal? c '(12 22 32))))
262
- (fail 'unzip3:1))
263
-
264
- (or (let-values (((a b c d) (unzip4 '((10 11 12 13)
265
- (20 21 22 23)
266
- (30 31 32 33)))))
267
- (and (equal? a '(10 20 30))
268
- (equal? b '(11 21 31))
269
- (equal? c '(12 22 32))
270
- (equal? d '(13 23 33))))
271
- (fail 'unzip4:1))
272
-
273
- (or (let-values (((a b c d e) (unzip5 '((10 11 12 13 14)
274
- (20 21 22 23 24)
275
- (30 31 32 33 34)))))
276
- (and (equal? a '(10 20 30))
277
- (equal? b '(11 21 31))
278
- (equal? c '(12 22 32))
279
- (equal? d '(13 23 33))
280
- (equal? e '(14 24 34))))
281
- (fail 'unzip5:1))
282
-
283
- (or (equal? 3 (count even? '(3 1 4 1 5 9 2 5 6)))
284
- (fail 'count:1))
285
- (or (equal? 3 (count < '(1 2 4 8) '(2 4 6 8 10 12 14 16)))
286
- (fail 'count:2))
287
- (or (equal? 2 (count < '(3 1 4 1) (circular-list 1 10)))
288
- (fail 'count:3))
289
-
290
- (or (equal? '(c 3 b 2 a 1) (fold cons* '() '(a b c) '(1 2 3 4 5)))
291
- (fail 'fold:1))
292
-
293
- (or (equal? '(a 1 b 2 c 3) (fold-right cons* '() '(a b c) '(1 2 3 4 5)))
294
- (fail 'fold-right:1))
295
-
296
- (or (let* ((x (list 1 2 3))
297
- (r (list x (cdr x) (cddr x)))
298
- (y (pair-fold (lambda (pair tail)
299
- (set-cdr! pair tail) pair)
300
- '()
301
- x)))
302
- (and (equal? y '(3 2 1))
303
- (every (lambda (c) (memq c r)) (list y (cdr y) (cddr y)))))
304
- (fail 'pair-fold:1))
305
-
306
- (or (equal? '((a b c) (b c) (c)) (pair-fold-right cons '() '(a b c)))
307
- (fail 'pair-fold-right:1))
308
-
309
- (or (equal? 5 (reduce max 'illegal '(1 2 3 4 5)))
310
- (fail 'reduce:1))
311
- (or (equal? 0 (reduce max 0 '()))
312
- (fail 'reduce:2))
313
-
314
- (or (equal? '(1 2 3 4 5) (reduce-right append 'illegal '((1 2) () (3 4 5))))
315
- (fail 'reduce-right:1))
316
-
317
- (or (equal? '(1 4 9 16 25 36 49 64 81 100)
318
- (unfold (lambda (x) (> x 10))
319
- (lambda (x) (* x x))
320
- (lambda (x) (+ x 1))
321
- 1))
322
- (fail 'unfold:1))
323
-
324
- (or (equal? '(1 4 9 16 25 36 49 64 81 100)
325
- (unfold-right zero?
326
- (lambda (x) (* x x))
327
- (lambda (x) (- x 1))
328
- 10))
329
- (fail 'unfold-right:1))
330
-
331
- (or (equal? '(4 1 5 1)
332
- (map + '(3 1 4 1) (circular-list 1 0)))
333
- (fail 'map:1))
334
-
335
- (or (equal? 99990000
336
- (apply + (map (lambda (x) (* x 2)) (iota 10000))))
337
- (fail 'map:2))
338
-
339
- (or (equal? '(5 4 3 2 1)
340
- (let ((v 1)
341
- (l '()))
342
- (for-each (lambda (x y)
343
- (let ((n v))
344
- (set! v (+ v 1))
345
- (set! l (cons n l))))
346
- '(0 0 0 0 0)
347
- (circular-list 1 2))
348
- l))
349
- (fail 'for-each:1))
350
-
351
- (or (equal? 49995000
352
- (let1 total 0
353
- (for-each
354
- (lambda (x) (set! total (+ x total)))
355
- (iota 10000))
356
- total))
357
- (fail 'for-each:2))
358
-
359
- (or (equal? '(1 -1 3 -3 8 -8)
360
- (append-map (lambda (x) (list x (- x))) '(1 3 8)))
361
- (fail 'append-map:1))
362
-
363
- (or (equal? '(1 -1 3 -3 8 -8)
364
- (append-map! (lambda (x) (list x (- x))) '(1 3 8)))
365
- (fail 'append-map!:1))
366
-
367
- (or (let* ((l (list 1 2 3))
368
- (m (map! (lambda (x) (* x x)) l)))
369
- (and (equal? m '(1 4 9))
370
- (equal? l '(1 4 9))))
371
- (fail 'map!:1))
372
-
373
- (or (equal? '(1 2 3 4 5)
374
- (let ((v 1))
375
- (map-in-order (lambda (x)
376
- (let ((n v))
377
- (set! v (+ v 1))
378
- n))
379
- '(0 0 0 0 0))))
380
- (fail 'map-in-order:1))
381
-
382
- (or (equal? '((3) (2 3) (1 2 3))
383
- (let ((xs (list 1 2 3))
384
- (l '()))
385
- (pair-for-each (lambda (x) (set! l (cons x l))) xs)
386
- l))
387
- (fail 'pair-for-each:1))
388
-
389
- (or (equal? '(1 9 49)
390
- (filter-map (lambda (x y) (and (number? x) (* x x)))
391
- '(a 1 b 3 c 7)
392
- (circular-list 1 2)))
393
- (fail 'filter-map:1))
394
-
395
- (or (equal? '(0 -1 -2 -3 -4 -5 -6 -7 -8 -9)
396
- (filter-map (lambda (x) (when (< x 10) (- x))) (iota 1000)))
397
- (fail 'filter-map:2))
398
-
399
- (or (equal? 10000
400
- (length (filter-map (lambda (x) x) (iota 10000))))
401
- (fail 'filter-map:3))
402
-
403
- (or (equal? '(0 8 8 -4) (filter even? '(0 7 8 8 43 -4)))
404
- (fail 'filter:1))
405
-
406
- (or (equal? '(0 1 2 3 4 5 6 7 8 9)
407
- (filter (lambda (x) (< x 10)) (range 1000)))
408
- (fail 'filter:2))
409
-
410
- (or (equal? 10000
411
- (length (filter (lambda (x) x) (iota 10000))))
412
- (fail 'filter:3))
413
-
414
- (or (let-values (((a b) (partition symbol? '(one 2 3 four five 6))))
415
- (and (equal? a '(one four five))
416
- (equal? b '(2 3 6))))
417
- (fail 'partition:1))
418
-
419
- (or (equal? '(7 43) (remove even? '(0 7 8 8 43 -4)))
420
- (fail 'remove:1))
421
-
422
- (or (let* ((x (list 0 7 8 8 43 -4))
423
- (y (pair-fold cons '() x))
424
- (r (filter! even? x)))
425
- (and (equal? '(0 8 8 -4) r)
426
- (every (lambda (c) (memq c y)) (pair-fold cons '() r))))
427
- (fail 'filter!:1))
428
-
429
- (or (let* ((x (list 'one 2 3 'four 'five 6))
430
- (y (pair-fold cons '() x)))
431
- (let-values (((a b) (partition! symbol? x)))
432
- (and (equal? a '(one four five))
433
- (equal? b '(2 3 6))
434
- (every (lambda (c) (memq c y)) (pair-fold cons '() a))
435
- (every (lambda (c) (memq c y)) (pair-fold cons '() b)))))
436
- (fail 'partition!:1))
437
-
438
- (or (let* ((x (list 0 7 8 8 43 -4))
439
- (y (pair-fold cons '() x))
440
- (r (remove! even? x)))
441
- (and (equal? '(7 43) r)
442
- (every (lambda (c) (memq c y)) (pair-fold cons '() r))))
443
- (fail 'remove!:1))
444
-
445
- (or (equal? 4 (find even? '(3 1 4 1 5 9 8)))
446
- (fail 'find:1))
447
-
448
- (or (equal? '(4 1 5 9 8) (find-tail even? '(3 1 4 1 5 9 8)))
449
- (fail 'find-tail:1))
450
- (or (equal? '#f (find-tail even? '(1 3 5 7)))
451
- (fail 'find-tail:2))
452
-
453
- (or (equal? '(2 18) (take-while even? '(2 18 3 10 22 9)))
454
- (fail 'take-while:1))
455
-
456
- (or (let* ((x (list 2 18 3 10 22 9))
457
- (r (take-while! even? x)))
458
- (and (equal? r '(2 18))
459
- (eq? r x)
460
- (eq? (cdr r) (cdr x))))
461
- (fail 'take-while!:1))
462
-
463
- (or (equal? '(3 10 22 9) (drop-while even? '(2 18 3 10 22 9)))
464
- (fail 'drop-while:1))
465
-
466
- (or (let-values (((a b) (span even? '(2 18 3 10 22 9))))
467
- (and (equal? a '(2 18))
468
- (equal? b '(3 10 22 9))))
469
- (fail 'span:1))
470
-
471
- (or (let-values (((a b) (break even? '(3 1 4 1 5 9))))
472
- (and (equal? a '(3 1))
473
- (equal? b '(4 1 5 9))))
474
- (fail 'break:1))
475
-
476
- (or (let* ((x (list 2 18 3 10 22 9))
477
- (cells (pair-fold cons '() x)))
478
- (let-values (((a b) (span! even? x)))
479
- (and (equal? a '(2 18))
480
- (equal? b '(3 10 22 9))
481
- (every (lambda (x) (memq x cells)) (pair-fold cons '() a))
482
- (every (lambda (x) (memq x cells)) (pair-fold cons '() b)))))
483
- (fail 'span!:1))
484
-
485
- (or (let* ((x (list 3 1 4 1 5 9))
486
- (cells (pair-fold cons '() x)))
487
- (let-values (((a b) (break! even? x)))
488
- (and (equal? a '(3 1))
489
- (equal? b '(4 1 5 9))
490
- (every (lambda (x) (memq x cells)) (pair-fold cons '() a))
491
- (every (lambda (x) (memq x cells)) (pair-fold cons '() b)))))
492
- (fail 'break!:1))
493
-
494
- (or (any integer? '(a 3 b 2.7))
495
- (fail 'any:1))
496
- (or (not (any integer? '(a 3.1 b 2.7)))
497
- (fail 'any:2))
498
- (or (any < '(3 1 4 1 5) (circular-list 2 7 1 8 2))
499
- (fail 'any:3))
500
- (or (equal? 'yes (any (lambda (a b) (if (< a b) 'yes #f))
501
- '(1 2 3) '(0 1 4)))
502
- (fail 'any:4))
503
-
504
- (or (every integer? '(1 2 3))
505
- (fail 'every:1))
506
- (or (not (every integer? '(3 4 5.1)))
507
- (fail 'every:2))
508
- (or (every < '(1 2 3) (circular-list 2 3 4))
509
- (fail 'every:3))
510
-
511
- (or (equal? 2 (list-index even? '(3 1 4 1 5 9)))
512
- (fail 'list-index:1))
513
- (or (equal? 1 (list-index < '(3 1 4 1 5 9 2 5 6) '(2 7 1 8 2)))
514
- (fail 'list-index:2))
515
- (or (not (list-index = '(3 1 4 1 5 9 2 5 6) '(2 7 1 8 2)))
516
- (fail 'list-index:3))
517
-
518
- (or (equal? '(37 48) (member 5 '(1 2 5 37 48) <))
519
- (fail 'member:1))
520
-
521
- (or (equal? '(1 2 5) (delete 5 '(1 48 2 5 37) <))
522
- (fail 'delete:1))
523
- (or (equal? '(1 2 7) (delete 5 '(1 5 2 5 7)))
524
- (fail 'delete:2))
525
-
526
- (or (let* ((x (list 1 48 2 5 37))
527
- (cells (pair-fold cons '() x))
528
- (r (delete! 5 x <)))
529
- (and (equal? r '(1 2 5))
530
- (every (lambda (x) (memq x cells)) (pair-fold cons '() r))))
531
- (fail 'delete!:1))
532
-
533
- (or (let* ((x (list 1 48 2 5 37))
534
- (cells (pair-fold cons '() x))
535
- (r (delete! 5 x >)))
536
- (and (equal? r '(48 5 37))
537
- (every (lambda (x) (memq x cells)) (pair-fold cons '() r))))
538
- (fail 'delete!:2))
539
-
540
- (or (equal? '((a . 3) (b . 7) (c . 1))
541
- (delete-duplicates '((a . 3) (b . 7) (a . 9) (c . 1))
542
- (lambda (x y) (eq? (car x) (car y)))))
543
- (fail 'delete-duplicates:1))
544
- (or (equal? '(a b c z) (delete-duplicates '(a b a c a b c z) eq?))
545
- (fail 'delete-duplicates:2))
546
-
547
- (or (let* ((x (list 'a 'b 'a 'c 'a 'b 'c 'z))
548
- (cells (pair-fold cons '() x))
549
- (r (delete-duplicates! x)))
550
- (and (equal? '(a b c z) r)
551
- (every (lambda (x) (memq x cells)) (pair-fold cons '() r))))
552
- (fail 'delete-duplicates!:1))
553
-
554
- (or (equal? '(3 . #t) (assoc 6
555
- '((4 . #t) (3 . #t) (5 . #t))
556
- (lambda (x y)
557
- (zero? (remainder x y)))))
558
- (fail 'assoc:1))
559
-
560
- (or (equal? '((1 . #t) (2 . #f)) (alist-cons 1 #t '((2 . #f))))
561
- (fail 'alist-cons:1))
562
-
563
- (or (let* ((a (list (cons 1 2) (cons 3 4)))
564
- (b (alist-copy a)))
565
- (and (equal? a b)
566
- (every (lambda (x) (not (memq x b))) a)
567
- (every (lambda (x) (not (memq x a))) b)))
568
- (fail 'alist-copy:1))
569
-
570
- (or (equal? '((1 . #t) (2 . #t) (4 . #t))
571
- (alist-delete 5 '((1 . #t) (2 . #t) (37 . #t) (4 . #t) (48 #t)) <))
572
- (fail 'alist-delete:1))
573
- (or (equal? '((1 . #t) (2 . #t) (4 . #t))
574
- (alist-delete 7 '((1 . #t) (2 . #t) (7 . #t) (4 . #t) (7 #t))))
575
- (fail 'alist-delete:2))
576
-
577
- (or (let* ((x (list-copy '((1 . #t) (2 . #t) (7 . #t) (4 . #t) (7 #t))))
578
- (y (list-copy x))
579
- (cells (pair-fold cons '() x))
580
- (r (alist-delete! 7 x)))
581
- (and (equal? r '((1 . #t) (2 . #t) (4 . #t)))
582
- (every (lambda (x) (memq x cells)) (pair-fold cons '() r))
583
- (every (lambda (x) (memq x y)) r)))
584
- (fail 'alist-delete!:1))
585
-
586
- (or (lset<= eq? '(a) '(a b a) '(a b c c))
587
- (fail 'lset<=:1))
588
- (or (not (lset<= eq? '(a) '(a b a) '(a)))
589
- (fail 'lset<=:2))
590
- (or (lset<= eq?)
591
- (fail 'lset<=:3))
592
- (or (lset<= eq? '(a))
593
- (fail 'lset<=:4))
594
-
595
- (or (lset= eq? '(b e a) '(a e b) '(e e b a))
596
- (fail 'lset=:1))
597
- (or (not (lset= eq? '(b e a) '(a e b) '(e e b a c)))
598
- (fail 'lset=:2))
599
- (or (lset= eq?)
600
- (fail 'lset=:3))
601
- (or (lset= eq? '(a))
602
- (fail 'lset=:4))
603
-
604
- (or (equal? '(u o i a b c d c e)
605
- (lset-adjoin eq? '(a b c d c e) 'a 'e 'i 'o 'u))
606
- (fail 'lset-adjoin:1))
607
-
608
- (or (equal? '(u o i a b c d e)
609
- (lset-union eq? '(a b c d e) '(a e i o u)))
610
- (fail 'lset-union:1))
611
- (or (equal? '(x a a c) (lset-union eq? '(a a c) '(x a x)))
612
- (fail 'lset-union:2))
613
- (or (null? (lset-union eq?))
614
- (fail 'lset-union:3))
615
- (or (equal? '(a b c) (lset-union eq? '(a b c)))
616
- (fail 'lset-union:4))
617
-
618
- (or (equal? '(a e) (lset-intersection eq? '(a b c d e) '(a e i o u)))
619
- (fail 'lset-intersection:1))
620
- (or (equal? '(a x a) (lset-intersection eq? '(a x y a) '(x a x z)))
621
- (fail 'lset-intersection:2))
622
- (or (equal? '(a b c) (lset-intersection eq? '(a b c)))
623
- (fail 'lset-intersection:3))
624
-
625
- (or (equal? '(b c d) (lset-difference eq? '(a b c d e) '(a e i o u)))
626
- (fail 'lset-difference:1))
627
- (or (equal? '(a b c) (lset-difference eq? '(a b c)))
628
- (fail 'lset-difference:2))
629
-
630
- (or (lset= eq? '(d c b i o u) (lset-xor eq? '(a b c d e) '(a e i o u)))
631
- (fail 'lset-xor:1))
632
- (or (lset= eq? '() (lset-xor eq?))
633
- (fail 'lset-xor:2))
634
- (or (lset= eq? '(a b c d e) (lset-xor eq? '(a b c d e)))
635
- (fail 'lset-xor:3))
636
-
637
- (or (let-values (((d i) (lset-diff+intersection eq? '(a b c d e) '(c d f))))
638
- (and (equal? d '(a b e))
639
- (equal? i '(c d))))
640
- (fail 'lset-diff+intersection:1))
641
-
642
- ; FIXME: For the following five procedures, need to check that cells
643
- ; returned are from the arguments.
644
-
645
- (or (equal? '(u o i a b c d e)
646
- (lset-union! eq? (list 'a 'b 'c 'd 'e) (list 'a 'e 'i 'o 'u)))
647
- (fail 'lset-union!:1))
648
- (or (equal? '(x a a c) (lset-union! eq? (list 'a 'a 'c) (list 'x 'a 'x)))
649
- (fail 'lset-union!:2))
650
- (or (null? (lset-union! eq?))
651
- (fail 'lset-union!:3))
652
- (or (equal? '(a b c) (lset-union! eq? (list 'a 'b 'c)))
653
- (fail 'lset-union!:4))
654
-
655
- (or (equal? '(a e) (lset-intersection! eq? (list 'a 'b 'c 'd 'e)
656
- (list 'a 'e 'i 'o 'u)))
657
- (fail 'lset-intersection!:1))
658
- (or (equal? '(a x a) (lset-intersection! eq? (list 'a 'x 'y 'a)
659
- (list 'x 'a 'x 'z)))
660
- (fail 'lset-intersection!:2))
661
- (or (equal? '(a b c) (lset-intersection! eq? (list 'a 'b 'c)))
662
- (fail 'lset-intersection!:3))
663
-
664
- (or (equal? '(b c d) (lset-difference! eq? (list 'a 'b 'c 'd 'e)
665
- (list 'a 'e 'i 'o 'u)))
666
- (fail 'lset-difference!:1))
667
- (or (equal? '(a b c) (lset-difference! eq? (list 'a 'b 'c)))
668
- (fail 'lset-difference!:2))
669
-
670
- (or (lset= eq? '(d c b i o u) (lset-xor! eq? (list 'a 'b 'c 'd 'e)
671
- (list 'a 'e 'i 'o 'u)))
672
- (fail 'lset-xor!:1))
673
- (or (lset= eq? '() (lset-xor! eq?))
674
- (fail 'lset-xor!:2))
675
- (or (lset= eq? '(a b c d e) (lset-xor! eq? (list 'a 'b 'c 'd 'e)))
676
- (fail 'lset-xor!:3))
677
-
678
- (or (let-values (((d i) (lset-diff+intersection! eq? (list 'a 'b 'c 'd 'e)
679
- (list 'c 'd 'f))))
680
- (and (equal? d '(a b e))
681
- (equal? i '(c d))))
682
- (fail 'lset-diff+intersection!:1))
683
-
684
- (writeln "Done.")