1 ;;;; srfi-1.test --- Test suite for Guile's SRFI-1 functions. -*- scheme -*-
3 ;;;; Copyright 2003, 2004, 2005 Free Software Foundation, Inc.
5 ;;;; This program is free software; you can redistribute it and/or modify
6 ;;;; it under the terms of the GNU General Public License as published by
7 ;;;; the Free Software Foundation; either version 2, or (at your option)
8 ;;;; any later version.
10 ;;;; This program is distributed in the hope that it will be useful,
11 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;;;; GNU General Public License for more details.
15 ;;;; You should have received a copy of the GNU General Public License
16 ;;;; along with this software; see the file COPYING. If not, write to
17 ;;;; the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 ;;;; Boston, MA 02111-1307 USA
20 (use-modules (srfi srfi-1)
23 (define (ref-delete x lst . proc)
24 "Reference implemenation of srfi-1 `delete'."
25 (set! proc (if (null? proc) equal? (car proc)))
30 (if (not (proc x (car lst)))
31 (set! ret (cons (car lst) ret)))))
33 (define (ref-delete-duplicates lst . proc)
34 "Reference implemenation of srfi-1 `delete-duplicates'."
35 (set! proc (if (null? proc) equal? (car proc)))
41 (let ((elem (car lst)))
42 (set! keep (cons elem keep))
43 (set! lst (ref-delete elem lst proc))))))
50 (with-test-prefix "alist-copy"
52 ;; return a list which is the pairs making up alist A, the spine and cells
53 (define (alist-pairs a)
57 (more (cdr a) (cons a result))
60 ;; return a list of the elements common to lists X and Y, compared with eq?
61 (define (common-elements x y)
65 (cons (car x) (common-elements (cdr x) y))
66 (common-elements (cdr x) y))))
68 ;; validate an alist-copy of OLD to NEW
69 ;; lists must be equal, and must comprise new pairs
70 (define (valid-alist-copy? old new)
72 (null? (common-elements old new))))
74 (pass-if-exception "too few args" exception:wrong-num-args
77 (pass-if-exception "too many args" exception:wrong-num-args
81 (pass-if old (valid-alist-copy? old (alist-copy old))))
83 (let ((old '((1 . 2))))
84 (pass-if old (valid-alist-copy? old (alist-copy old))))
86 (let ((old '((1 . 2) (3 . 4))))
87 (pass-if old (valid-alist-copy? old (alist-copy old))))
89 (let ((old '((1 . 2) (3 . 4) (5 . 6))))
90 (pass-if old (valid-alist-copy? old (alist-copy old)))))
96 (with-test-prefix "alist-delete"
98 (pass-if "equality call arg order"
100 (alist-delete 'k '((ak . 123))
102 (if (and (eq? k 'k) (eq? ak 'ak))
106 (pass-if "delete keys greater than 5"
107 (equal? '((4 . x) (5 . y))
108 (alist-delete 5 '((4 . x) (5 . y) (6 . z)) <)))
111 (equal? '() (alist-delete 'x '())))
114 (equal? '() (alist-delete 'y '((y . 1)))))
117 (equal? '((n . 1)) (alist-delete 'y '((n . 1)))))
120 (equal? '() (alist-delete 'y '((y . 1) (y . 2)))))
123 (equal? '((n . 1)) (alist-delete 'y '((n . 1) (y . 2)))))
126 (equal? '((n . 2)) (alist-delete 'y '((y . 1) (n . 2)))))
129 (equal? '((n . 1) (n . 2)) (alist-delete 'y '((n . 1) (n . 2)))))
132 (equal? '() (alist-delete 'y '((y . 1) (y . 2) (y . 3)))))
135 (equal? '((n . 1)) (alist-delete 'y '((n . 1) (y . 2) (y . 3)))))
138 (equal? '((n . 2)) (alist-delete 'y '((y . 1) (n . 2) (y . 3)))))
141 (equal? '((n . 1) (n . 2)) (alist-delete 'y '((n . 1) (n . 2) (y . 3)))))
144 (equal? '( (n . 3)) (alist-delete 'y '((y . 1) (y . 2) (n . 3)))))
147 (equal? '((n . 1) (n . 3)) (alist-delete 'y '((n . 1) (y . 2) (n . 3)))))
150 (equal? '((n . 2) (n . 3)) (alist-delete 'y '((y . 1) (n . 2) (n . 3)))))
153 (equal? '((n . 1) (n . 2) (n . 3)) (alist-delete 'y '((n . 1) (n . 2) (n . 3))))))
159 (with-test-prefix "append-map"
161 (with-test-prefix "one list"
164 (equal? '() (append-map noop '(()))))
167 (equal? '(1) (append-map noop '((1)))))
170 (equal? '(1 2) (append-map noop '((1 2)))))
173 (equal? '() (append-map noop '(() ()))))
176 (equal? '(1) (append-map noop '(() (1)))))
179 (equal? '(1 2) (append-map noop '(() (1 2)))))
182 (equal? '(1 2) (append-map noop '((1) (2)))))
185 (equal? '(1 2) (append-map noop '(() (1 2))))))
187 (with-test-prefix "two lists"
190 (equal? '() (append-map noop '(()) '(9))))
193 (equal? '(1) (append-map noop '((1)) '(9))))
195 (pass-if "() () / 9 9"
196 (equal? '() (append-map noop '(() ()) '(9 9))))
198 (pass-if "(1) (2) / 9"
199 (equal? '(1) (append-map noop '((1) (2)) '(9))))
201 (pass-if "(1) (2) / 9 9"
202 (equal? '(1 2) (append-map noop '((1) (2)) '(9 9))))))
208 (with-test-prefix "break"
210 (define (test-break lst want-v1 want-v2)
213 (break negative? lst))
214 (lambda (got-v1 got-v2)
215 (and (equal? got-v1 want-v1)
216 (equal? got-v2 want-v2)))))
219 (test-break '() '() '()))
222 (test-break '(1) '(1) '()))
225 (test-break '(-1) '() '(-1)))
228 (test-break '(1 2) '(1 2) '()))
231 (test-break '(-1 1) '() '(-1 1)))
234 (test-break '(1 -1) '(1) '(-1)))
237 (test-break '(-1 -2) '() '(-1 -2)))
240 (test-break '(1 2 3) '(1 2 3) '()))
243 (test-break '(-1 1 2) '() '(-1 1 2)))
246 (test-break '(1 -1 2) '(1) '(-1 2)))
249 (test-break '(-1 -2 1) '() '(-1 -2 1)))
252 (test-break '(1 2 -1) '(1 2) '(-1)))
255 (test-break '(-1 1 -2) '() '(-1 1 -2)))
258 (test-break '(1 -1 -2) '(1) '(-1 -2)))
261 (test-break '(-1 -2 -3) '() '(-1 -2 -3))))
267 (with-test-prefix "break!"
269 (define (test-break! lst want-v1 want-v2)
272 (break! negative? lst))
273 (lambda (got-v1 got-v2)
274 (and (equal? got-v1 want-v1)
275 (equal? got-v2 want-v2)))))
278 (test-break! '() '() '()))
281 (test-break! (list 1) '(1) '()))
284 (test-break! (list -1) '() '(-1)))
287 (test-break! (list 1 2) '(1 2) '()))
290 (test-break! (list -1 1) '() '(-1 1)))
293 (test-break! (list 1 -1) '(1) '(-1)))
296 (test-break! (list -1 -2) '() '(-1 -2)))
299 (test-break! (list 1 2 3) '(1 2 3) '()))
302 (test-break! (list -1 1 2) '() '(-1 1 2)))
305 (test-break! (list 1 -1 2) '(1) '(-1 2)))
308 (test-break! (list -1 -2 1) '() '(-1 -2 1)))
311 (test-break! (list 1 2 -1) '(1 2) '(-1)))
314 (test-break! (list -1 1 -2) '() '(-1 1 -2)))
317 (test-break! (list 1 -1 -2) '(1) '(-1 -2)))
320 (test-break! (list -1 -2 -3) '() '(-1 -2 -3))))
323 ;; concatenate and concatenate!
327 (define (common-tests concatenate-proc unmodified?)
328 (define (try lstlst want)
329 (let ((lstlst-copy (copy-tree lstlst))
330 (got (concatenate-proc lstlst)))
332 (if (not (equal? lstlst lstlst-copy))
333 (error "input lists modified")))
336 (pass-if-exception "too few args" exception:wrong-num-args
339 (pass-if-exception "too many args" exception:wrong-num-args
340 (concatenate-proc '() '()))
342 (pass-if-exception "number" exception:wrong-type-arg
343 (concatenate-proc 123))
345 (pass-if-exception "vector" exception:wrong-type-arg
346 (concatenate-proc #(1 2 3)))
351 (pass-if (try '((1)) '(1)))
352 (pass-if (try '((1 2)) '(1 2)))
353 (pass-if (try '(() (1)) '(1)))
354 (pass-if (try '(() () (1)) '(1)))
356 (pass-if (try '((1) (2)) '(1 2)))
357 (pass-if (try '(() (1 2)) '(1 2)))
359 (pass-if (try '((1) 2) '(1 . 2)))
360 (pass-if (try '((1) (2) 3) '(1 2 . 3)))
361 (pass-if (try '((1) (2) (3 . 4)) '(1 2 3 . 4)))
364 (with-test-prefix "concatenate"
365 (common-tests concatenate #t))
367 (with-test-prefix "concatenate!"
368 (common-tests concatenate! #f)))
374 (with-test-prefix "count"
375 (pass-if-exception "no args" exception:wrong-num-args
378 (pass-if-exception "one arg" exception:wrong-num-args
381 (with-test-prefix "one list"
385 (pass-if "empty list" (= 0 (count or1 '())))
387 (pass-if-exception "pred arg count 0" exception:wrong-type-arg
388 (count (lambda () x) '(1 2 3)))
389 (pass-if-exception "pred arg count 2" exception:wrong-type-arg
390 (count (lambda (x y) x) '(1 2 3)))
392 (pass-if-exception "improper 1" exception:wrong-type-arg
394 (pass-if-exception "improper 2" exception:wrong-type-arg
395 (count or1 '(1 . 2)))
396 (pass-if-exception "improper 3" exception:wrong-type-arg
397 (count or1 '(1 2 . 3)))
399 (pass-if (= 0 (count or1 '(#f))))
400 (pass-if (= 1 (count or1 '(#t))))
402 (pass-if (= 0 (count or1 '(#f #f))))
403 (pass-if (= 1 (count or1 '(#f #t))))
404 (pass-if (= 1 (count or1 '(#t #f))))
405 (pass-if (= 2 (count or1 '(#t #t))))
407 (pass-if (= 0 (count or1 '(#f #f #f))))
408 (pass-if (= 1 (count or1 '(#f #f #t))))
409 (pass-if (= 1 (count or1 '(#t #f #f))))
410 (pass-if (= 2 (count or1 '(#t #f #t))))
411 (pass-if (= 3 (count or1 '(#t #t #t)))))
413 (with-test-prefix "two lists"
418 (= 1 (count (lambda (x y)
423 (pass-if "empty lists" (= 0 (count or2 '() '())))
425 (pass-if-exception "pred arg count 0" exception:wrong-type-arg
426 (count (lambda () #t) '(1 2 3) '(1 2 3)))
427 (pass-if-exception "pred arg count 1" exception:wrong-type-arg
428 (count (lambda (x) x) '(1 2 3) '(1 2 3)))
429 (pass-if-exception "pred arg count 3" exception:wrong-type-arg
430 (count (lambda (x y z) x) '(1 2 3) '(1 2 3)))
432 (pass-if-exception "improper first 1" exception:wrong-type-arg
433 (count or2 1 '(1 2 3)))
434 (pass-if-exception "improper first 2" exception:wrong-type-arg
435 (count or2 '(1 . 2) '(1 2 3)))
436 (pass-if-exception "improper first 3" exception:wrong-type-arg
437 (count or2 '(1 2 . 3) '(1 2 3)))
439 (pass-if-exception "improper second 1" exception:wrong-type-arg
440 (count or2 '(1 2 3) 1))
441 (pass-if-exception "improper second 2" exception:wrong-type-arg
442 (count or2 '(1 2 3) '(1 . 2)))
443 (pass-if-exception "improper second 3" exception:wrong-type-arg
444 (count or2 '(1 2 3) '(1 2 . 3)))
446 (pass-if (= 0 (count or2 '(#f) '(#f))))
447 (pass-if (= 1 (count or2 '(#t) '(#f))))
448 (pass-if (= 1 (count or2 '(#f) '(#t))))
450 (pass-if (= 0 (count or2 '(#f #f) '(#f #f))))
451 (pass-if (= 1 (count or2 '(#t #f) '(#t #f))))
452 (pass-if (= 2 (count or2 '(#t #t) '(#f #f))))
453 (pass-if (= 2 (count or2 '(#t #f) '(#f #t))))
455 (with-test-prefix "stop shortest"
456 (pass-if (= 2 (count or2 '(#t #f #t) '(#f #t))))
457 (pass-if (= 2 (count or2 '(#t #f #t #t) '(#f #t))))
458 (pass-if (= 2 (count or2 '(#t #f) '(#f #t #t))))
459 (pass-if (= 2 (count or2 '(#t #f) '(#f #t #t #t))))))
461 (with-test-prefix "three lists"
466 (= 1 (count (lambda (x y z)
472 (pass-if "empty lists" (= 0 (count or3 '() '() '())))
474 ;; currently bad pred argument gives wrong-num-args when 3 or more
475 ;; lists, as opposed to wrong-type-arg for 1 or 2 lists
476 (pass-if-exception "pred arg count 0" exception:wrong-num-args
477 (count (lambda () #t) '(1 2 3) '(1 2 3) '(1 2 3)))
478 (pass-if-exception "pred arg count 2" exception:wrong-num-args
479 (count (lambda (x y) x) '(1 2 3) '(1 2 3)'(1 2 3) ))
480 (pass-if-exception "pred arg count 4" exception:wrong-num-args
481 (count (lambda (w x y z) x) '(1 2 3) '(1 2 3) '(1 2 3)))
483 (pass-if-exception "improper first 1" exception:wrong-type-arg
484 (count or3 1 '(1 2 3) '(1 2 3)))
485 (pass-if-exception "improper first 2" exception:wrong-type-arg
486 (count or3 '(1 . 2) '(1 2 3) '(1 2 3)))
487 (pass-if-exception "improper first 3" exception:wrong-type-arg
488 (count or3 '(1 2 . 3) '(1 2 3) '(1 2 3)))
490 (pass-if-exception "improper second 1" exception:wrong-type-arg
491 (count or3 '(1 2 3) 1 '(1 2 3)))
492 (pass-if-exception "improper second 2" exception:wrong-type-arg
493 (count or3 '(1 2 3) '(1 . 2) '(1 2 3)))
494 (pass-if-exception "improper second 3" exception:wrong-type-arg
495 (count or3 '(1 2 3) '(1 2 . 3) '(1 2 3)))
497 (pass-if-exception "improper third 1" exception:wrong-type-arg
498 (count or3 '(1 2 3) '(1 2 3) 1))
499 (pass-if-exception "improper third 2" exception:wrong-type-arg
500 (count or3 '(1 2 3) '(1 2 3) '(1 . 2)))
501 (pass-if-exception "improper third 3" exception:wrong-type-arg
502 (count or3 '(1 2 3) '(1 2 3) '(1 2 . 3)))
504 (pass-if (= 0 (count or3 '(#f) '(#f) '(#f))))
505 (pass-if (= 1 (count or3 '(#t) '(#f) '(#f))))
506 (pass-if (= 1 (count or3 '(#f) '(#t) '(#f))))
507 (pass-if (= 1 (count or3 '(#f) '(#f) '(#t))))
509 (pass-if (= 0 (count or3 '(#f #f) '(#f #f) '(#f #f))))
511 (pass-if (= 1 (count or3 '(#t #f) '(#f #f) '(#f #f))))
512 (pass-if (= 1 (count or3 '(#f #t) '(#f #f) '(#f #f))))
513 (pass-if (= 1 (count or3 '(#f #f) '(#t #f) '(#f #f))))
514 (pass-if (= 1 (count or3 '(#f #f) '(#f #t) '(#f #f))))
515 (pass-if (= 1 (count or3 '(#f #f) '(#f #f) '(#t #f))))
516 (pass-if (= 1 (count or3 '(#f #f) '(#f #f) '(#f #t))))
518 (pass-if (= 2 (count or3 '(#t #t) '(#f #f) '(#f #f))))
519 (pass-if (= 2 (count or3 '(#f #f) '(#t #t) '(#f #f))))
520 (pass-if (= 2 (count or3 '(#f #f) '(#f #f) '(#t #t))))
521 (pass-if (= 2 (count or3 '(#f #f) '(#t #f) '(#f #t))))
523 (with-test-prefix "stop shortest"
524 (pass-if (= 0 (count or3 '() '(#t #t #t) '(#t #t))))
525 (pass-if (= 0 (count or3 '(#t #t #t) '() '(#t #t))))
526 (pass-if (= 0 (count or3 '(#t #t #t) '(#t #t) '())))
528 (pass-if (= 1 (count or3 '(#t) '(#t #t #t) '(#t #t))))
529 (pass-if (= 1 (count or3 '(#t #t #t) '(#t) '(#t #t))))
530 (pass-if (= 1 (count or3 '(#t #t #t) '(#t #t) '(#t)))))
532 (pass-if "apply list unchanged"
533 (let ((lst (list (list 1 2) (list 3 4) (list 5 6))))
534 (and (equal? 2 (apply count or3 lst))
536 (equal? '((1 2) (3 4) (5 6)) lst))))))
539 ;; delete and delete!
543 ;; Call (PROC lst) for all lists of length up to 6, with all combinations
544 ;; of elements to be retained or deleted. Elements to retain are numbers,
545 ;; 0 upwards. Elements to be deleted are #f.
546 (define (test-lists proc)
549 (do ((limit (ash 1 n))
553 (do ((bit 0 (1+ bit)))
555 (set! lst (cons (if (logbit? bit i) bit #f) lst)))
558 (define (common-tests delete-proc)
559 (pass-if-exception "too few args" exception:wrong-num-args
562 (pass-if-exception "too many args" exception:wrong-num-args
563 (delete-proc 0 '() equal? 99))
566 (eq? '() (delete-proc 0 '())))
568 (pass-if "equal? (the default)"
570 (delete-proc '(2) '((1) (2) (3)))))
573 (equal? '((1) (2) (3))
574 (delete-proc '(2) '((1) (2) (3)) eq?)))
576 (pass-if "called arg order"
578 (delete-proc 3 '(1 2 3 4 5) <))))
580 (with-test-prefix "delete"
581 (common-tests delete)
585 (let ((lst-copy (list-copy lst)))
586 (with-test-prefix lst-copy
588 (equal? (delete #f lst)
589 (ref-delete #f lst)))
590 (pass-if "non-destructive"
591 (equal? lst-copy lst)))))))
593 (with-test-prefix "delete!"
594 (common-tests delete!)
599 (equal? (delete! #f lst)
600 (ref-delete #f lst)))))))
603 ;; delete-duplicates and delete-duplicates!
607 ;; Call (PROC lst) for all lists of length 1 <= n <= 4, with all
608 ;; combinations of numbers 1 to n in the elements
609 (define (test-lists proc)
612 (do ((limit (integer-expt n n))
617 (rem i (quotient rem n)))
619 (set! lst (cons (remainder rem n) lst)))
622 (define (common-tests delete-duplicates-proc)
623 (pass-if-exception "too few args" exception:wrong-num-args
624 (delete-duplicates-proc))
626 (pass-if-exception "too many args" exception:wrong-num-args
627 (delete-duplicates-proc '() equal? 99))
630 (eq? '() (delete-duplicates-proc '())))
632 (pass-if "equal? (the default)"
634 (delete-duplicates-proc '((2) (2) (2)))))
637 (equal? '((2) (2) (2))
638 (delete-duplicates-proc '((2) (2) (2)) eq?)))
640 (pass-if "called arg order"
642 (delete-duplicates-proc '(1 2 3 4 5)
649 (with-test-prefix "delete-duplicates"
650 (common-tests delete-duplicates)
654 (let ((lst-copy (list-copy lst)))
655 (with-test-prefix lst-copy
657 (equal? (delete-duplicates lst)
658 (ref-delete-duplicates lst)))
659 (pass-if "non-destructive"
660 (equal? lst-copy lst)))))))
662 (with-test-prefix "delete-duplicates!"
663 (common-tests delete-duplicates!)
668 (equal? (delete-duplicates! lst)
669 (ref-delete-duplicates lst)))))))
675 (with-test-prefix "drop"
678 (null? (drop '() 0)))
705 (pass-if "'(a b c) 1"
706 (let ((lst '(a b c)))
710 (pass-if "circular '(a) 0"
711 (let ((lst (circular-list 'a)))
715 (pass-if "circular '(a) 1"
716 (let ((lst (circular-list 'a)))
720 (pass-if "circular '(a) 2"
721 (let ((lst (circular-list 'a)))
725 (pass-if "circular '(a b) 1"
726 (let ((lst (circular-list 'a)))
730 (pass-if "circular '(a b) 2"
731 (let ((lst (circular-list 'a)))
735 (pass-if "circular '(a b) 5"
736 (let ((lst (circular-list 'a)))
740 (pass-if "'(a . b) 1"
744 (pass-if "'(a b . c) 1"
746 (drop '(a b . c) 2))))
752 (with-test-prefix "drop-right"
754 (pass-if-exception "() -1" exception:out-of-range
756 (pass-if (equal? '() (drop-right '() 0)))
757 (pass-if-exception "() 1" exception:wrong-type-arg
760 (pass-if-exception "(1) -1" exception:out-of-range
761 (drop-right '(1) -1))
762 (pass-if (equal? '(1) (drop-right '(1) 0)))
763 (pass-if (equal? '() (drop-right '(1) 1)))
764 (pass-if-exception "(1) 2" exception:wrong-type-arg
767 (pass-if-exception "(4 5) -1" exception:out-of-range
768 (drop-right '(4 5) -1))
769 (pass-if (equal? '(4 5) (drop-right '(4 5) 0)))
770 (pass-if (equal? '(4) (drop-right '(4 5) 1)))
771 (pass-if (equal? '() (drop-right '(4 5) 2)))
772 (pass-if-exception "(4 5) 3" exception:wrong-type-arg
773 (drop-right '(4 5) 3))
775 (pass-if-exception "(4 5 6) -1" exception:out-of-range
776 (drop-right '(4 5 6) -1))
777 (pass-if (equal? '(4 5 6) (drop-right '(4 5 6) 0)))
778 (pass-if (equal? '(4 5) (drop-right '(4 5 6) 1)))
779 (pass-if (equal? '(4) (drop-right '(4 5 6) 2)))
780 (pass-if (equal? '() (drop-right '(4 5 6) 3)))
781 (pass-if-exception "(4 5 6) 4" exception:wrong-type-arg
782 (drop-right '(4 5 6) 4)))
788 (with-test-prefix "drop-right!"
790 (pass-if-exception "() -1" exception:out-of-range
791 (drop-right! '() -1))
792 (pass-if (equal? '() (drop-right! '() 0)))
793 (pass-if-exception "() 1" exception:wrong-type-arg
796 (pass-if-exception "(1) -1" exception:out-of-range
797 (drop-right! (list 1) -1))
798 (pass-if (equal? '(1) (drop-right! (list 1) 0)))
799 (pass-if (equal? '() (drop-right! (list 1) 1)))
800 (pass-if-exception "(1) 2" exception:wrong-type-arg
801 (drop-right! (list 1) 2))
803 (pass-if-exception "(4 5) -1" exception:out-of-range
804 (drop-right! (list 4 5) -1))
805 (pass-if (equal? '(4 5) (drop-right! (list 4 5) 0)))
806 (pass-if (equal? '(4) (drop-right! (list 4 5) 1)))
807 (pass-if (equal? '() (drop-right! (list 4 5) 2)))
808 (pass-if-exception "(4 5) 3" exception:wrong-type-arg
809 (drop-right! (list 4 5) 3))
811 (pass-if-exception "(4 5 6) -1" exception:out-of-range
812 (drop-right! (list 4 5 6) -1))
813 (pass-if (equal? '(4 5 6) (drop-right! (list 4 5 6) 0)))
814 (pass-if (equal? '(4 5) (drop-right! (list 4 5 6) 1)))
815 (pass-if (equal? '(4) (drop-right! (list 4 5 6) 2)))
816 (pass-if (equal? '() (drop-right! (list 4 5 6) 3)))
817 (pass-if-exception "(4 5 6) 4" exception:wrong-type-arg
818 (drop-right! (list 4 5 6) 4)))
824 (with-test-prefix "drop-while"
826 (pass-if (equal? '() (drop-while odd? '())))
827 (pass-if (equal? '() (drop-while odd? '(1))))
828 (pass-if (equal? '() (drop-while odd? '(1 3))))
829 (pass-if (equal? '() (drop-while odd? '(1 3 5))))
831 (pass-if (equal? '(2) (drop-while odd? '(2))))
832 (pass-if (equal? '(2) (drop-while odd? '(1 2))))
833 (pass-if (equal? '(4) (drop-while odd? '(1 3 4))))
835 (pass-if (equal? '(2 1) (drop-while odd? '(2 1))))
836 (pass-if (equal? '(4 3) (drop-while odd? '(1 4 3))))
837 (pass-if (equal? '(4 1 3) (drop-while odd? '(4 1 3)))))
843 (with-test-prefix "filter-map"
845 (with-test-prefix "one list"
846 (pass-if-exception "'x" exception:wrong-type-arg
847 (filter-map noop 'x))
849 (pass-if-exception "'(1 . x)" exception:wrong-type-arg
850 (filter-map noop '(1 . x)))
853 (equal? '(1) (filter-map noop '(1))))
856 (equal? '() (filter-map noop '(#f))))
859 (equal? '(1 2) (filter-map noop '(1 2))))
862 (equal? '(2) (filter-map noop '(#f 2))))
865 (equal? '() (filter-map noop '(#f #f))))
868 (equal? '(1 2 3) (filter-map noop '(1 2 3))))
871 (equal? '(2 3) (filter-map noop '(#f 2 3))))
874 (equal? '(1 3) (filter-map noop '(1 #f 3))))
877 (equal? '(1 2) (filter-map noop '(1 2 #f)))))
879 (with-test-prefix "two lists"
880 (pass-if-exception "'x '(1 2 3)" exception:wrong-type-arg
881 (filter-map noop 'x '(1 2 3)))
883 (pass-if-exception "'(1 2 3) 'x" exception:wrong-type-arg
884 (filter-map noop '(1 2 3) 'x))
886 (pass-if-exception "'(1 . x) '(1 2 3)" exception:wrong-type-arg
887 (filter-map noop '(1 . x) '(1 2 3)))
889 (pass-if-exception "'(1 2 3) '(1 . x)" exception:wrong-type-arg
890 (filter-map noop '(1 2 3) '(1 . x)))
892 (pass-if "(1 2 3) (4 5 6)"
893 (equal? '(5 7 9) (filter-map + '(1 2 3) '(4 5 6))))
895 (pass-if "(#f 2 3) (4 5)"
896 (equal? '(2) (filter-map noop '(#f 2 3) '(4 5))))
898 (pass-if "(4 #f) (1 2 3)"
899 (equal? '(4) (filter-map noop '(4 #f) '(1 2 3))))
901 (pass-if "() (1 2 3)"
902 (equal? '() (filter-map noop '() '(1 2 3))))
904 (pass-if "(1 2 3) ()"
905 (equal? '() (filter-map noop '(1 2 3) '()))))
907 (with-test-prefix "three lists"
908 (pass-if-exception "'x '(1 2 3) '(1 2 3)" exception:wrong-type-arg
909 (filter-map noop 'x '(1 2 3) '(1 2 3)))
911 (pass-if-exception "'(1 2 3) 'x '(1 2 3)" exception:wrong-type-arg
912 (filter-map noop '(1 2 3) 'x '(1 2 3)))
914 (pass-if-exception "'(1 2 3) '(1 2 3) 'x" exception:wrong-type-arg
915 (filter-map noop '(1 2 3) '(1 2 3) 'x))
917 (pass-if-exception "'(1 . x) '(1 2 3) '(1 2 3)" exception:wrong-type-arg
918 (filter-map noop '(1 . x) '(1 2 3) '(1 2 3)))
920 (pass-if-exception "'(1 2 3) '(1 . x) '(1 2 3)" exception:wrong-type-arg
921 (filter-map noop '(1 2 3) '(1 . x) '(1 2 3)))
923 (pass-if-exception "'(1 2 3) '(1 2 3) '(1 . x)" exception:wrong-type-arg
924 (filter-map noop '(1 2 3) '(1 2 3) '(1 . x)))
926 (pass-if "(1 2 3) (4 5 6) (7 8 9)"
927 (equal? '(12 15 18) (filter-map + '(1 2 3) '(4 5 6) '(7 8 9))))
929 (pass-if "(#f 2 3) (4 5) (7 8 9)"
930 (equal? '(2) (filter-map noop '(#f 2 3) '(4 5) '(7 8 9))))
932 (pass-if "(#f 2 3) (7 8 9) (4 5)"
933 (equal? '(2) (filter-map noop '(#f 2 3) '(7 8 9) '(4 5))))
935 (pass-if "(4 #f) (1 2 3) (7 8 9)"
936 (equal? '(4) (filter-map noop '(4 #f) '(1 2 3) '(7 8 9))))
938 (pass-if "apply list unchanged"
939 (let ((lst (list (list 1 #f 2) (list 3 4 5) (list 6 7 8))))
940 (and (equal? '(1 2) (apply filter-map noop lst))
942 (equal? lst '((1 #f 2) (3 4 5) (6 7 8))))))))
948 (with-test-prefix "find"
949 (pass-if (eqv? #f (find odd? '())))
950 (pass-if (eqv? #f (find odd? '(0))))
951 (pass-if (eqv? #f (find odd? '(0 2))))
952 (pass-if (eqv? 1 (find odd? '(1))))
953 (pass-if (eqv? 1 (find odd? '(0 1))))
954 (pass-if (eqv? 1 (find odd? '(0 1 2))))
955 (pass-if (eqv? 1 (find odd? '(2 0 1))))
956 (pass-if (eqv? 1 (find (lambda (x) (= 1 x)) '(2 0 1)))))
962 (with-test-prefix "find-tail"
963 (pass-if (let ((lst '()))
964 (eq? #f (find-tail odd? lst))))
965 (pass-if (let ((lst '(0)))
966 (eq? #f (find-tail odd? lst))))
967 (pass-if (let ((lst '(0 2)))
968 (eq? #f (find-tail odd? lst))))
969 (pass-if (let ((lst '(1)))
970 (eq? lst (find-tail odd? lst))))
971 (pass-if (let ((lst '(1 2)))
972 (eq? lst (find-tail odd? lst))))
973 (pass-if (let ((lst '(2 1)))
974 (eq? (cdr lst) (find-tail odd? lst))))
975 (pass-if (let ((lst '(2 1 0)))
976 (eq? (cdr lst) (find-tail odd? lst))))
977 (pass-if (let ((lst '(2 0 1)))
978 (eq? (cddr lst) (find-tail odd? lst))))
979 (pass-if (let ((lst '(2 0 1)))
980 (eq? (cddr lst) (find-tail (lambda (x) (= 1 x)) lst)))))
986 (with-test-prefix "length+"
987 (pass-if-exception "too few args" exception:wrong-num-args
989 (pass-if-exception "too many args" exception:wrong-num-args
991 (pass-if (= 0 (length+ '())))
992 (pass-if (= 1 (length+ '(x))))
993 (pass-if (= 2 (length+ '(x y))))
994 (pass-if (= 3 (length+ '(x y z))))
995 (pass-if (not (length+ (circular-list 1))))
996 (pass-if (not (length+ (circular-list 1 2))))
997 (pass-if (not (length+ (circular-list 1 2 3)))))
1003 (with-test-prefix "list="
1006 (eq? #t (list= eqv?)))
1008 (with-test-prefix "one list"
1011 (eq? #t (list= eqv? '())))
1013 (eq? #t (list= eqv? '(1))))
1014 (pass-if "two elems"
1015 (eq? #t (list= eqv? '(2)))))
1017 (with-test-prefix "two lists"
1019 (pass-if "empty / empty"
1020 (eq? #t (list= eqv? '() '())))
1022 (pass-if "one / empty"
1023 (eq? #f (list= eqv? '(1) '())))
1025 (pass-if "empty / one"
1026 (eq? #f (list= eqv? '() '(1))))
1028 (pass-if "one / one same"
1029 (eq? #t (list= eqv? '(1) '(1))))
1031 (pass-if "one / one diff"
1032 (eq? #f (list= eqv? '(1) '(2))))
1034 (pass-if "called arg order"
1036 (list= (lambda (x y)
1037 (set! good (and good (= (1+ x) y)))
1042 (with-test-prefix "three lists"
1044 (pass-if "empty / empty / empty"
1045 (eq? #t (list= eqv? '() '() '())))
1047 (pass-if "one / empty / empty"
1048 (eq? #f (list= eqv? '(1) '() '())))
1050 (pass-if "one / one / empty"
1051 (eq? #f (list= eqv? '(1) '(1) '())))
1053 (pass-if "one / diff / empty"
1054 (eq? #f (list= eqv? '(1) '(2) '())))
1056 (pass-if "one / one / one"
1057 (eq? #t (list= eqv? '(1) '(1) '(1))))
1059 (pass-if "two / two / diff"
1060 (eq? #f (list= eqv? '(1 2) '(1 2) '(1 99))))
1062 (pass-if "two / two / two"
1063 (eq? #t (list= eqv? '(1 2) '(1 2) '(1 2))))
1065 (pass-if "called arg order"
1067 (list= (lambda (x y)
1068 (set! good (and good (= (1+ x) y)))
1070 '(1 4) '(2 5) '(3 6))
1077 (with-test-prefix "list-copy"
1078 (pass-if (equal? '() (list-copy '())))
1079 (pass-if (equal? '(1 2) (list-copy '(1 2))))
1080 (pass-if (equal? '(1 2 3) (list-copy '(1 2 3))))
1081 (pass-if (equal? '(1 2 3 4) (list-copy '(1 2 3 4))))
1082 (pass-if (equal? '(1 2 3 4 5) (list-copy '(1 2 3 4 5))))
1084 ;; improper lists can be copied
1085 (pass-if (equal? 1 (list-copy 1)))
1086 (pass-if (equal? '(1 . 2) (list-copy '(1 . 2))))
1087 (pass-if (equal? '(1 2 . 3) (list-copy '(1 2 . 3))))
1088 (pass-if (equal? '(1 2 3 . 4) (list-copy '(1 2 3 . 4))))
1089 (pass-if (equal? '(1 2 3 4 . 5) (list-copy '(1 2 3 4 . 5)))))
1095 (with-test-prefix "lset="
1097 ;; in guile 1.6.7 and earlier, lset= incorrectly demanded at least one
1100 (eq? #t (lset= eq?)))
1102 (with-test-prefix "one arg"
1105 (eq? #t (lset= eqv? '())))
1108 (eq? #t (lset= eqv? '(1))))
1111 (eq? #t (lset= eqv? '(1 2)))))
1113 (with-test-prefix "two args"
1116 (eq? #t (lset= eqv? '() '())))
1119 (eq? #t (lset= eqv? '(1) '(1))))
1122 (eq? #f (lset= eqv? '(1) '(2))))
1124 (pass-if "(1) (1 2)"
1125 (eq? #f (lset= eqv? '(1) '(1 2))))
1127 (pass-if "(1 2) (2 1)"
1128 (eq? #t (lset= eqv? '(1 2) '(2 1))))
1130 (pass-if "called arg order"
1132 (lset= (lambda (x y)
1133 (if (not (= x (1- y)))
1139 (with-test-prefix "three args"
1142 (eq? #t (lset= eqv? '() '() '())))
1144 (pass-if "(1) (1) (1)"
1145 (eq? #t (lset= eqv? '(1) '(1) '(1))))
1147 (pass-if "(1) (1) (2)"
1148 (eq? #f (lset= eqv? '(1) '(1) '(2))))
1150 (pass-if "(1) (1) (1 2)"
1151 (eq? #f (lset= eqv? '(1) '(1) '(1 2))))
1153 (pass-if "(1 2 3) (3 2 1) (1 3 2)"
1154 (eq? #t (lset= eqv? '(1 2 3) '(3 2 1) '(1 3 2))))
1156 (pass-if "called arg order"
1158 (lset= (lambda (x y)
1159 (if (not (= x (1- y)))
1162 '(1 1) '(2 2) '(3 3))
1169 (with-test-prefix "lset-adjoin"
1171 ;; in guile 1.6.7 and earlier, lset-adjoin didn't actually use the given
1172 ;; `=' procedure, all comparisons were just with `equal?
1174 (with-test-prefix "case-insensitive ="
1176 (pass-if "(\"x\") \"X\""
1177 (equal? '("x") (lset-adjoin string-ci=? '("x") "X"))))
1179 (pass-if "called arg order"
1181 (lset-adjoin (lambda (x y)
1182 (set! good (and (= x 1) (= y 2)))
1187 (pass-if (equal? '() (lset-adjoin = '())))
1189 (pass-if (equal? '(1) (lset-adjoin = '() 1)))
1191 (pass-if (equal? '(1) (lset-adjoin = '() 1 1)))
1193 (pass-if (equal? '(2 1) (lset-adjoin = '() 1 2)))
1195 (pass-if (equal? '(3 1 2) (lset-adjoin = '(1 2) 1 2 3 2 1)))
1197 (pass-if "apply list unchanged"
1198 (let ((lst (list 1 2)))
1199 (and (equal? '(2 1 3) (apply lset-adjoin = '(3) lst))
1201 (equal? '(1 2) lst))))
1203 (pass-if "(1 1) 1 1"
1204 (equal? '(1 1) (lset-adjoin = '(1 1) 1 1)))
1206 ;; duplicates among args are cast out
1208 (equal? '(1 2) (lset-adjoin = '(2) 1 1))))
1214 (with-test-prefix "lset-union"
1217 (eq? '() (lset-union eq?)))
1220 (equal? '(1 2 3) (lset-union eq? '(1 2 3))))
1223 (equal? '() (lset-union eq? '() '())))
1225 (pass-if "'() '(1 2 3)"
1226 (equal? '(1 2 3) (lset-union eq? '() '(1 2 3))))
1228 (pass-if "'(1 2 3) '()"
1229 (equal? '(1 2 3) (lset-union eq? '(1 2 3) '())))
1231 (pass-if "'(1 2 3) '(4 3 5)"
1232 (equal? '(5 4 1 2 3) (lset-union eq? '(1 2 3) '(4 3 5))))
1234 (pass-if "'(1 2 3) '(4) '(3 5))"
1235 (equal? '(5 4 1 2 3) (lset-union eq? '(1 2 3) '(4) '(3 5))))
1237 ;; in guile 1.6.7 and earlier, `=' was called with the arguments the wrong
1239 (pass-if "called arg order"
1241 (lset-union (lambda (x y)
1242 (set! good (and (= x 1) (= y 2)))
1251 (with-test-prefix "member"
1253 (pass-if-exception "no args" exception:wrong-num-args
1256 (pass-if-exception "one arg" exception:wrong-num-args
1259 (pass-if "1 (1 2 3)"
1260 (let ((lst '(1 2 3)))
1261 (eq? lst (member 1 lst))))
1263 (pass-if "2 (1 2 3)"
1264 (let ((lst '(1 2 3)))
1265 (eq? (cdr lst) (member 2 lst))))
1267 (pass-if "3 (1 2 3)"
1268 (let ((lst '(1 2 3)))
1269 (eq? (cddr lst) (member 3 lst))))
1271 (pass-if "4 (1 2 3)"
1272 (let ((lst '(1 2 3)))
1273 (eq? #f (member 4 lst))))
1275 (pass-if "called arg order"
1277 (member 1 '(2) (lambda (x y)
1278 (set! good (and (eqv? 1 x)
1286 (with-test-prefix "take"
1289 (null? (take '() 0)))
1292 (null? (take '(a) 0)))
1295 (null? (take '() 0)))
1297 (pass-if "'(a b c) 0"
1298 (null? (take '() 0)))
1303 (and (equal? '(a) got)
1304 (not (eq? lst got)))))
1310 (pass-if "'(a b c) 1"
1317 (and (equal? '(a b) got)
1318 (not (eq? lst got)))))
1320 (pass-if "'(a b c) 2"
1324 (pass-if "circular '(a) 0"
1326 (take (circular-list 'a) 0)))
1328 (pass-if "circular '(a) 1"
1330 (take (circular-list 'a) 1)))
1332 (pass-if "circular '(a) 2"
1334 (take (circular-list 'a) 2)))
1336 (pass-if "circular '(a b) 5"
1337 (equal? '(a b a b a)
1338 (take (circular-list 'a 'b) 5)))
1340 (pass-if "'(a . b) 1"
1344 (pass-if "'(a b . c) 1"
1346 (take '(a b . c) 1)))
1348 (pass-if "'(a b . c) 2"
1350 (take '(a b . c) 2))))
1356 (with-test-prefix "take-while"
1358 (pass-if (equal? '() (take-while odd? '())))
1359 (pass-if (equal? '(1) (take-while odd? '(1))))
1360 (pass-if (equal? '(1 3) (take-while odd? '(1 3))))
1361 (pass-if (equal? '(1 3 5) (take-while odd? '(1 3 5))))
1363 (pass-if (equal? '() (take-while odd? '(2))))
1364 (pass-if (equal? '(1) (take-while odd? '(1 2))))
1365 (pass-if (equal? '(1 3) (take-while odd? '(1 3 4))))
1367 (pass-if (equal? '() (take-while odd? '(2 1))))
1368 (pass-if (equal? '(1) (take-while odd? '(1 4 3))))
1369 (pass-if (equal? '() (take-while odd? '(4 1 3)))))
1375 (with-test-prefix "take-while!"
1377 (pass-if (equal? '() (take-while! odd? '())))
1378 (pass-if (equal? '(1) (take-while! odd? (list 1))))
1379 (pass-if (equal? '(1 3) (take-while! odd? (list 1 3))))
1380 (pass-if (equal? '(1 3 5) (take-while! odd? (list 1 3 5))))
1382 (pass-if (equal? '() (take-while! odd? (list 2))))
1383 (pass-if (equal? '(1) (take-while! odd? (list 1 2))))
1384 (pass-if (equal? '(1 3) (take-while! odd? (list 1 3 4))))
1386 (pass-if (equal? '() (take-while! odd? (list 2 1))))
1387 (pass-if (equal? '(1) (take-while! odd? (list 1 4 3))))
1388 (pass-if (equal? '() (take-while! odd? (list 4 1 3)))))
1394 (define (test-partition pred list kept-good dropped-good)
1395 (call-with-values (lambda ()
1396 (partition pred list))
1397 (lambda (kept dropped)
1398 (and (equal? kept kept-good)
1399 (equal? dropped dropped-good)))))
1401 (with-test-prefix "partition"
1403 (pass-if "with dropped tail"
1404 (test-partition even? '(1 2 3 4 5 6 7)
1405 '(2 4 6) '(1 3 5 7)))
1407 (pass-if "with kept tail"
1408 (test-partition even? '(1 2 3 4 5 6)
1411 (pass-if "with everything dropped"
1412 (test-partition even? '(1 3 5 7)
1415 (pass-if "with everything kept"
1416 (test-partition even? '(2 4 6)
1419 (pass-if "with empty list"
1420 (test-partition even? '()
1423 (pass-if "with reasonably long list"
1424 ;; the old implementation from SRFI-1 reference implementation
1425 ;; would signal a stack-overflow for a list of only 500 elements!
1426 (call-with-values (lambda ()
1428 (make-list 10000 1)))
1430 (and (= (length odd) 10000)
1431 (= (length even) 0))))))
1437 (define (test-partition! pred list kept-good dropped-good)
1438 (call-with-values (lambda ()
1439 (partition! pred list))
1440 (lambda (kept dropped)
1441 (and (equal? kept kept-good)
1442 (equal? dropped dropped-good)))))
1444 (with-test-prefix "partition!"
1446 (pass-if "with dropped tail"
1447 (test-partition! even? (list 1 2 3 4 5 6 7)
1448 '(2 4 6) '(1 3 5 7)))
1450 (pass-if "with kept tail"
1451 (test-partition! even? (list 1 2 3 4 5 6)
1454 (pass-if "with everything dropped"
1455 (test-partition! even? (list 1 3 5 7)
1458 (pass-if "with everything kept"
1459 (test-partition! even? (list 2 4 6)
1462 (pass-if "with empty list"
1463 (test-partition! even? '()
1466 (pass-if "with reasonably long list"
1467 ;; the old implementation from SRFI-1 reference implementation
1468 ;; would signal a stack-overflow for a list of only 500 elements!
1469 (call-with-values (lambda ()
1471 (make-list 10000 1)))
1473 (and (= (length odd) 10000)
1474 (= (length even) 0))))))
1480 (with-test-prefix "reduce"
1484 (ret (reduce (lambda (x prev)
1485 (set! calls (cons (list x prev) calls))
1488 (and (equal? calls '())
1493 (ret (reduce (lambda (x prev)
1494 (set! calls (cons (list x prev) calls))
1497 (and (equal? calls '())
1500 (pass-if "two elems"
1502 (ret (reduce (lambda (x prev)
1503 (set! calls (cons (list x prev) calls))
1506 (and (equal? calls '((3 2)))
1509 (pass-if "three elems"
1511 (ret (reduce (lambda (x prev)
1512 (set! calls (cons (list x prev) calls))
1515 (and (equal? calls '((4 3)
1519 (pass-if "four elems"
1521 (ret (reduce (lambda (x prev)
1522 (set! calls (cons (list x prev) calls))
1525 (and (equal? calls '((5 4)
1534 (with-test-prefix "reduce-right"
1538 (ret (reduce-right (lambda (x prev)
1539 (set! calls (cons (list x prev) calls))
1542 (and (equal? calls '())
1547 (ret (reduce-right (lambda (x prev)
1548 (set! calls (cons (list x prev) calls))
1551 (and (equal? calls '())
1554 (pass-if "two elems"
1556 (ret (reduce-right (lambda (x prev)
1557 (set! calls (cons (list x prev) calls))
1560 (and (equal? calls '((2 3)))
1563 (pass-if "three elems"
1565 (ret (reduce-right (lambda (x prev)
1566 (set! calls (cons (list x prev) calls))
1569 (and (equal? calls '((2 3)
1573 (pass-if "four elems"
1575 (ret (reduce-right (lambda (x prev)
1576 (set! calls (cons (list x prev) calls))
1579 (and (equal? calls '((2 3)
1588 (with-test-prefix "remove"
1590 (pass-if (equal? '() (remove odd? '())))
1591 (pass-if (equal? '() (remove odd? '(1))))
1592 (pass-if (equal? '(2) (remove odd? '(2))))
1594 (pass-if (equal? '() (remove odd? '(1 3))))
1595 (pass-if (equal? '(2) (remove odd? '(2 3))))
1596 (pass-if (equal? '(2) (remove odd? '(1 2))))
1597 (pass-if (equal? '(2 4) (remove odd? '(2 4))))
1599 (pass-if (equal? '() (remove odd? '(1 3 5))))
1600 (pass-if (equal? '(2) (remove odd? '(2 3 5))))
1601 (pass-if (equal? '(2) (remove odd? '(1 2 5))))
1602 (pass-if (equal? '(2 4) (remove odd? '(2 4 5))))
1604 (pass-if (equal? '(6) (remove odd? '(1 3 6))))
1605 (pass-if (equal? '(2 6) (remove odd? '(2 3 6))))
1606 (pass-if (equal? '(2 6) (remove odd? '(1 2 6))))
1607 (pass-if (equal? '(2 4 6) (remove odd? '(2 4 6)))))
1613 (with-test-prefix "remove!"
1615 (pass-if (equal? '() (remove! odd? '())))
1616 (pass-if (equal? '() (remove! odd? (list 1))))
1617 (pass-if (equal? '(2) (remove! odd? (list 2))))
1619 (pass-if (equal? '() (remove! odd? (list 1 3))))
1620 (pass-if (equal? '(2) (remove! odd? (list 2 3))))
1621 (pass-if (equal? '(2) (remove! odd? (list 1 2))))
1622 (pass-if (equal? '(2 4) (remove! odd? (list 2 4))))
1624 (pass-if (equal? '() (remove! odd? (list 1 3 5))))
1625 (pass-if (equal? '(2) (remove! odd? (list 2 3 5))))
1626 (pass-if (equal? '(2) (remove! odd? (list 1 2 5))))
1627 (pass-if (equal? '(2 4) (remove! odd? (list 2 4 5))))
1629 (pass-if (equal? '(6) (remove! odd? (list 1 3 6))))
1630 (pass-if (equal? '(2 6) (remove! odd? (list 2 3 6))))
1631 (pass-if (equal? '(2 6) (remove! odd? (list 1 2 6))))
1632 (pass-if (equal? '(2 4 6) (remove! odd? (list 2 4 6)))))
1638 (with-test-prefix "split-at"
1640 (define (equal-values? lst thunk)
1641 (call-with-values thunk
1645 (pass-if-exception "() -1" exception:out-of-range
1647 (pass-if (equal-values? '(() ())
1648 (lambda () (split-at '() 0))))
1649 (pass-if-exception "() 1" exception:wrong-type-arg
1652 (pass-if-exception "(1) -1" exception:out-of-range
1654 (pass-if (equal-values? '(() (1)) (lambda () (split-at '(1) 0))))
1655 (pass-if (equal-values? '((1) ()) (lambda () (split-at '(1) 1))))
1656 (pass-if-exception "(1) 2" exception:wrong-type-arg
1659 (pass-if-exception "(4 5) -1" exception:out-of-range
1660 (split-at '(4 5) -1))
1661 (pass-if (equal-values? '(() (4 5)) (lambda () (split-at '(4 5) 0))))
1662 (pass-if (equal-values? '((4) (5)) (lambda () (split-at '(4 5) 1))))
1663 (pass-if (equal-values? '((4 5) ()) (lambda () (split-at '(4 5) 2))))
1664 (pass-if-exception "(4 5) 3" exception:wrong-type-arg
1665 (split-at '(4 5) 3))
1667 (pass-if-exception "(4 5 6) -1" exception:out-of-range
1668 (split-at '(4 5 6) -1))
1669 (pass-if (equal-values? '(() (4 5 6)) (lambda () (split-at '(4 5 6) 0))))
1670 (pass-if (equal-values? '((4) (5 6)) (lambda () (split-at '(4 5 6) 1))))
1671 (pass-if (equal-values? '((4 5) (6)) (lambda () (split-at '(4 5 6) 2))))
1672 (pass-if (equal-values? '((4 5 6) ()) (lambda () (split-at '(4 5 6) 3))))
1673 (pass-if-exception "(4 5 6) 4" exception:wrong-type-arg
1674 (split-at '(4 5 6) 4)))
1680 (with-test-prefix "split-at!"
1682 (define (equal-values? lst thunk)
1683 (call-with-values thunk
1687 (pass-if-exception "() -1" exception:out-of-range
1689 (pass-if (equal-values? '(() ())
1690 (lambda () (split-at! '() 0))))
1691 (pass-if-exception "() 1" exception:wrong-type-arg
1694 (pass-if-exception "(1) -1" exception:out-of-range
1695 (split-at! (list 1) -1))
1696 (pass-if (equal-values? '(() (1)) (lambda () (split-at! (list 1) 0))))
1697 (pass-if (equal-values? '((1) ()) (lambda () (split-at! (list 1) 1))))
1698 (pass-if-exception "(1) 2" exception:wrong-type-arg
1699 (split-at! (list 1) 2))
1701 (pass-if-exception "(4 5) -1" exception:out-of-range
1702 (split-at! (list 4 5) -1))
1703 (pass-if (equal-values? '(() (4 5)) (lambda () (split-at! (list 4 5) 0))))
1704 (pass-if (equal-values? '((4) (5)) (lambda () (split-at! (list 4 5) 1))))
1705 (pass-if (equal-values? '((4 5) ()) (lambda () (split-at! (list 4 5) 2))))
1706 (pass-if-exception "(4 5) 3" exception:wrong-type-arg
1707 (split-at! (list 4 5) 3))
1709 (pass-if-exception "(4 5 6) -1" exception:out-of-range
1710 (split-at! (list 4 5 6) -1))
1711 (pass-if (equal-values? '(() (4 5 6)) (lambda () (split-at! (list 4 5 6) 0))))
1712 (pass-if (equal-values? '((4) (5 6)) (lambda () (split-at! (list 4 5 6) 1))))
1713 (pass-if (equal-values? '((4 5) (6)) (lambda () (split-at! (list 4 5 6) 2))))
1714 (pass-if (equal-values? '((4 5 6) ()) (lambda () (split-at! (list 4 5 6) 3))))
1715 (pass-if-exception "(4 5 6) 4" exception:wrong-type-arg
1716 (split-at! (list 4 5 6) 4)))
1722 (with-test-prefix "span"
1724 (define (test-span lst want-v1 want-v2)
1727 (span positive? lst))
1728 (lambda (got-v1 got-v2)
1729 (and (equal? got-v1 want-v1)
1730 (equal? got-v2 want-v2)))))
1733 (test-span '() '() '()))
1736 (test-span '(1) '(1) '()))
1739 (test-span '(-1) '() '(-1)))
1742 (test-span '(1 2) '(1 2) '()))
1745 (test-span '(-1 1) '() '(-1 1)))
1748 (test-span '(1 -1) '(1) '(-1)))
1751 (test-span '(-1 -2) '() '(-1 -2)))
1754 (test-span '(1 2 3) '(1 2 3) '()))
1757 (test-span '(-1 1 2) '() '(-1 1 2)))
1760 (test-span '(1 -1 2) '(1) '(-1 2)))
1763 (test-span '(-1 -2 1) '() '(-1 -2 1)))
1766 (test-span '(1 2 -1) '(1 2) '(-1)))
1769 (test-span '(-1 1 -2) '() '(-1 1 -2)))
1772 (test-span '(1 -1 -2) '(1) '(-1 -2)))
1775 (test-span '(-1 -2 -3) '() '(-1 -2 -3))))
1781 (with-test-prefix "span!"
1783 (define (test-span! lst want-v1 want-v2)
1786 (span! positive? lst))
1787 (lambda (got-v1 got-v2)
1788 (and (equal? got-v1 want-v1)
1789 (equal? got-v2 want-v2)))))
1792 (test-span! '() '() '()))
1795 (test-span! (list 1) '(1) '()))
1798 (test-span! (list -1) '() '(-1)))
1801 (test-span! (list 1 2) '(1 2) '()))
1804 (test-span! (list -1 1) '() '(-1 1)))
1807 (test-span! (list 1 -1) '(1) '(-1)))
1810 (test-span! (list -1 -2) '() '(-1 -2)))
1813 (test-span! (list 1 2 3) '(1 2 3) '()))
1816 (test-span! (list -1 1 2) '() '(-1 1 2)))
1819 (test-span! (list 1 -1 2) '(1) '(-1 2)))
1822 (test-span! (list -1 -2 1) '() '(-1 -2 1)))
1825 (test-span! (list 1 2 -1) '(1 2) '(-1)))
1828 (test-span! (list -1 1 -2) '() '(-1 1 -2)))
1831 (test-span! (list 1 -1 -2) '(1) '(-1 -2)))
1834 (test-span! (list -1 -2 -3) '() '(-1 -2 -3))))
1840 (with-test-prefix "take!"
1842 (pass-if-exception "() -1" exception:out-of-range
1844 (pass-if (equal? '() (take! '() 0)))
1845 (pass-if-exception "() 1" exception:wrong-type-arg
1848 (pass-if-exception "(1) -1" exception:out-of-range
1850 (pass-if (equal? '() (take! '(1) 0)))
1851 (pass-if (equal? '(1) (take! '(1) 1)))
1852 (pass-if-exception "(1) 2" exception:wrong-type-arg
1855 (pass-if-exception "(4 5) -1" exception:out-of-range
1857 (pass-if (equal? '() (take! '(4 5) 0)))
1858 (pass-if (equal? '(4) (take! '(4 5) 1)))
1859 (pass-if (equal? '(4 5) (take! '(4 5) 2)))
1860 (pass-if-exception "(4 5) 3" exception:wrong-type-arg
1863 (pass-if-exception "(4 5 6) -1" exception:out-of-range
1864 (take! '(4 5 6) -1))
1865 (pass-if (equal? '() (take! '(4 5 6) 0)))
1866 (pass-if (equal? '(4) (take! '(4 5 6) 1)))
1867 (pass-if (equal? '(4 5) (take! '(4 5 6) 2)))
1868 (pass-if (equal? '(4 5 6) (take! '(4 5 6) 3)))
1869 (pass-if-exception "(4 5 6) 4" exception:wrong-type-arg
1870 (take! '(4 5 6) 4)))
1877 (with-test-prefix "take-right"
1879 (pass-if-exception "() -1" exception:out-of-range
1880 (take-right '() -1))
1881 (pass-if (equal? '() (take-right '() 0)))
1882 (pass-if-exception "() 1" exception:wrong-type-arg
1885 (pass-if-exception "(1) -1" exception:out-of-range
1886 (take-right '(1) -1))
1887 (pass-if (equal? '() (take-right '(1) 0)))
1888 (pass-if (equal? '(1) (take-right '(1) 1)))
1889 (pass-if-exception "(1) 2" exception:wrong-type-arg
1890 (take-right '(1) 2))
1892 (pass-if-exception "(4 5) -1" exception:out-of-range
1893 (take-right '(4 5) -1))
1894 (pass-if (equal? '() (take-right '(4 5) 0)))
1895 (pass-if (equal? '(5) (take-right '(4 5) 1)))
1896 (pass-if (equal? '(4 5) (take-right '(4 5) 2)))
1897 (pass-if-exception "(4 5) 3" exception:wrong-type-arg
1898 (take-right '(4 5) 3))
1900 (pass-if-exception "(4 5 6) -1" exception:out-of-range
1901 (take-right '(4 5 6) -1))
1902 (pass-if (equal? '() (take-right '(4 5 6) 0)))
1903 (pass-if (equal? '(6) (take-right '(4 5 6) 1)))
1904 (pass-if (equal? '(5 6) (take-right '(4 5 6) 2)))
1905 (pass-if (equal? '(4 5 6) (take-right '(4 5 6) 3)))
1906 (pass-if-exception "(4 5 6) 4" exception:wrong-type-arg
1907 (take-right '(4 5 6) 4)))