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))))
326 (with-test-prefix "car+cdr"
337 ;; concatenate and concatenate!
341 (define (common-tests concatenate-proc unmodified?)
342 (define (try lstlst want)
343 (let ((lstlst-copy (copy-tree lstlst))
344 (got (concatenate-proc lstlst)))
346 (if (not (equal? lstlst lstlst-copy))
347 (error "input lists modified")))
350 (pass-if-exception "too few args" exception:wrong-num-args
353 (pass-if-exception "too many args" exception:wrong-num-args
354 (concatenate-proc '() '()))
356 (pass-if-exception "number" exception:wrong-type-arg
357 (concatenate-proc 123))
359 (pass-if-exception "vector" exception:wrong-type-arg
360 (concatenate-proc #(1 2 3)))
365 (pass-if (try '((1)) '(1)))
366 (pass-if (try '((1 2)) '(1 2)))
367 (pass-if (try '(() (1)) '(1)))
368 (pass-if (try '(() () (1)) '(1)))
370 (pass-if (try '((1) (2)) '(1 2)))
371 (pass-if (try '(() (1 2)) '(1 2)))
373 (pass-if (try '((1) 2) '(1 . 2)))
374 (pass-if (try '((1) (2) 3) '(1 2 . 3)))
375 (pass-if (try '((1) (2) (3 . 4)) '(1 2 3 . 4)))
378 (with-test-prefix "concatenate"
379 (common-tests concatenate #t))
381 (with-test-prefix "concatenate!"
382 (common-tests concatenate! #f)))
388 (with-test-prefix "count"
389 (pass-if-exception "no args" exception:wrong-num-args
392 (pass-if-exception "one arg" exception:wrong-num-args
395 (with-test-prefix "one list"
399 (pass-if "empty list" (= 0 (count or1 '())))
401 (pass-if-exception "pred arg count 0" exception:wrong-type-arg
402 (count (lambda () x) '(1 2 3)))
403 (pass-if-exception "pred arg count 2" exception:wrong-type-arg
404 (count (lambda (x y) x) '(1 2 3)))
406 (pass-if-exception "improper 1" exception:wrong-type-arg
408 (pass-if-exception "improper 2" exception:wrong-type-arg
409 (count or1 '(1 . 2)))
410 (pass-if-exception "improper 3" exception:wrong-type-arg
411 (count or1 '(1 2 . 3)))
413 (pass-if (= 0 (count or1 '(#f))))
414 (pass-if (= 1 (count or1 '(#t))))
416 (pass-if (= 0 (count or1 '(#f #f))))
417 (pass-if (= 1 (count or1 '(#f #t))))
418 (pass-if (= 1 (count or1 '(#t #f))))
419 (pass-if (= 2 (count or1 '(#t #t))))
421 (pass-if (= 0 (count or1 '(#f #f #f))))
422 (pass-if (= 1 (count or1 '(#f #f #t))))
423 (pass-if (= 1 (count or1 '(#t #f #f))))
424 (pass-if (= 2 (count or1 '(#t #f #t))))
425 (pass-if (= 3 (count or1 '(#t #t #t)))))
427 (with-test-prefix "two lists"
432 (= 1 (count (lambda (x y)
437 (pass-if "empty lists" (= 0 (count or2 '() '())))
439 (pass-if-exception "pred arg count 0" exception:wrong-type-arg
440 (count (lambda () #t) '(1 2 3) '(1 2 3)))
441 (pass-if-exception "pred arg count 1" exception:wrong-type-arg
442 (count (lambda (x) x) '(1 2 3) '(1 2 3)))
443 (pass-if-exception "pred arg count 3" exception:wrong-type-arg
444 (count (lambda (x y z) x) '(1 2 3) '(1 2 3)))
446 (pass-if-exception "improper first 1" exception:wrong-type-arg
447 (count or2 1 '(1 2 3)))
448 (pass-if-exception "improper first 2" exception:wrong-type-arg
449 (count or2 '(1 . 2) '(1 2 3)))
450 (pass-if-exception "improper first 3" exception:wrong-type-arg
451 (count or2 '(1 2 . 3) '(1 2 3)))
453 (pass-if-exception "improper second 1" exception:wrong-type-arg
454 (count or2 '(1 2 3) 1))
455 (pass-if-exception "improper second 2" exception:wrong-type-arg
456 (count or2 '(1 2 3) '(1 . 2)))
457 (pass-if-exception "improper second 3" exception:wrong-type-arg
458 (count or2 '(1 2 3) '(1 2 . 3)))
460 (pass-if (= 0 (count or2 '(#f) '(#f))))
461 (pass-if (= 1 (count or2 '(#t) '(#f))))
462 (pass-if (= 1 (count or2 '(#f) '(#t))))
464 (pass-if (= 0 (count or2 '(#f #f) '(#f #f))))
465 (pass-if (= 1 (count or2 '(#t #f) '(#t #f))))
466 (pass-if (= 2 (count or2 '(#t #t) '(#f #f))))
467 (pass-if (= 2 (count or2 '(#t #f) '(#f #t))))
469 (with-test-prefix "stop shortest"
470 (pass-if (= 2 (count or2 '(#t #f #t) '(#f #t))))
471 (pass-if (= 2 (count or2 '(#t #f #t #t) '(#f #t))))
472 (pass-if (= 2 (count or2 '(#t #f) '(#f #t #t))))
473 (pass-if (= 2 (count or2 '(#t #f) '(#f #t #t #t))))))
475 (with-test-prefix "three lists"
480 (= 1 (count (lambda (x y z)
486 (pass-if "empty lists" (= 0 (count or3 '() '() '())))
488 ;; currently bad pred argument gives wrong-num-args when 3 or more
489 ;; lists, as opposed to wrong-type-arg for 1 or 2 lists
490 (pass-if-exception "pred arg count 0" exception:wrong-num-args
491 (count (lambda () #t) '(1 2 3) '(1 2 3) '(1 2 3)))
492 (pass-if-exception "pred arg count 2" exception:wrong-num-args
493 (count (lambda (x y) x) '(1 2 3) '(1 2 3)'(1 2 3) ))
494 (pass-if-exception "pred arg count 4" exception:wrong-num-args
495 (count (lambda (w x y z) x) '(1 2 3) '(1 2 3) '(1 2 3)))
497 (pass-if-exception "improper first 1" exception:wrong-type-arg
498 (count or3 1 '(1 2 3) '(1 2 3)))
499 (pass-if-exception "improper first 2" exception:wrong-type-arg
500 (count or3 '(1 . 2) '(1 2 3) '(1 2 3)))
501 (pass-if-exception "improper first 3" exception:wrong-type-arg
502 (count or3 '(1 2 . 3) '(1 2 3) '(1 2 3)))
504 (pass-if-exception "improper second 1" exception:wrong-type-arg
505 (count or3 '(1 2 3) 1 '(1 2 3)))
506 (pass-if-exception "improper second 2" exception:wrong-type-arg
507 (count or3 '(1 2 3) '(1 . 2) '(1 2 3)))
508 (pass-if-exception "improper second 3" exception:wrong-type-arg
509 (count or3 '(1 2 3) '(1 2 . 3) '(1 2 3)))
511 (pass-if-exception "improper third 1" exception:wrong-type-arg
512 (count or3 '(1 2 3) '(1 2 3) 1))
513 (pass-if-exception "improper third 2" exception:wrong-type-arg
514 (count or3 '(1 2 3) '(1 2 3) '(1 . 2)))
515 (pass-if-exception "improper third 3" exception:wrong-type-arg
516 (count or3 '(1 2 3) '(1 2 3) '(1 2 . 3)))
518 (pass-if (= 0 (count or3 '(#f) '(#f) '(#f))))
519 (pass-if (= 1 (count or3 '(#t) '(#f) '(#f))))
520 (pass-if (= 1 (count or3 '(#f) '(#t) '(#f))))
521 (pass-if (= 1 (count or3 '(#f) '(#f) '(#t))))
523 (pass-if (= 0 (count or3 '(#f #f) '(#f #f) '(#f #f))))
525 (pass-if (= 1 (count or3 '(#t #f) '(#f #f) '(#f #f))))
526 (pass-if (= 1 (count or3 '(#f #t) '(#f #f) '(#f #f))))
527 (pass-if (= 1 (count or3 '(#f #f) '(#t #f) '(#f #f))))
528 (pass-if (= 1 (count or3 '(#f #f) '(#f #t) '(#f #f))))
529 (pass-if (= 1 (count or3 '(#f #f) '(#f #f) '(#t #f))))
530 (pass-if (= 1 (count or3 '(#f #f) '(#f #f) '(#f #t))))
532 (pass-if (= 2 (count or3 '(#t #t) '(#f #f) '(#f #f))))
533 (pass-if (= 2 (count or3 '(#f #f) '(#t #t) '(#f #f))))
534 (pass-if (= 2 (count or3 '(#f #f) '(#f #f) '(#t #t))))
535 (pass-if (= 2 (count or3 '(#f #f) '(#t #f) '(#f #t))))
537 (with-test-prefix "stop shortest"
538 (pass-if (= 0 (count or3 '() '(#t #t #t) '(#t #t))))
539 (pass-if (= 0 (count or3 '(#t #t #t) '() '(#t #t))))
540 (pass-if (= 0 (count or3 '(#t #t #t) '(#t #t) '())))
542 (pass-if (= 1 (count or3 '(#t) '(#t #t #t) '(#t #t))))
543 (pass-if (= 1 (count or3 '(#t #t #t) '(#t) '(#t #t))))
544 (pass-if (= 1 (count or3 '(#t #t #t) '(#t #t) '(#t)))))
546 (pass-if "apply list unchanged"
547 (let ((lst (list (list 1 2) (list 3 4) (list 5 6))))
548 (and (equal? 2 (apply count or3 lst))
550 (equal? '((1 2) (3 4) (5 6)) lst))))))
553 ;; delete and delete!
557 ;; Call (PROC lst) for all lists of length up to 6, with all combinations
558 ;; of elements to be retained or deleted. Elements to retain are numbers,
559 ;; 0 upwards. Elements to be deleted are #f.
560 (define (test-lists proc)
563 (do ((limit (ash 1 n))
567 (do ((bit 0 (1+ bit)))
569 (set! lst (cons (if (logbit? bit i) bit #f) lst)))
572 (define (common-tests delete-proc)
573 (pass-if-exception "too few args" exception:wrong-num-args
576 (pass-if-exception "too many args" exception:wrong-num-args
577 (delete-proc 0 '() equal? 99))
580 (eq? '() (delete-proc 0 '())))
582 (pass-if "equal? (the default)"
584 (delete-proc '(2) '((1) (2) (3)))))
587 (equal? '((1) (2) (3))
588 (delete-proc '(2) '((1) (2) (3)) eq?)))
590 (pass-if "called arg order"
592 (delete-proc 3 '(1 2 3 4 5) <))))
594 (with-test-prefix "delete"
595 (common-tests delete)
599 (let ((lst-copy (list-copy lst)))
600 (with-test-prefix lst-copy
602 (equal? (delete #f lst)
603 (ref-delete #f lst)))
604 (pass-if "non-destructive"
605 (equal? lst-copy lst)))))))
607 (with-test-prefix "delete!"
608 (common-tests delete!)
613 (equal? (delete! #f lst)
614 (ref-delete #f lst)))))))
617 ;; delete-duplicates and delete-duplicates!
621 ;; Call (PROC lst) for all lists of length 1 <= n <= 4, with all
622 ;; combinations of numbers 1 to n in the elements
623 (define (test-lists proc)
626 (do ((limit (integer-expt n n))
631 (rem i (quotient rem n)))
633 (set! lst (cons (remainder rem n) lst)))
636 (define (common-tests delete-duplicates-proc)
637 (pass-if-exception "too few args" exception:wrong-num-args
638 (delete-duplicates-proc))
640 (pass-if-exception "too many args" exception:wrong-num-args
641 (delete-duplicates-proc '() equal? 99))
644 (eq? '() (delete-duplicates-proc '())))
646 (pass-if "equal? (the default)"
648 (delete-duplicates-proc '((2) (2) (2)))))
651 (equal? '((2) (2) (2))
652 (delete-duplicates-proc '((2) (2) (2)) eq?)))
654 (pass-if "called arg order"
656 (delete-duplicates-proc '(1 2 3 4 5)
663 (with-test-prefix "delete-duplicates"
664 (common-tests delete-duplicates)
668 (let ((lst-copy (list-copy lst)))
669 (with-test-prefix lst-copy
671 (equal? (delete-duplicates lst)
672 (ref-delete-duplicates lst)))
673 (pass-if "non-destructive"
674 (equal? lst-copy lst)))))))
676 (with-test-prefix "delete-duplicates!"
677 (common-tests delete-duplicates!)
682 (equal? (delete-duplicates! lst)
683 (ref-delete-duplicates lst)))))))
689 (with-test-prefix "drop"
692 (null? (drop '() 0)))
719 (pass-if "'(a b c) 1"
720 (let ((lst '(a b c)))
724 (pass-if "circular '(a) 0"
725 (let ((lst (circular-list 'a)))
729 (pass-if "circular '(a) 1"
730 (let ((lst (circular-list 'a)))
734 (pass-if "circular '(a) 2"
735 (let ((lst (circular-list 'a)))
739 (pass-if "circular '(a b) 1"
740 (let ((lst (circular-list 'a)))
744 (pass-if "circular '(a b) 2"
745 (let ((lst (circular-list 'a)))
749 (pass-if "circular '(a b) 5"
750 (let ((lst (circular-list 'a)))
754 (pass-if "'(a . b) 1"
758 (pass-if "'(a b . c) 1"
760 (drop '(a b . c) 2))))
766 (with-test-prefix "drop-right"
768 (pass-if-exception "() -1" exception:out-of-range
770 (pass-if (equal? '() (drop-right '() 0)))
771 (pass-if-exception "() 1" exception:wrong-type-arg
774 (pass-if-exception "(1) -1" exception:out-of-range
775 (drop-right '(1) -1))
776 (pass-if (equal? '(1) (drop-right '(1) 0)))
777 (pass-if (equal? '() (drop-right '(1) 1)))
778 (pass-if-exception "(1) 2" exception:wrong-type-arg
781 (pass-if-exception "(4 5) -1" exception:out-of-range
782 (drop-right '(4 5) -1))
783 (pass-if (equal? '(4 5) (drop-right '(4 5) 0)))
784 (pass-if (equal? '(4) (drop-right '(4 5) 1)))
785 (pass-if (equal? '() (drop-right '(4 5) 2)))
786 (pass-if-exception "(4 5) 3" exception:wrong-type-arg
787 (drop-right '(4 5) 3))
789 (pass-if-exception "(4 5 6) -1" exception:out-of-range
790 (drop-right '(4 5 6) -1))
791 (pass-if (equal? '(4 5 6) (drop-right '(4 5 6) 0)))
792 (pass-if (equal? '(4 5) (drop-right '(4 5 6) 1)))
793 (pass-if (equal? '(4) (drop-right '(4 5 6) 2)))
794 (pass-if (equal? '() (drop-right '(4 5 6) 3)))
795 (pass-if-exception "(4 5 6) 4" exception:wrong-type-arg
796 (drop-right '(4 5 6) 4)))
802 (with-test-prefix "drop-right!"
804 (pass-if-exception "() -1" exception:out-of-range
805 (drop-right! '() -1))
806 (pass-if (equal? '() (drop-right! '() 0)))
807 (pass-if-exception "() 1" exception:wrong-type-arg
810 (pass-if-exception "(1) -1" exception:out-of-range
811 (drop-right! (list 1) -1))
812 (pass-if (equal? '(1) (drop-right! (list 1) 0)))
813 (pass-if (equal? '() (drop-right! (list 1) 1)))
814 (pass-if-exception "(1) 2" exception:wrong-type-arg
815 (drop-right! (list 1) 2))
817 (pass-if-exception "(4 5) -1" exception:out-of-range
818 (drop-right! (list 4 5) -1))
819 (pass-if (equal? '(4 5) (drop-right! (list 4 5) 0)))
820 (pass-if (equal? '(4) (drop-right! (list 4 5) 1)))
821 (pass-if (equal? '() (drop-right! (list 4 5) 2)))
822 (pass-if-exception "(4 5) 3" exception:wrong-type-arg
823 (drop-right! (list 4 5) 3))
825 (pass-if-exception "(4 5 6) -1" exception:out-of-range
826 (drop-right! (list 4 5 6) -1))
827 (pass-if (equal? '(4 5 6) (drop-right! (list 4 5 6) 0)))
828 (pass-if (equal? '(4 5) (drop-right! (list 4 5 6) 1)))
829 (pass-if (equal? '(4) (drop-right! (list 4 5 6) 2)))
830 (pass-if (equal? '() (drop-right! (list 4 5 6) 3)))
831 (pass-if-exception "(4 5 6) 4" exception:wrong-type-arg
832 (drop-right! (list 4 5 6) 4)))
838 (with-test-prefix "drop-while"
840 (pass-if (equal? '() (drop-while odd? '())))
841 (pass-if (equal? '() (drop-while odd? '(1))))
842 (pass-if (equal? '() (drop-while odd? '(1 3))))
843 (pass-if (equal? '() (drop-while odd? '(1 3 5))))
845 (pass-if (equal? '(2) (drop-while odd? '(2))))
846 (pass-if (equal? '(2) (drop-while odd? '(1 2))))
847 (pass-if (equal? '(4) (drop-while odd? '(1 3 4))))
849 (pass-if (equal? '(2 1) (drop-while odd? '(2 1))))
850 (pass-if (equal? '(4 3) (drop-while odd? '(1 4 3))))
851 (pass-if (equal? '(4 1 3) (drop-while odd? '(4 1 3)))))
857 (with-test-prefix "eighth"
858 (pass-if-exception "() -1" exception:out-of-range
859 (eighth '(a b c d e f g)))
860 (pass-if (eq? 'h (eighth '(a b c d e f g h))))
861 (pass-if (eq? 'h (eighth '(a b c d e f g h i)))))
867 (with-test-prefix "fifth"
868 (pass-if-exception "() -1" exception:out-of-range
870 (pass-if (eq? 'e (fifth '(a b c d e))))
871 (pass-if (eq? 'e (fifth '(a b c d e f)))))
877 (with-test-prefix "filter-map"
879 (with-test-prefix "one list"
880 (pass-if-exception "'x" exception:wrong-type-arg
881 (filter-map noop 'x))
883 (pass-if-exception "'(1 . x)" exception:wrong-type-arg
884 (filter-map noop '(1 . x)))
887 (equal? '(1) (filter-map noop '(1))))
890 (equal? '() (filter-map noop '(#f))))
893 (equal? '(1 2) (filter-map noop '(1 2))))
896 (equal? '(2) (filter-map noop '(#f 2))))
899 (equal? '() (filter-map noop '(#f #f))))
902 (equal? '(1 2 3) (filter-map noop '(1 2 3))))
905 (equal? '(2 3) (filter-map noop '(#f 2 3))))
908 (equal? '(1 3) (filter-map noop '(1 #f 3))))
911 (equal? '(1 2) (filter-map noop '(1 2 #f)))))
913 (with-test-prefix "two lists"
914 (pass-if-exception "'x '(1 2 3)" exception:wrong-type-arg
915 (filter-map noop 'x '(1 2 3)))
917 (pass-if-exception "'(1 2 3) 'x" exception:wrong-type-arg
918 (filter-map noop '(1 2 3) 'x))
920 (pass-if-exception "'(1 . x) '(1 2 3)" exception:wrong-type-arg
921 (filter-map noop '(1 . x) '(1 2 3)))
923 (pass-if-exception "'(1 2 3) '(1 . x)" exception:wrong-type-arg
924 (filter-map noop '(1 2 3) '(1 . x)))
926 (pass-if "(1 2 3) (4 5 6)"
927 (equal? '(5 7 9) (filter-map + '(1 2 3) '(4 5 6))))
929 (pass-if "(#f 2 3) (4 5)"
930 (equal? '(2) (filter-map noop '(#f 2 3) '(4 5))))
932 (pass-if "(4 #f) (1 2 3)"
933 (equal? '(4) (filter-map noop '(4 #f) '(1 2 3))))
935 (pass-if "() (1 2 3)"
936 (equal? '() (filter-map noop '() '(1 2 3))))
938 (pass-if "(1 2 3) ()"
939 (equal? '() (filter-map noop '(1 2 3) '()))))
941 (with-test-prefix "three lists"
942 (pass-if-exception "'x '(1 2 3) '(1 2 3)" exception:wrong-type-arg
943 (filter-map noop 'x '(1 2 3) '(1 2 3)))
945 (pass-if-exception "'(1 2 3) 'x '(1 2 3)" exception:wrong-type-arg
946 (filter-map noop '(1 2 3) 'x '(1 2 3)))
948 (pass-if-exception "'(1 2 3) '(1 2 3) 'x" exception:wrong-type-arg
949 (filter-map noop '(1 2 3) '(1 2 3) 'x))
951 (pass-if-exception "'(1 . x) '(1 2 3) '(1 2 3)" exception:wrong-type-arg
952 (filter-map noop '(1 . x) '(1 2 3) '(1 2 3)))
954 (pass-if-exception "'(1 2 3) '(1 . x) '(1 2 3)" exception:wrong-type-arg
955 (filter-map noop '(1 2 3) '(1 . x) '(1 2 3)))
957 (pass-if-exception "'(1 2 3) '(1 2 3) '(1 . x)" exception:wrong-type-arg
958 (filter-map noop '(1 2 3) '(1 2 3) '(1 . x)))
960 (pass-if "(1 2 3) (4 5 6) (7 8 9)"
961 (equal? '(12 15 18) (filter-map + '(1 2 3) '(4 5 6) '(7 8 9))))
963 (pass-if "(#f 2 3) (4 5) (7 8 9)"
964 (equal? '(2) (filter-map noop '(#f 2 3) '(4 5) '(7 8 9))))
966 (pass-if "(#f 2 3) (7 8 9) (4 5)"
967 (equal? '(2) (filter-map noop '(#f 2 3) '(7 8 9) '(4 5))))
969 (pass-if "(4 #f) (1 2 3) (7 8 9)"
970 (equal? '(4) (filter-map noop '(4 #f) '(1 2 3) '(7 8 9))))
972 (pass-if "apply list unchanged"
973 (let ((lst (list (list 1 #f 2) (list 3 4 5) (list 6 7 8))))
974 (and (equal? '(1 2) (apply filter-map noop lst))
976 (equal? lst '((1 #f 2) (3 4 5) (6 7 8))))))))
982 (with-test-prefix "find"
983 (pass-if (eqv? #f (find odd? '())))
984 (pass-if (eqv? #f (find odd? '(0))))
985 (pass-if (eqv? #f (find odd? '(0 2))))
986 (pass-if (eqv? 1 (find odd? '(1))))
987 (pass-if (eqv? 1 (find odd? '(0 1))))
988 (pass-if (eqv? 1 (find odd? '(0 1 2))))
989 (pass-if (eqv? 1 (find odd? '(2 0 1))))
990 (pass-if (eqv? 1 (find (lambda (x) (= 1 x)) '(2 0 1)))))
996 (with-test-prefix "find-tail"
997 (pass-if (let ((lst '()))
998 (eq? #f (find-tail odd? lst))))
999 (pass-if (let ((lst '(0)))
1000 (eq? #f (find-tail odd? lst))))
1001 (pass-if (let ((lst '(0 2)))
1002 (eq? #f (find-tail odd? lst))))
1003 (pass-if (let ((lst '(1)))
1004 (eq? lst (find-tail odd? lst))))
1005 (pass-if (let ((lst '(1 2)))
1006 (eq? lst (find-tail odd? lst))))
1007 (pass-if (let ((lst '(2 1)))
1008 (eq? (cdr lst) (find-tail odd? lst))))
1009 (pass-if (let ((lst '(2 1 0)))
1010 (eq? (cdr lst) (find-tail odd? lst))))
1011 (pass-if (let ((lst '(2 0 1)))
1012 (eq? (cddr lst) (find-tail odd? lst))))
1013 (pass-if (let ((lst '(2 0 1)))
1014 (eq? (cddr lst) (find-tail (lambda (x) (= 1 x)) lst)))))
1020 (with-test-prefix "fold"
1021 (pass-if-exception "no args" exception:wrong-num-args
1024 (pass-if-exception "one arg" exception:wrong-num-args
1027 (pass-if-exception "two args" exception:wrong-num-args
1030 (with-test-prefix "one list"
1032 (pass-if "arg order"
1033 (eq? #t (fold (lambda (x prev)
1038 (pass-if "empty list" (= 123 (fold + 123 '())))
1040 (pass-if-exception "proc arg count 0" exception:wrong-type-arg
1041 (fold (lambda () x) 123 '(1 2 3)))
1042 (pass-if-exception "proc arg count 1" exception:wrong-type-arg
1043 (fold (lambda (x) x) 123 '(1 2 3)))
1044 (pass-if-exception "proc arg count 3" exception:wrong-type-arg
1045 (fold (lambda (x y z) x) 123 '(1 2 3)))
1047 (pass-if-exception "improper 1" exception:wrong-type-arg
1049 (pass-if-exception "improper 2" exception:wrong-type-arg
1050 (fold + 123 '(1 . 2)))
1051 (pass-if-exception "improper 3" exception:wrong-type-arg
1052 (fold + 123 '(1 2 . 3)))
1054 (pass-if (= 3 (fold + 1 '(2))))
1055 (pass-if (= 6 (fold + 1 '(2 3))))
1056 (pass-if (= 10 (fold + 1 '(2 3 4)))))
1058 (with-test-prefix "two lists"
1060 (pass-if "arg order"
1061 (eq? #t (fold (lambda (x y prev)
1067 (pass-if "empty lists" (= 1 (fold + 1 '() '())))
1069 ;; currently bad proc argument gives wrong-num-args when 2 or more
1070 ;; lists, as opposed to wrong-type-arg for 1 list
1071 (pass-if-exception "proc arg count 2" exception:wrong-num-args
1072 (fold (lambda (x prev) x) 1 '(1 2 3) '(1 2 3)))
1073 (pass-if-exception "proc arg count 4" exception:wrong-num-args
1074 (fold (lambda (x y z prev) x) 1 '(1 2 3) '(1 2 3)))
1076 (pass-if-exception "improper first 1" exception:wrong-type-arg
1077 (fold + 1 1 '(1 2 3)))
1078 (pass-if-exception "improper first 2" exception:wrong-type-arg
1079 (fold + 1 '(1 . 2) '(1 2 3)))
1080 (pass-if-exception "improper first 3" exception:wrong-type-arg
1081 (fold + 1 '(1 2 . 3) '(1 2 3)))
1083 (pass-if-exception "improper second 1" exception:wrong-type-arg
1084 (fold + 1 '(1 2 3) 1))
1085 (pass-if-exception "improper second 2" exception:wrong-type-arg
1086 (fold + 1 '(1 2 3) '(1 . 2)))
1087 (pass-if-exception "improper second 3" exception:wrong-type-arg
1088 (fold + 1 '(1 2 3) '(1 2 . 3)))
1090 (pass-if (= 6 (fold + 1 '(2) '(3))))
1091 (pass-if (= 15 (fold + 1 '(2 3) '(4 5))))
1092 (pass-if (= 28 (fold + 1 '(2 3 4) '(5 6 7))))
1094 (with-test-prefix "stop shortest"
1095 (pass-if (= 13 (fold + 1 '(1 2 3) '(4 5))))
1096 (pass-if (= 13 (fold + 1 '(4 5) '(1 2 3))))
1097 (pass-if (= 11 (fold + 1 '(3 4) '(1 2 9 9))))
1098 (pass-if (= 11 (fold + 1 '(1 2 9 9) '(3 4)))))
1100 (pass-if "apply list unchanged"
1101 (let ((lst (list (list 1 2) (list 3 4))))
1102 (and (equal? 11 (apply fold + 1 lst))
1104 (equal? '((1 2) (3 4)) lst)))))
1106 (with-test-prefix "three lists"
1108 (pass-if "arg order"
1109 (eq? #t (fold (lambda (x y z prev)
1116 (pass-if "empty lists" (= 1 (fold + 1 '() '() '())))
1118 (pass-if-exception "proc arg count 3" exception:wrong-num-args
1119 (fold (lambda (x y prev) x) 1 '(1 2 3) '(1 2 3)'(1 2 3) ))
1120 (pass-if-exception "proc arg count 5" exception:wrong-num-args
1121 (fold (lambda (w x y z prev) x) 1 '(1 2 3) '(1 2 3) '(1 2 3)))
1123 (pass-if-exception "improper first 1" exception:wrong-type-arg
1124 (fold + 1 1 '(1 2 3) '(1 2 3)))
1125 (pass-if-exception "improper first 2" exception:wrong-type-arg
1126 (fold + 1 '(1 . 2) '(1 2 3) '(1 2 3)))
1127 (pass-if-exception "improper first 3" exception:wrong-type-arg
1128 (fold + 1 '(1 2 . 3) '(1 2 3) '(1 2 3)))
1130 (pass-if-exception "improper second 1" exception:wrong-type-arg
1131 (fold + 1 '(1 2 3) 1 '(1 2 3)))
1132 (pass-if-exception "improper second 2" exception:wrong-type-arg
1133 (fold + 1 '(1 2 3) '(1 . 2) '(1 2 3)))
1134 (pass-if-exception "improper second 3" exception:wrong-type-arg
1135 (fold + 1 '(1 2 3) '(1 2 . 3) '(1 2 3)))
1137 (pass-if-exception "improper third 1" exception:wrong-type-arg
1138 (fold + 1 '(1 2 3) '(1 2 3) 1))
1139 (pass-if-exception "improper third 2" exception:wrong-type-arg
1140 (fold + 1 '(1 2 3) '(1 2 3) '(1 . 2)))
1141 (pass-if-exception "improper third 3" exception:wrong-type-arg
1142 (fold + 1 '(1 2 3) '(1 2 3) '(1 2 . 3)))
1144 (pass-if (= 10 (fold + 1 '(2) '(3) '(4))))
1145 (pass-if (= 28 (fold + 1 '(2 5) '(3 6) '(4 7))))
1146 (pass-if (= 55 (fold + 1 '(2 5 8) '(3 6 9) '(4 7 10))))
1148 (with-test-prefix "stop shortest"
1149 (pass-if (= 28 (fold + 1 '(2 5 9) '(3 6) '(4 7))))
1150 (pass-if (= 28 (fold + 1 '(2 5) '(3 6 9) '(4 7))))
1151 (pass-if (= 28 (fold + 1 '(2 5) '(3 6) '(4 7 9)))))
1153 (pass-if "apply list unchanged"
1154 (let ((lst (list (list 1 2) (list 3 4) (list 5 6))))
1155 (and (equal? 22 (apply fold + 1 lst))
1157 (equal? '((1 2) (3 4) (5 6)) lst))))))
1163 (with-test-prefix "length+"
1164 (pass-if-exception "too few args" exception:wrong-num-args
1166 (pass-if-exception "too many args" exception:wrong-num-args
1168 (pass-if (= 0 (length+ '())))
1169 (pass-if (= 1 (length+ '(x))))
1170 (pass-if (= 2 (length+ '(x y))))
1171 (pass-if (= 3 (length+ '(x y z))))
1172 (pass-if (not (length+ (circular-list 1))))
1173 (pass-if (not (length+ (circular-list 1 2))))
1174 (pass-if (not (length+ (circular-list 1 2 3)))))
1180 (with-test-prefix "last"
1182 (pass-if-exception "empty" exception:wrong-type-arg
1185 (eqv? 1 (last '(1))))
1186 (pass-if "two elems"
1187 (eqv? 2 (last '(1 2))))
1188 (pass-if "three elems"
1189 (eqv? 3 (last '(1 2 3))))
1190 (pass-if "four elems"
1191 (eqv? 4 (last '(1 2 3 4)))))
1197 (with-test-prefix "list="
1200 (eq? #t (list= eqv?)))
1202 (with-test-prefix "one list"
1205 (eq? #t (list= eqv? '())))
1207 (eq? #t (list= eqv? '(1))))
1208 (pass-if "two elems"
1209 (eq? #t (list= eqv? '(2)))))
1211 (with-test-prefix "two lists"
1213 (pass-if "empty / empty"
1214 (eq? #t (list= eqv? '() '())))
1216 (pass-if "one / empty"
1217 (eq? #f (list= eqv? '(1) '())))
1219 (pass-if "empty / one"
1220 (eq? #f (list= eqv? '() '(1))))
1222 (pass-if "one / one same"
1223 (eq? #t (list= eqv? '(1) '(1))))
1225 (pass-if "one / one diff"
1226 (eq? #f (list= eqv? '(1) '(2))))
1228 (pass-if "called arg order"
1230 (list= (lambda (x y)
1231 (set! good (and good (= (1+ x) y)))
1236 (with-test-prefix "three lists"
1238 (pass-if "empty / empty / empty"
1239 (eq? #t (list= eqv? '() '() '())))
1241 (pass-if "one / empty / empty"
1242 (eq? #f (list= eqv? '(1) '() '())))
1244 (pass-if "one / one / empty"
1245 (eq? #f (list= eqv? '(1) '(1) '())))
1247 (pass-if "one / diff / empty"
1248 (eq? #f (list= eqv? '(1) '(2) '())))
1250 (pass-if "one / one / one"
1251 (eq? #t (list= eqv? '(1) '(1) '(1))))
1253 (pass-if "two / two / diff"
1254 (eq? #f (list= eqv? '(1 2) '(1 2) '(1 99))))
1256 (pass-if "two / two / two"
1257 (eq? #t (list= eqv? '(1 2) '(1 2) '(1 2))))
1259 (pass-if "called arg order"
1261 (list= (lambda (x y)
1262 (set! good (and good (= (1+ x) y)))
1264 '(1 4) '(2 5) '(3 6))
1271 (with-test-prefix "list-copy"
1272 (pass-if (equal? '() (list-copy '())))
1273 (pass-if (equal? '(1 2) (list-copy '(1 2))))
1274 (pass-if (equal? '(1 2 3) (list-copy '(1 2 3))))
1275 (pass-if (equal? '(1 2 3 4) (list-copy '(1 2 3 4))))
1276 (pass-if (equal? '(1 2 3 4 5) (list-copy '(1 2 3 4 5))))
1278 ;; improper lists can be copied
1279 (pass-if (equal? 1 (list-copy 1)))
1280 (pass-if (equal? '(1 . 2) (list-copy '(1 . 2))))
1281 (pass-if (equal? '(1 2 . 3) (list-copy '(1 2 . 3))))
1282 (pass-if (equal? '(1 2 3 . 4) (list-copy '(1 2 3 . 4))))
1283 (pass-if (equal? '(1 2 3 4 . 5) (list-copy '(1 2 3 4 . 5)))))
1289 (with-test-prefix "list-index"
1290 (pass-if-exception "no args" exception:wrong-num-args
1293 (pass-if-exception "one arg" exception:wrong-num-args
1296 (with-test-prefix "one list"
1298 (pass-if "empty list" (eq? #f (list-index symbol? '())))
1300 (pass-if-exception "pred arg count 0" exception:wrong-type-arg
1301 (list-index (lambda () x) '(1 2 3)))
1302 (pass-if-exception "pred arg count 2" exception:wrong-type-arg
1303 (list-index (lambda (x y) x) '(1 2 3)))
1305 (pass-if-exception "improper 1" exception:wrong-type-arg
1306 (list-index symbol? 1))
1307 (pass-if-exception "improper 2" exception:wrong-type-arg
1308 (list-index symbol? '(1 . 2)))
1309 (pass-if-exception "improper 3" exception:wrong-type-arg
1310 (list-index symbol? '(1 2 . 3)))
1312 (pass-if (eqv? #f (list-index symbol? '(1))))
1313 (pass-if (eqv? 0 (list-index symbol? '(x))))
1315 (pass-if (eqv? #f (list-index symbol? '(1 2))))
1316 (pass-if (eqv? 0 (list-index symbol? '(x 1))))
1317 (pass-if (eqv? 1 (list-index symbol? '(1 x))))
1319 (pass-if (eqv? #f (list-index symbol? '(1 2 3))))
1320 (pass-if (eqv? 0 (list-index symbol? '(x 1 2))))
1321 (pass-if (eqv? 1 (list-index symbol? '(1 x 2))))
1322 (pass-if (eqv? 2 (list-index symbol? '(1 2 x)))))
1324 (with-test-prefix "two lists"
1330 (pass-if "arg order"
1331 (eqv? 0 (list-index (lambda (x y)
1336 (pass-if "empty lists" (eqv? #f (list-index sym2 '() '())))
1338 (pass-if-exception "pred arg count 0" exception:wrong-type-arg
1339 (list-index (lambda () #t) '(1 2 3) '(1 2 3)))
1340 (pass-if-exception "pred arg count 1" exception:wrong-type-arg
1341 (list-index (lambda (x) x) '(1 2 3) '(1 2 3)))
1342 (pass-if-exception "pred arg count 3" exception:wrong-type-arg
1343 (list-index (lambda (x y z) x) '(1 2 3) '(1 2 3)))
1345 (pass-if-exception "improper first 1" exception:wrong-type-arg
1346 (list-index sym2 1 '(1 2 3)))
1347 (pass-if-exception "improper first 2" exception:wrong-type-arg
1348 (list-index sym2 '(1 . 2) '(1 2 3)))
1349 (pass-if-exception "improper first 3" exception:wrong-type-arg
1350 (list-index sym2 '(1 2 . 3) '(1 2 3)))
1352 (pass-if-exception "improper second 1" exception:wrong-type-arg
1353 (list-index sym2 '(1 2 3) 1))
1354 (pass-if-exception "improper second 2" exception:wrong-type-arg
1355 (list-index sym2 '(1 2 3) '(1 . 2)))
1356 (pass-if-exception "improper second 3" exception:wrong-type-arg
1357 (list-index sym2 '(1 2 3) '(1 2 . 3)))
1359 (pass-if (eqv? #f (list-index sym2 '(1) '(2))))
1360 (pass-if (eqv? 0 (list-index sym2 '(1) '(x))))
1362 (pass-if (eqv? #f (list-index sym2 '(1 2) '(3 4))))
1363 (pass-if (eqv? 0 (list-index sym2 '(1 2) '(x 3))))
1364 (pass-if (eqv? 1 (list-index sym2 '(1 2) '(3 x))))
1366 (pass-if (eqv? #f (list-index sym2 '(1 2 3) '(3 4 5))))
1367 (pass-if (eqv? 0 (list-index sym2 '(1 2 3) '(x 3 4))))
1368 (pass-if (eqv? 1 (list-index sym2 '(1 2 3) '(3 x 4))))
1369 (pass-if (eqv? 2 (list-index sym2 '(1 2 3) '(3 4 x))))
1371 (with-test-prefix "stop shortest"
1372 (pass-if (eqv? #f (list-index sym1 '(1 2 x) '(4 5))))
1373 (pass-if (eqv? #f (list-index sym2 '(4 5) '(1 2 x))))
1374 (pass-if (eqv? #f (list-index sym1 '(3 4) '(1 2 x y))))
1375 (pass-if (eqv? #f (list-index sym2 '(1 2 x y) '(3 4))))))
1377 (with-test-prefix "three lists"
1378 (define (sym1 x y z)
1380 (define (sym2 x y z)
1382 (define (sym3 x y z)
1385 (pass-if "arg order"
1386 (eqv? 0 (list-index (lambda (x y z)
1392 (pass-if "empty lists" (eqv? #f (list-index sym3 '() '() '())))
1394 ;; currently bad pred argument gives wrong-num-args when 3 or more
1395 ;; lists, as opposed to wrong-type-arg for 1 or 2 lists
1396 (pass-if-exception "pred arg count 0" exception:wrong-num-args
1397 (list-index (lambda () #t) '(1 2 3) '(1 2 3) '(1 2 3)))
1398 (pass-if-exception "pred arg count 2" exception:wrong-num-args
1399 (list-index (lambda (x y) x) '(1 2 3) '(1 2 3)'(1 2 3) ))
1400 (pass-if-exception "pred arg count 4" exception:wrong-num-args
1401 (list-index (lambda (w x y z) x) '(1 2 3) '(1 2 3) '(1 2 3)))
1403 (pass-if-exception "improper first 1" exception:wrong-type-arg
1404 (list-index sym3 1 '(1 2 3) '(1 2 3)))
1405 (pass-if-exception "improper first 2" exception:wrong-type-arg
1406 (list-index sym3 '(1 . 2) '(1 2 3) '(1 2 3)))
1407 (pass-if-exception "improper first 3" exception:wrong-type-arg
1408 (list-index sym3 '(1 2 . 3) '(1 2 3) '(1 2 3)))
1410 (pass-if-exception "improper second 1" exception:wrong-type-arg
1411 (list-index sym3 '(1 2 3) 1 '(1 2 3)))
1412 (pass-if-exception "improper second 2" exception:wrong-type-arg
1413 (list-index sym3 '(1 2 3) '(1 . 2) '(1 2 3)))
1414 (pass-if-exception "improper second 3" exception:wrong-type-arg
1415 (list-index sym3 '(1 2 3) '(1 2 . 3) '(1 2 3)))
1417 (pass-if-exception "improper third 1" exception:wrong-type-arg
1418 (list-index sym3 '(1 2 3) '(1 2 3) 1))
1419 (pass-if-exception "improper third 2" exception:wrong-type-arg
1420 (list-index sym3 '(1 2 3) '(1 2 3) '(1 . 2)))
1421 (pass-if-exception "improper third 3" exception:wrong-type-arg
1422 (list-index sym3 '(1 2 3) '(1 2 3) '(1 2 . 3)))
1424 (pass-if (eqv? #f (list-index sym3 '(#f) '(#f) '(#f))))
1425 (pass-if (eqv? 0 (list-index sym3 '(#f) '(#f) '(x))))
1427 (pass-if (eqv? #f (list-index sym3 '(#f #f) '(#f #f) '(#f #f))))
1428 (pass-if (eqv? 0 (list-index sym3 '(#f #f) '(#f #f) '(x #f))))
1429 (pass-if (eqv? 1 (list-index sym3 '(#f #f) '(#f #f) '(#f x))))
1431 (pass-if (eqv? #f (list-index sym3 '(#f #f #f) '(#f #f #f) '(#f #f #f))))
1432 (pass-if (eqv? 0 (list-index sym3 '(#f #f #f) '(#f #f #f) '(x #f #f))))
1433 (pass-if (eqv? 1 (list-index sym3 '(#f #f #f) '(#f #f #f) '(#f x #f))))
1434 (pass-if (eqv? 2 (list-index sym3 '(#f #f #f) '(#f #f #f) '(#f #f x))))
1436 (with-test-prefix "stop shortest"
1437 (pass-if (eqv? #f (list-index sym2 '() '(x x x) '(x x))))
1438 (pass-if (eqv? #f (list-index sym1 '(x x x) '() '(x x))))
1439 (pass-if (eqv? #f (list-index sym2 '(x x x) '(x x) '())))
1441 (pass-if (eqv? #f (list-index sym2 '(#t) '(#t x x) '(#t x))))
1442 (pass-if (eqv? #f (list-index sym1 '(#t x x) '(#t) '(#t x))))
1443 (pass-if (eqv? #f (list-index sym1 '(#t x x) '(#t x) '(#t)))))
1445 (pass-if "apply list unchanged"
1446 (let ((lst (list (list 1 2) (list 3 4) (list 5 6))))
1447 (and (equal? #f (apply list-index sym3 lst))
1449 (equal? '((1 2) (3 4) (5 6)) lst))))))
1455 (with-test-prefix "list-tabulate"
1457 (pass-if-exception "-1" exception:out-of-range
1458 (list-tabulate -1 identity))
1460 (equal? '() (list-tabulate 0 identity)))
1462 (equal? '(0) (list-tabulate 1 identity)))
1464 (equal? '(0 1) (list-tabulate 2 identity)))
1466 (equal? '(0 1 2) (list-tabulate 3 identity)))
1468 (equal? '(0 1 2 3) (list-tabulate 4 identity)))
1469 (pass-if "string ref proc"
1470 (equal? '(#\a #\b #\c #\d) (list-tabulate 4
1472 (string-ref "abcd" i))))))
1478 (with-test-prefix "lset="
1480 ;; in guile 1.6.7 and earlier, lset= incorrectly demanded at least one
1483 (eq? #t (lset= eq?)))
1485 (with-test-prefix "one arg"
1488 (eq? #t (lset= eqv? '())))
1491 (eq? #t (lset= eqv? '(1))))
1494 (eq? #t (lset= eqv? '(1 2)))))
1496 (with-test-prefix "two args"
1499 (eq? #t (lset= eqv? '() '())))
1502 (eq? #t (lset= eqv? '(1) '(1))))
1505 (eq? #f (lset= eqv? '(1) '(2))))
1507 (pass-if "(1) (1 2)"
1508 (eq? #f (lset= eqv? '(1) '(1 2))))
1510 (pass-if "(1 2) (2 1)"
1511 (eq? #t (lset= eqv? '(1 2) '(2 1))))
1513 (pass-if "called arg order"
1515 (lset= (lambda (x y)
1516 (if (not (= x (1- y)))
1522 (with-test-prefix "three args"
1525 (eq? #t (lset= eqv? '() '() '())))
1527 (pass-if "(1) (1) (1)"
1528 (eq? #t (lset= eqv? '(1) '(1) '(1))))
1530 (pass-if "(1) (1) (2)"
1531 (eq? #f (lset= eqv? '(1) '(1) '(2))))
1533 (pass-if "(1) (1) (1 2)"
1534 (eq? #f (lset= eqv? '(1) '(1) '(1 2))))
1536 (pass-if "(1 2 3) (3 2 1) (1 3 2)"
1537 (eq? #t (lset= eqv? '(1 2 3) '(3 2 1) '(1 3 2))))
1539 (pass-if "called arg order"
1541 (lset= (lambda (x y)
1542 (if (not (= x (1- y)))
1545 '(1 1) '(2 2) '(3 3))
1552 (with-test-prefix "lset-adjoin"
1554 ;; in guile 1.6.7 and earlier, lset-adjoin didn't actually use the given
1555 ;; `=' procedure, all comparisons were just with `equal?
1557 (with-test-prefix "case-insensitive ="
1559 (pass-if "(\"x\") \"X\""
1560 (equal? '("x") (lset-adjoin string-ci=? '("x") "X"))))
1562 (pass-if "called arg order"
1564 (lset-adjoin (lambda (x y)
1565 (set! good (and (= x 1) (= y 2)))
1570 (pass-if (equal? '() (lset-adjoin = '())))
1572 (pass-if (equal? '(1) (lset-adjoin = '() 1)))
1574 (pass-if (equal? '(1) (lset-adjoin = '() 1 1)))
1576 (pass-if (equal? '(2 1) (lset-adjoin = '() 1 2)))
1578 (pass-if (equal? '(3 1 2) (lset-adjoin = '(1 2) 1 2 3 2 1)))
1580 (pass-if "apply list unchanged"
1581 (let ((lst (list 1 2)))
1582 (and (equal? '(2 1 3) (apply lset-adjoin = '(3) lst))
1584 (equal? '(1 2) lst))))
1586 (pass-if "(1 1) 1 1"
1587 (equal? '(1 1) (lset-adjoin = '(1 1) 1 1)))
1589 ;; duplicates among args are cast out
1591 (equal? '(1 2) (lset-adjoin = '(2) 1 1))))
1597 (with-test-prefix "lset-union"
1600 (eq? '() (lset-union eq?)))
1603 (equal? '(1 2 3) (lset-union eq? '(1 2 3))))
1606 (equal? '() (lset-union eq? '() '())))
1608 (pass-if "'() '(1 2 3)"
1609 (equal? '(1 2 3) (lset-union eq? '() '(1 2 3))))
1611 (pass-if "'(1 2 3) '()"
1612 (equal? '(1 2 3) (lset-union eq? '(1 2 3) '())))
1614 (pass-if "'(1 2 3) '(4 3 5)"
1615 (equal? '(5 4 1 2 3) (lset-union eq? '(1 2 3) '(4 3 5))))
1617 (pass-if "'(1 2 3) '(4) '(3 5))"
1618 (equal? '(5 4 1 2 3) (lset-union eq? '(1 2 3) '(4) '(3 5))))
1620 ;; in guile 1.6.7 and earlier, `=' was called with the arguments the wrong
1622 (pass-if "called arg order"
1624 (lset-union (lambda (x y)
1625 (set! good (and (= x 1) (= y 2)))
1634 (with-test-prefix "member"
1636 (pass-if-exception "no args" exception:wrong-num-args
1639 (pass-if-exception "one arg" exception:wrong-num-args
1642 (pass-if "1 (1 2 3)"
1643 (let ((lst '(1 2 3)))
1644 (eq? lst (member 1 lst))))
1646 (pass-if "2 (1 2 3)"
1647 (let ((lst '(1 2 3)))
1648 (eq? (cdr lst) (member 2 lst))))
1650 (pass-if "3 (1 2 3)"
1651 (let ((lst '(1 2 3)))
1652 (eq? (cddr lst) (member 3 lst))))
1654 (pass-if "4 (1 2 3)"
1655 (let ((lst '(1 2 3)))
1656 (eq? #f (member 4 lst))))
1658 (pass-if "called arg order"
1660 (member 1 '(2) (lambda (x y)
1661 (set! good (and (eqv? 1 x)
1669 (with-test-prefix "ninth"
1670 (pass-if-exception "() -1" exception:out-of-range
1671 (ninth '(a b c d e f g h)))
1672 (pass-if (eq? 'i (ninth '(a b c d e f g h i))))
1673 (pass-if (eq? 'i (ninth '(a b c d e f g h i j)))))
1680 (with-test-prefix "not-pair?"
1682 (eq? #t (not-pair? 123)))
1684 (eq? #f (not-pair? '(x . y))))
1686 (eq? #t (not-pair? 'x))))
1692 (with-test-prefix "take"
1695 (null? (take '() 0)))
1698 (null? (take '(a) 0)))
1701 (null? (take '() 0)))
1703 (pass-if "'(a b c) 0"
1704 (null? (take '() 0)))
1709 (and (equal? '(a) got)
1710 (not (eq? lst got)))))
1716 (pass-if "'(a b c) 1"
1723 (and (equal? '(a b) got)
1724 (not (eq? lst got)))))
1726 (pass-if "'(a b c) 2"
1730 (pass-if "circular '(a) 0"
1732 (take (circular-list 'a) 0)))
1734 (pass-if "circular '(a) 1"
1736 (take (circular-list 'a) 1)))
1738 (pass-if "circular '(a) 2"
1740 (take (circular-list 'a) 2)))
1742 (pass-if "circular '(a b) 5"
1743 (equal? '(a b a b a)
1744 (take (circular-list 'a 'b) 5)))
1746 (pass-if "'(a . b) 1"
1750 (pass-if "'(a b . c) 1"
1752 (take '(a b . c) 1)))
1754 (pass-if "'(a b . c) 2"
1756 (take '(a b . c) 2))))
1762 (with-test-prefix "take-while"
1764 (pass-if (equal? '() (take-while odd? '())))
1765 (pass-if (equal? '(1) (take-while odd? '(1))))
1766 (pass-if (equal? '(1 3) (take-while odd? '(1 3))))
1767 (pass-if (equal? '(1 3 5) (take-while odd? '(1 3 5))))
1769 (pass-if (equal? '() (take-while odd? '(2))))
1770 (pass-if (equal? '(1) (take-while odd? '(1 2))))
1771 (pass-if (equal? '(1 3) (take-while odd? '(1 3 4))))
1773 (pass-if (equal? '() (take-while odd? '(2 1))))
1774 (pass-if (equal? '(1) (take-while odd? '(1 4 3))))
1775 (pass-if (equal? '() (take-while odd? '(4 1 3)))))
1781 (with-test-prefix "take-while!"
1783 (pass-if (equal? '() (take-while! odd? '())))
1784 (pass-if (equal? '(1) (take-while! odd? (list 1))))
1785 (pass-if (equal? '(1 3) (take-while! odd? (list 1 3))))
1786 (pass-if (equal? '(1 3 5) (take-while! odd? (list 1 3 5))))
1788 (pass-if (equal? '() (take-while! odd? (list 2))))
1789 (pass-if (equal? '(1) (take-while! odd? (list 1 2))))
1790 (pass-if (equal? '(1 3) (take-while! odd? (list 1 3 4))))
1792 (pass-if (equal? '() (take-while! odd? (list 2 1))))
1793 (pass-if (equal? '(1) (take-while! odd? (list 1 4 3))))
1794 (pass-if (equal? '() (take-while! odd? (list 4 1 3)))))
1800 (define (test-partition pred list kept-good dropped-good)
1801 (call-with-values (lambda ()
1802 (partition pred list))
1803 (lambda (kept dropped)
1804 (and (equal? kept kept-good)
1805 (equal? dropped dropped-good)))))
1807 (with-test-prefix "partition"
1809 (pass-if "with dropped tail"
1810 (test-partition even? '(1 2 3 4 5 6 7)
1811 '(2 4 6) '(1 3 5 7)))
1813 (pass-if "with kept tail"
1814 (test-partition even? '(1 2 3 4 5 6)
1817 (pass-if "with everything dropped"
1818 (test-partition even? '(1 3 5 7)
1821 (pass-if "with everything kept"
1822 (test-partition even? '(2 4 6)
1825 (pass-if "with empty list"
1826 (test-partition even? '()
1829 (pass-if "with reasonably long list"
1830 ;; the old implementation from SRFI-1 reference implementation
1831 ;; would signal a stack-overflow for a list of only 500 elements!
1832 (call-with-values (lambda ()
1834 (make-list 10000 1)))
1836 (and (= (length odd) 10000)
1837 (= (length even) 0))))))
1843 (define (test-partition! pred list kept-good dropped-good)
1844 (call-with-values (lambda ()
1845 (partition! pred list))
1846 (lambda (kept dropped)
1847 (and (equal? kept kept-good)
1848 (equal? dropped dropped-good)))))
1850 (with-test-prefix "partition!"
1852 (pass-if "with dropped tail"
1853 (test-partition! even? (list 1 2 3 4 5 6 7)
1854 '(2 4 6) '(1 3 5 7)))
1856 (pass-if "with kept tail"
1857 (test-partition! even? (list 1 2 3 4 5 6)
1860 (pass-if "with everything dropped"
1861 (test-partition! even? (list 1 3 5 7)
1864 (pass-if "with everything kept"
1865 (test-partition! even? (list 2 4 6)
1868 (pass-if "with empty list"
1869 (test-partition! even? '()
1872 (pass-if "with reasonably long list"
1873 ;; the old implementation from SRFI-1 reference implementation
1874 ;; would signal a stack-overflow for a list of only 500 elements!
1875 (call-with-values (lambda ()
1877 (make-list 10000 1)))
1879 (and (= (length odd) 10000)
1880 (= (length even) 0))))))
1886 (with-test-prefix "reduce"
1890 (ret (reduce (lambda (x prev)
1891 (set! calls (cons (list x prev) calls))
1894 (and (equal? calls '())
1899 (ret (reduce (lambda (x prev)
1900 (set! calls (cons (list x prev) calls))
1903 (and (equal? calls '())
1906 (pass-if "two elems"
1908 (ret (reduce (lambda (x prev)
1909 (set! calls (cons (list x prev) calls))
1912 (and (equal? calls '((3 2)))
1915 (pass-if "three elems"
1917 (ret (reduce (lambda (x prev)
1918 (set! calls (cons (list x prev) calls))
1921 (and (equal? calls '((4 3)
1925 (pass-if "four elems"
1927 (ret (reduce (lambda (x prev)
1928 (set! calls (cons (list x prev) calls))
1931 (and (equal? calls '((5 4)
1940 (with-test-prefix "reduce-right"
1944 (ret (reduce-right (lambda (x prev)
1945 (set! calls (cons (list x prev) calls))
1948 (and (equal? calls '())
1953 (ret (reduce-right (lambda (x prev)
1954 (set! calls (cons (list x prev) calls))
1957 (and (equal? calls '())
1960 (pass-if "two elems"
1962 (ret (reduce-right (lambda (x prev)
1963 (set! calls (cons (list x prev) calls))
1966 (and (equal? calls '((2 3)))
1969 (pass-if "three elems"
1971 (ret (reduce-right (lambda (x prev)
1972 (set! calls (cons (list x prev) calls))
1975 (and (equal? calls '((2 3)
1979 (pass-if "four elems"
1981 (ret (reduce-right (lambda (x prev)
1982 (set! calls (cons (list x prev) calls))
1985 (and (equal? calls '((2 3)
1994 (with-test-prefix "remove"
1996 (pass-if (equal? '() (remove odd? '())))
1997 (pass-if (equal? '() (remove odd? '(1))))
1998 (pass-if (equal? '(2) (remove odd? '(2))))
2000 (pass-if (equal? '() (remove odd? '(1 3))))
2001 (pass-if (equal? '(2) (remove odd? '(2 3))))
2002 (pass-if (equal? '(2) (remove odd? '(1 2))))
2003 (pass-if (equal? '(2 4) (remove odd? '(2 4))))
2005 (pass-if (equal? '() (remove odd? '(1 3 5))))
2006 (pass-if (equal? '(2) (remove odd? '(2 3 5))))
2007 (pass-if (equal? '(2) (remove odd? '(1 2 5))))
2008 (pass-if (equal? '(2 4) (remove odd? '(2 4 5))))
2010 (pass-if (equal? '(6) (remove odd? '(1 3 6))))
2011 (pass-if (equal? '(2 6) (remove odd? '(2 3 6))))
2012 (pass-if (equal? '(2 6) (remove odd? '(1 2 6))))
2013 (pass-if (equal? '(2 4 6) (remove odd? '(2 4 6)))))
2019 (with-test-prefix "remove!"
2021 (pass-if (equal? '() (remove! odd? '())))
2022 (pass-if (equal? '() (remove! odd? (list 1))))
2023 (pass-if (equal? '(2) (remove! odd? (list 2))))
2025 (pass-if (equal? '() (remove! odd? (list 1 3))))
2026 (pass-if (equal? '(2) (remove! odd? (list 2 3))))
2027 (pass-if (equal? '(2) (remove! odd? (list 1 2))))
2028 (pass-if (equal? '(2 4) (remove! odd? (list 2 4))))
2030 (pass-if (equal? '() (remove! odd? (list 1 3 5))))
2031 (pass-if (equal? '(2) (remove! odd? (list 2 3 5))))
2032 (pass-if (equal? '(2) (remove! odd? (list 1 2 5))))
2033 (pass-if (equal? '(2 4) (remove! odd? (list 2 4 5))))
2035 (pass-if (equal? '(6) (remove! odd? (list 1 3 6))))
2036 (pass-if (equal? '(2 6) (remove! odd? (list 2 3 6))))
2037 (pass-if (equal? '(2 6) (remove! odd? (list 1 2 6))))
2038 (pass-if (equal? '(2 4 6) (remove! odd? (list 2 4 6)))))
2044 (with-test-prefix "seventh"
2045 (pass-if-exception "() -1" exception:out-of-range
2046 (seventh '(a b c d e f)))
2047 (pass-if (eq? 'g (seventh '(a b c d e f g))))
2048 (pass-if (eq? 'g (seventh '(a b c d e f g h)))))
2054 (with-test-prefix "sixth"
2055 (pass-if-exception "() -1" exception:out-of-range
2056 (sixth '(a b c d e)))
2057 (pass-if (eq? 'f (sixth '(a b c d e f))))
2058 (pass-if (eq? 'f (sixth '(a b c d e f g)))))
2064 (with-test-prefix "split-at"
2066 (define (equal-values? lst thunk)
2067 (call-with-values thunk
2071 (pass-if-exception "() -1" exception:out-of-range
2073 (pass-if (equal-values? '(() ())
2074 (lambda () (split-at '() 0))))
2075 (pass-if-exception "() 1" exception:wrong-type-arg
2078 (pass-if-exception "(1) -1" exception:out-of-range
2080 (pass-if (equal-values? '(() (1)) (lambda () (split-at '(1) 0))))
2081 (pass-if (equal-values? '((1) ()) (lambda () (split-at '(1) 1))))
2082 (pass-if-exception "(1) 2" exception:wrong-type-arg
2085 (pass-if-exception "(4 5) -1" exception:out-of-range
2086 (split-at '(4 5) -1))
2087 (pass-if (equal-values? '(() (4 5)) (lambda () (split-at '(4 5) 0))))
2088 (pass-if (equal-values? '((4) (5)) (lambda () (split-at '(4 5) 1))))
2089 (pass-if (equal-values? '((4 5) ()) (lambda () (split-at '(4 5) 2))))
2090 (pass-if-exception "(4 5) 3" exception:wrong-type-arg
2091 (split-at '(4 5) 3))
2093 (pass-if-exception "(4 5 6) -1" exception:out-of-range
2094 (split-at '(4 5 6) -1))
2095 (pass-if (equal-values? '(() (4 5 6)) (lambda () (split-at '(4 5 6) 0))))
2096 (pass-if (equal-values? '((4) (5 6)) (lambda () (split-at '(4 5 6) 1))))
2097 (pass-if (equal-values? '((4 5) (6)) (lambda () (split-at '(4 5 6) 2))))
2098 (pass-if (equal-values? '((4 5 6) ()) (lambda () (split-at '(4 5 6) 3))))
2099 (pass-if-exception "(4 5 6) 4" exception:wrong-type-arg
2100 (split-at '(4 5 6) 4)))
2106 (with-test-prefix "split-at!"
2108 (define (equal-values? lst thunk)
2109 (call-with-values thunk
2113 (pass-if-exception "() -1" exception:out-of-range
2115 (pass-if (equal-values? '(() ())
2116 (lambda () (split-at! '() 0))))
2117 (pass-if-exception "() 1" exception:wrong-type-arg
2120 (pass-if-exception "(1) -1" exception:out-of-range
2121 (split-at! (list 1) -1))
2122 (pass-if (equal-values? '(() (1)) (lambda () (split-at! (list 1) 0))))
2123 (pass-if (equal-values? '((1) ()) (lambda () (split-at! (list 1) 1))))
2124 (pass-if-exception "(1) 2" exception:wrong-type-arg
2125 (split-at! (list 1) 2))
2127 (pass-if-exception "(4 5) -1" exception:out-of-range
2128 (split-at! (list 4 5) -1))
2129 (pass-if (equal-values? '(() (4 5)) (lambda () (split-at! (list 4 5) 0))))
2130 (pass-if (equal-values? '((4) (5)) (lambda () (split-at! (list 4 5) 1))))
2131 (pass-if (equal-values? '((4 5) ()) (lambda () (split-at! (list 4 5) 2))))
2132 (pass-if-exception "(4 5) 3" exception:wrong-type-arg
2133 (split-at! (list 4 5) 3))
2135 (pass-if-exception "(4 5 6) -1" exception:out-of-range
2136 (split-at! (list 4 5 6) -1))
2137 (pass-if (equal-values? '(() (4 5 6)) (lambda () (split-at! (list 4 5 6) 0))))
2138 (pass-if (equal-values? '((4) (5 6)) (lambda () (split-at! (list 4 5 6) 1))))
2139 (pass-if (equal-values? '((4 5) (6)) (lambda () (split-at! (list 4 5 6) 2))))
2140 (pass-if (equal-values? '((4 5 6) ()) (lambda () (split-at! (list 4 5 6) 3))))
2141 (pass-if-exception "(4 5 6) 4" exception:wrong-type-arg
2142 (split-at! (list 4 5 6) 4)))
2148 (with-test-prefix "span"
2150 (define (test-span lst want-v1 want-v2)
2153 (span positive? lst))
2154 (lambda (got-v1 got-v2)
2155 (and (equal? got-v1 want-v1)
2156 (equal? got-v2 want-v2)))))
2159 (test-span '() '() '()))
2162 (test-span '(1) '(1) '()))
2165 (test-span '(-1) '() '(-1)))
2168 (test-span '(1 2) '(1 2) '()))
2171 (test-span '(-1 1) '() '(-1 1)))
2174 (test-span '(1 -1) '(1) '(-1)))
2177 (test-span '(-1 -2) '() '(-1 -2)))
2180 (test-span '(1 2 3) '(1 2 3) '()))
2183 (test-span '(-1 1 2) '() '(-1 1 2)))
2186 (test-span '(1 -1 2) '(1) '(-1 2)))
2189 (test-span '(-1 -2 1) '() '(-1 -2 1)))
2192 (test-span '(1 2 -1) '(1 2) '(-1)))
2195 (test-span '(-1 1 -2) '() '(-1 1 -2)))
2198 (test-span '(1 -1 -2) '(1) '(-1 -2)))
2201 (test-span '(-1 -2 -3) '() '(-1 -2 -3))))
2207 (with-test-prefix "span!"
2209 (define (test-span! lst want-v1 want-v2)
2212 (span! positive? lst))
2213 (lambda (got-v1 got-v2)
2214 (and (equal? got-v1 want-v1)
2215 (equal? got-v2 want-v2)))))
2218 (test-span! '() '() '()))
2221 (test-span! (list 1) '(1) '()))
2224 (test-span! (list -1) '() '(-1)))
2227 (test-span! (list 1 2) '(1 2) '()))
2230 (test-span! (list -1 1) '() '(-1 1)))
2233 (test-span! (list 1 -1) '(1) '(-1)))
2236 (test-span! (list -1 -2) '() '(-1 -2)))
2239 (test-span! (list 1 2 3) '(1 2 3) '()))
2242 (test-span! (list -1 1 2) '() '(-1 1 2)))
2245 (test-span! (list 1 -1 2) '(1) '(-1 2)))
2248 (test-span! (list -1 -2 1) '() '(-1 -2 1)))
2251 (test-span! (list 1 2 -1) '(1 2) '(-1)))
2254 (test-span! (list -1 1 -2) '() '(-1 1 -2)))
2257 (test-span! (list 1 -1 -2) '(1) '(-1 -2)))
2260 (test-span! (list -1 -2 -3) '() '(-1 -2 -3))))
2266 (with-test-prefix "take!"
2268 (pass-if-exception "() -1" exception:out-of-range
2270 (pass-if (equal? '() (take! '() 0)))
2271 (pass-if-exception "() 1" exception:wrong-type-arg
2274 (pass-if-exception "(1) -1" exception:out-of-range
2276 (pass-if (equal? '() (take! '(1) 0)))
2277 (pass-if (equal? '(1) (take! '(1) 1)))
2278 (pass-if-exception "(1) 2" exception:wrong-type-arg
2281 (pass-if-exception "(4 5) -1" exception:out-of-range
2283 (pass-if (equal? '() (take! '(4 5) 0)))
2284 (pass-if (equal? '(4) (take! '(4 5) 1)))
2285 (pass-if (equal? '(4 5) (take! '(4 5) 2)))
2286 (pass-if-exception "(4 5) 3" exception:wrong-type-arg
2289 (pass-if-exception "(4 5 6) -1" exception:out-of-range
2290 (take! '(4 5 6) -1))
2291 (pass-if (equal? '() (take! '(4 5 6) 0)))
2292 (pass-if (equal? '(4) (take! '(4 5 6) 1)))
2293 (pass-if (equal? '(4 5) (take! '(4 5 6) 2)))
2294 (pass-if (equal? '(4 5 6) (take! '(4 5 6) 3)))
2295 (pass-if-exception "(4 5 6) 4" exception:wrong-type-arg
2296 (take! '(4 5 6) 4)))
2303 (with-test-prefix "take-right"
2305 (pass-if-exception "() -1" exception:out-of-range
2306 (take-right '() -1))
2307 (pass-if (equal? '() (take-right '() 0)))
2308 (pass-if-exception "() 1" exception:wrong-type-arg
2311 (pass-if-exception "(1) -1" exception:out-of-range
2312 (take-right '(1) -1))
2313 (pass-if (equal? '() (take-right '(1) 0)))
2314 (pass-if (equal? '(1) (take-right '(1) 1)))
2315 (pass-if-exception "(1) 2" exception:wrong-type-arg
2316 (take-right '(1) 2))
2318 (pass-if-exception "(4 5) -1" exception:out-of-range
2319 (take-right '(4 5) -1))
2320 (pass-if (equal? '() (take-right '(4 5) 0)))
2321 (pass-if (equal? '(5) (take-right '(4 5) 1)))
2322 (pass-if (equal? '(4 5) (take-right '(4 5) 2)))
2323 (pass-if-exception "(4 5) 3" exception:wrong-type-arg
2324 (take-right '(4 5) 3))
2326 (pass-if-exception "(4 5 6) -1" exception:out-of-range
2327 (take-right '(4 5 6) -1))
2328 (pass-if (equal? '() (take-right '(4 5 6) 0)))
2329 (pass-if (equal? '(6) (take-right '(4 5 6) 1)))
2330 (pass-if (equal? '(5 6) (take-right '(4 5 6) 2)))
2331 (pass-if (equal? '(4 5 6) (take-right '(4 5 6) 3)))
2332 (pass-if-exception "(4 5 6) 4" exception:wrong-type-arg
2333 (take-right '(4 5 6) 4)))
2339 (with-test-prefix "tenth"
2340 (pass-if-exception "() -1" exception:out-of-range
2341 (tenth '(a b c d e f g h i)))
2342 (pass-if (eq? 'j (tenth '(a b c d e f g h i j))))
2343 (pass-if (eq? 'j (tenth '(a b c d e f g h i j k)))))
2349 (with-test-prefix "xcons"
2350 (pass-if (equal? '(y . x) (xcons 'x 'y))))