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., 51 Franklin Street, Fifth Floor,
18 ;;;; Boston, MA 02110-1301 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-difference"
1599 (pass-if "called arg order"
1601 (lset-difference (lambda (x y)
1602 (set! good (and (= x 1) (= y 2)))
1611 (with-test-prefix "lset-difference!"
1613 (pass-if-exception "proc - num" exception:wrong-type-arg
1614 (lset-difference! 123 '(4)))
1615 (pass-if-exception "proc - list" exception:wrong-type-arg
1616 (lset-difference! (list 1 2 3) '(4)))
1618 (pass-if "called arg order"
1620 (lset-difference! (lambda (x y)
1621 (set! good (and (= x 1) (= y 2)))
1626 (pass-if (equal? '() (lset-difference! = '())))
1627 (pass-if (equal? '(1) (lset-difference! = (list 1))))
1628 (pass-if (equal? '(1 2) (lset-difference! = (list 1 2))))
1630 (pass-if (equal? '() (lset-difference! = (list ) '(3))))
1631 (pass-if (equal? '() (lset-difference! = (list 3) '(3))))
1632 (pass-if (equal? '(1) (lset-difference! = (list 1 3) '(3))))
1633 (pass-if (equal? '(1) (lset-difference! = (list 3 1) '(3))))
1634 (pass-if (equal? '(1) (lset-difference! = (list 1 3 3) '(3))))
1635 (pass-if (equal? '(1) (lset-difference! = (list 3 1 3) '(3))))
1636 (pass-if (equal? '(1) (lset-difference! = (list 3 3 1) '(3))))
1638 (pass-if (equal? '(1) (lset-difference! = (list 1 2 3) '(2 3))))
1639 (pass-if (equal? '(1) (lset-difference! = (list 1 2 3) '(3 2))))
1640 (pass-if (equal? '(1) (lset-difference! = (list 1 2 3) '(3) '(2))))
1641 (pass-if (equal? '(1) (lset-difference! = (list 1 2 3) '(2) '(3))))
1642 (pass-if (equal? '(1) (lset-difference! = (list 1 2 3) '(2) '(2 3))))
1643 (pass-if (equal? '(1) (lset-difference! = (list 1 2 3) '(2) '(3 2))))
1645 (pass-if (equal? '(1 2) (lset-difference! = (list 1 2 3) '(3) '(3))))
1646 (pass-if (equal? '(1 2) (lset-difference! = (list 1 3 2) '(3) '(3))))
1647 (pass-if (equal? '(1 2) (lset-difference! = (list 3 1 2) '(3) '(3))))
1649 (pass-if (equal? '(1 2 3) (lset-difference! = (list 1 2 3 4) '(4))))
1650 (pass-if (equal? '(1 2 3) (lset-difference! = (list 1 2 4 3) '(4))))
1651 (pass-if (equal? '(1 2 3) (lset-difference! = (list 1 4 2 3) '(4))))
1652 (pass-if (equal? '(1 2 3) (lset-difference! = (list 4 1 2 3) '(4))))
1654 (pass-if (equal? '(1 2) (lset-difference! = (list 1 2 3 4) '(4) '(3))))
1655 (pass-if (equal? '(1 2) (lset-difference! = (list 1 3 2 4) '(4) '(3))))
1656 (pass-if (equal? '(1 2) (lset-difference! = (list 3 1 2 4) '(4) '(3))))
1657 (pass-if (equal? '(1 2) (lset-difference! = (list 1 3 4 2) '(4) '(3))))
1658 (pass-if (equal? '(1 2) (lset-difference! = (list 3 1 4 2) '(4) '(3))))
1659 (pass-if (equal? '(1 2) (lset-difference! = (list 3 4 1 2) '(4) '(3)))))
1662 ;; lset-diff+intersection
1665 (with-test-prefix "lset-diff+intersection"
1667 (pass-if "called arg order"
1669 (lset-diff+intersection (lambda (x y)
1670 (set! good (and (= x 1) (= y 2)))
1676 ;; lset-diff+intersection!
1679 (with-test-prefix "lset-diff+intersection"
1681 (pass-if "called arg order"
1683 (lset-diff+intersection (lambda (x y)
1684 (set! good (and (= x 1) (= y 2)))
1690 ;; lset-intersection
1693 (with-test-prefix "lset-intersection"
1695 (pass-if "called arg order"
1697 (lset-intersection (lambda (x y)
1698 (set! good (and (= x 1) (= y 2)))
1704 ;; lset-intersection!
1707 (with-test-prefix "lset-intersection"
1709 (pass-if "called arg order"
1711 (lset-intersection (lambda (x y)
1712 (set! good (and (= x 1) (= y 2)))
1721 (with-test-prefix "lset-union"
1724 (eq? '() (lset-union eq?)))
1727 (equal? '(1 2 3) (lset-union eq? '(1 2 3))))
1730 (equal? '() (lset-union eq? '() '())))
1732 (pass-if "'() '(1 2 3)"
1733 (equal? '(1 2 3) (lset-union eq? '() '(1 2 3))))
1735 (pass-if "'(1 2 3) '()"
1736 (equal? '(1 2 3) (lset-union eq? '(1 2 3) '())))
1738 (pass-if "'(1 2 3) '(4 3 5)"
1739 (equal? '(5 4 1 2 3) (lset-union eq? '(1 2 3) '(4 3 5))))
1741 (pass-if "'(1 2 3) '(4) '(3 5))"
1742 (equal? '(5 4 1 2 3) (lset-union eq? '(1 2 3) '(4) '(3 5))))
1744 ;; in guile 1.6.7 and earlier, `=' was called with the arguments the wrong
1746 (pass-if "called arg order"
1748 (lset-union (lambda (x y)
1749 (set! good (and (= x 1) (= y 2)))
1758 (with-test-prefix "member"
1760 (pass-if-exception "no args" exception:wrong-num-args
1763 (pass-if-exception "one arg" exception:wrong-num-args
1766 (pass-if "1 (1 2 3)"
1767 (let ((lst '(1 2 3)))
1768 (eq? lst (member 1 lst))))
1770 (pass-if "2 (1 2 3)"
1771 (let ((lst '(1 2 3)))
1772 (eq? (cdr lst) (member 2 lst))))
1774 (pass-if "3 (1 2 3)"
1775 (let ((lst '(1 2 3)))
1776 (eq? (cddr lst) (member 3 lst))))
1778 (pass-if "4 (1 2 3)"
1779 (let ((lst '(1 2 3)))
1780 (eq? #f (member 4 lst))))
1782 (pass-if "called arg order"
1784 (member 1 '(2) (lambda (x y)
1785 (set! good (and (eqv? 1 x)
1793 (with-test-prefix "ninth"
1794 (pass-if-exception "() -1" exception:out-of-range
1795 (ninth '(a b c d e f g h)))
1796 (pass-if (eq? 'i (ninth '(a b c d e f g h i))))
1797 (pass-if (eq? 'i (ninth '(a b c d e f g h i j)))))
1804 (with-test-prefix "not-pair?"
1806 (eq? #t (not-pair? 123)))
1808 (eq? #f (not-pair? '(x . y))))
1810 (eq? #t (not-pair? 'x))))
1816 (with-test-prefix "take"
1819 (null? (take '() 0)))
1822 (null? (take '(a) 0)))
1825 (null? (take '() 0)))
1827 (pass-if "'(a b c) 0"
1828 (null? (take '() 0)))
1833 (and (equal? '(a) got)
1834 (not (eq? lst got)))))
1840 (pass-if "'(a b c) 1"
1847 (and (equal? '(a b) got)
1848 (not (eq? lst got)))))
1850 (pass-if "'(a b c) 2"
1854 (pass-if "circular '(a) 0"
1856 (take (circular-list 'a) 0)))
1858 (pass-if "circular '(a) 1"
1860 (take (circular-list 'a) 1)))
1862 (pass-if "circular '(a) 2"
1864 (take (circular-list 'a) 2)))
1866 (pass-if "circular '(a b) 5"
1867 (equal? '(a b a b a)
1868 (take (circular-list 'a 'b) 5)))
1870 (pass-if "'(a . b) 1"
1874 (pass-if "'(a b . c) 1"
1876 (take '(a b . c) 1)))
1878 (pass-if "'(a b . c) 2"
1880 (take '(a b . c) 2))))
1886 (with-test-prefix "take-while"
1888 (pass-if (equal? '() (take-while odd? '())))
1889 (pass-if (equal? '(1) (take-while odd? '(1))))
1890 (pass-if (equal? '(1 3) (take-while odd? '(1 3))))
1891 (pass-if (equal? '(1 3 5) (take-while odd? '(1 3 5))))
1893 (pass-if (equal? '() (take-while odd? '(2))))
1894 (pass-if (equal? '(1) (take-while odd? '(1 2))))
1895 (pass-if (equal? '(1 3) (take-while odd? '(1 3 4))))
1897 (pass-if (equal? '() (take-while odd? '(2 1))))
1898 (pass-if (equal? '(1) (take-while odd? '(1 4 3))))
1899 (pass-if (equal? '() (take-while odd? '(4 1 3)))))
1905 (with-test-prefix "take-while!"
1907 (pass-if (equal? '() (take-while! odd? '())))
1908 (pass-if (equal? '(1) (take-while! odd? (list 1))))
1909 (pass-if (equal? '(1 3) (take-while! odd? (list 1 3))))
1910 (pass-if (equal? '(1 3 5) (take-while! odd? (list 1 3 5))))
1912 (pass-if (equal? '() (take-while! odd? (list 2))))
1913 (pass-if (equal? '(1) (take-while! odd? (list 1 2))))
1914 (pass-if (equal? '(1 3) (take-while! odd? (list 1 3 4))))
1916 (pass-if (equal? '() (take-while! odd? (list 2 1))))
1917 (pass-if (equal? '(1) (take-while! odd? (list 1 4 3))))
1918 (pass-if (equal? '() (take-while! odd? (list 4 1 3)))))
1924 (define (test-partition pred list kept-good dropped-good)
1925 (call-with-values (lambda ()
1926 (partition pred list))
1927 (lambda (kept dropped)
1928 (and (equal? kept kept-good)
1929 (equal? dropped dropped-good)))))
1931 (with-test-prefix "partition"
1933 (pass-if "with dropped tail"
1934 (test-partition even? '(1 2 3 4 5 6 7)
1935 '(2 4 6) '(1 3 5 7)))
1937 (pass-if "with kept tail"
1938 (test-partition even? '(1 2 3 4 5 6)
1941 (pass-if "with everything dropped"
1942 (test-partition even? '(1 3 5 7)
1945 (pass-if "with everything kept"
1946 (test-partition even? '(2 4 6)
1949 (pass-if "with empty list"
1950 (test-partition even? '()
1953 (pass-if "with reasonably long list"
1954 ;; the old implementation from SRFI-1 reference implementation
1955 ;; would signal a stack-overflow for a list of only 500 elements!
1956 (call-with-values (lambda ()
1958 (make-list 10000 1)))
1960 (and (= (length odd) 10000)
1961 (= (length even) 0))))))
1967 (define (test-partition! pred list kept-good dropped-good)
1968 (call-with-values (lambda ()
1969 (partition! pred list))
1970 (lambda (kept dropped)
1971 (and (equal? kept kept-good)
1972 (equal? dropped dropped-good)))))
1974 (with-test-prefix "partition!"
1976 (pass-if "with dropped tail"
1977 (test-partition! even? (list 1 2 3 4 5 6 7)
1978 '(2 4 6) '(1 3 5 7)))
1980 (pass-if "with kept tail"
1981 (test-partition! even? (list 1 2 3 4 5 6)
1984 (pass-if "with everything dropped"
1985 (test-partition! even? (list 1 3 5 7)
1988 (pass-if "with everything kept"
1989 (test-partition! even? (list 2 4 6)
1992 (pass-if "with empty list"
1993 (test-partition! even? '()
1996 (pass-if "with reasonably long list"
1997 ;; the old implementation from SRFI-1 reference implementation
1998 ;; would signal a stack-overflow for a list of only 500 elements!
1999 (call-with-values (lambda ()
2001 (make-list 10000 1)))
2003 (and (= (length odd) 10000)
2004 (= (length even) 0))))))
2010 (with-test-prefix "reduce"
2014 (ret (reduce (lambda (x prev)
2015 (set! calls (cons (list x prev) calls))
2018 (and (equal? calls '())
2023 (ret (reduce (lambda (x prev)
2024 (set! calls (cons (list x prev) calls))
2027 (and (equal? calls '())
2030 (pass-if "two elems"
2032 (ret (reduce (lambda (x prev)
2033 (set! calls (cons (list x prev) calls))
2036 (and (equal? calls '((3 2)))
2039 (pass-if "three elems"
2041 (ret (reduce (lambda (x prev)
2042 (set! calls (cons (list x prev) calls))
2045 (and (equal? calls '((4 3)
2049 (pass-if "four elems"
2051 (ret (reduce (lambda (x prev)
2052 (set! calls (cons (list x prev) calls))
2055 (and (equal? calls '((5 4)
2064 (with-test-prefix "reduce-right"
2068 (ret (reduce-right (lambda (x prev)
2069 (set! calls (cons (list x prev) calls))
2072 (and (equal? calls '())
2077 (ret (reduce-right (lambda (x prev)
2078 (set! calls (cons (list x prev) calls))
2081 (and (equal? calls '())
2084 (pass-if "two elems"
2086 (ret (reduce-right (lambda (x prev)
2087 (set! calls (cons (list x prev) calls))
2090 (and (equal? calls '((2 3)))
2093 (pass-if "three elems"
2095 (ret (reduce-right (lambda (x prev)
2096 (set! calls (cons (list x prev) calls))
2099 (and (equal? calls '((2 3)
2103 (pass-if "four elems"
2105 (ret (reduce-right (lambda (x prev)
2106 (set! calls (cons (list x prev) calls))
2109 (and (equal? calls '((2 3)
2118 (with-test-prefix "remove"
2120 (pass-if (equal? '() (remove odd? '())))
2121 (pass-if (equal? '() (remove odd? '(1))))
2122 (pass-if (equal? '(2) (remove odd? '(2))))
2124 (pass-if (equal? '() (remove odd? '(1 3))))
2125 (pass-if (equal? '(2) (remove odd? '(2 3))))
2126 (pass-if (equal? '(2) (remove odd? '(1 2))))
2127 (pass-if (equal? '(2 4) (remove odd? '(2 4))))
2129 (pass-if (equal? '() (remove odd? '(1 3 5))))
2130 (pass-if (equal? '(2) (remove odd? '(2 3 5))))
2131 (pass-if (equal? '(2) (remove odd? '(1 2 5))))
2132 (pass-if (equal? '(2 4) (remove odd? '(2 4 5))))
2134 (pass-if (equal? '(6) (remove odd? '(1 3 6))))
2135 (pass-if (equal? '(2 6) (remove odd? '(2 3 6))))
2136 (pass-if (equal? '(2 6) (remove odd? '(1 2 6))))
2137 (pass-if (equal? '(2 4 6) (remove odd? '(2 4 6)))))
2143 (with-test-prefix "remove!"
2145 (pass-if (equal? '() (remove! odd? '())))
2146 (pass-if (equal? '() (remove! odd? (list 1))))
2147 (pass-if (equal? '(2) (remove! odd? (list 2))))
2149 (pass-if (equal? '() (remove! odd? (list 1 3))))
2150 (pass-if (equal? '(2) (remove! odd? (list 2 3))))
2151 (pass-if (equal? '(2) (remove! odd? (list 1 2))))
2152 (pass-if (equal? '(2 4) (remove! odd? (list 2 4))))
2154 (pass-if (equal? '() (remove! odd? (list 1 3 5))))
2155 (pass-if (equal? '(2) (remove! odd? (list 2 3 5))))
2156 (pass-if (equal? '(2) (remove! odd? (list 1 2 5))))
2157 (pass-if (equal? '(2 4) (remove! odd? (list 2 4 5))))
2159 (pass-if (equal? '(6) (remove! odd? (list 1 3 6))))
2160 (pass-if (equal? '(2 6) (remove! odd? (list 2 3 6))))
2161 (pass-if (equal? '(2 6) (remove! odd? (list 1 2 6))))
2162 (pass-if (equal? '(2 4 6) (remove! odd? (list 2 4 6)))))
2168 (with-test-prefix "seventh"
2169 (pass-if-exception "() -1" exception:out-of-range
2170 (seventh '(a b c d e f)))
2171 (pass-if (eq? 'g (seventh '(a b c d e f g))))
2172 (pass-if (eq? 'g (seventh '(a b c d e f g h)))))
2178 (with-test-prefix "sixth"
2179 (pass-if-exception "() -1" exception:out-of-range
2180 (sixth '(a b c d e)))
2181 (pass-if (eq? 'f (sixth '(a b c d e f))))
2182 (pass-if (eq? 'f (sixth '(a b c d e f g)))))
2188 (with-test-prefix "split-at"
2190 (define (equal-values? lst thunk)
2191 (call-with-values thunk
2195 (pass-if-exception "() -1" exception:out-of-range
2197 (pass-if (equal-values? '(() ())
2198 (lambda () (split-at '() 0))))
2199 (pass-if-exception "() 1" exception:wrong-type-arg
2202 (pass-if-exception "(1) -1" exception:out-of-range
2204 (pass-if (equal-values? '(() (1)) (lambda () (split-at '(1) 0))))
2205 (pass-if (equal-values? '((1) ()) (lambda () (split-at '(1) 1))))
2206 (pass-if-exception "(1) 2" exception:wrong-type-arg
2209 (pass-if-exception "(4 5) -1" exception:out-of-range
2210 (split-at '(4 5) -1))
2211 (pass-if (equal-values? '(() (4 5)) (lambda () (split-at '(4 5) 0))))
2212 (pass-if (equal-values? '((4) (5)) (lambda () (split-at '(4 5) 1))))
2213 (pass-if (equal-values? '((4 5) ()) (lambda () (split-at '(4 5) 2))))
2214 (pass-if-exception "(4 5) 3" exception:wrong-type-arg
2215 (split-at '(4 5) 3))
2217 (pass-if-exception "(4 5 6) -1" exception:out-of-range
2218 (split-at '(4 5 6) -1))
2219 (pass-if (equal-values? '(() (4 5 6)) (lambda () (split-at '(4 5 6) 0))))
2220 (pass-if (equal-values? '((4) (5 6)) (lambda () (split-at '(4 5 6) 1))))
2221 (pass-if (equal-values? '((4 5) (6)) (lambda () (split-at '(4 5 6) 2))))
2222 (pass-if (equal-values? '((4 5 6) ()) (lambda () (split-at '(4 5 6) 3))))
2223 (pass-if-exception "(4 5 6) 4" exception:wrong-type-arg
2224 (split-at '(4 5 6) 4)))
2230 (with-test-prefix "split-at!"
2232 (define (equal-values? lst thunk)
2233 (call-with-values thunk
2237 (pass-if-exception "() -1" exception:out-of-range
2239 (pass-if (equal-values? '(() ())
2240 (lambda () (split-at! '() 0))))
2241 (pass-if-exception "() 1" exception:wrong-type-arg
2244 (pass-if-exception "(1) -1" exception:out-of-range
2245 (split-at! (list 1) -1))
2246 (pass-if (equal-values? '(() (1)) (lambda () (split-at! (list 1) 0))))
2247 (pass-if (equal-values? '((1) ()) (lambda () (split-at! (list 1) 1))))
2248 (pass-if-exception "(1) 2" exception:wrong-type-arg
2249 (split-at! (list 1) 2))
2251 (pass-if-exception "(4 5) -1" exception:out-of-range
2252 (split-at! (list 4 5) -1))
2253 (pass-if (equal-values? '(() (4 5)) (lambda () (split-at! (list 4 5) 0))))
2254 (pass-if (equal-values? '((4) (5)) (lambda () (split-at! (list 4 5) 1))))
2255 (pass-if (equal-values? '((4 5) ()) (lambda () (split-at! (list 4 5) 2))))
2256 (pass-if-exception "(4 5) 3" exception:wrong-type-arg
2257 (split-at! (list 4 5) 3))
2259 (pass-if-exception "(4 5 6) -1" exception:out-of-range
2260 (split-at! (list 4 5 6) -1))
2261 (pass-if (equal-values? '(() (4 5 6)) (lambda () (split-at! (list 4 5 6) 0))))
2262 (pass-if (equal-values? '((4) (5 6)) (lambda () (split-at! (list 4 5 6) 1))))
2263 (pass-if (equal-values? '((4 5) (6)) (lambda () (split-at! (list 4 5 6) 2))))
2264 (pass-if (equal-values? '((4 5 6) ()) (lambda () (split-at! (list 4 5 6) 3))))
2265 (pass-if-exception "(4 5 6) 4" exception:wrong-type-arg
2266 (split-at! (list 4 5 6) 4)))
2272 (with-test-prefix "span"
2274 (define (test-span lst want-v1 want-v2)
2277 (span positive? lst))
2278 (lambda (got-v1 got-v2)
2279 (and (equal? got-v1 want-v1)
2280 (equal? got-v2 want-v2)))))
2283 (test-span '() '() '()))
2286 (test-span '(1) '(1) '()))
2289 (test-span '(-1) '() '(-1)))
2292 (test-span '(1 2) '(1 2) '()))
2295 (test-span '(-1 1) '() '(-1 1)))
2298 (test-span '(1 -1) '(1) '(-1)))
2301 (test-span '(-1 -2) '() '(-1 -2)))
2304 (test-span '(1 2 3) '(1 2 3) '()))
2307 (test-span '(-1 1 2) '() '(-1 1 2)))
2310 (test-span '(1 -1 2) '(1) '(-1 2)))
2313 (test-span '(-1 -2 1) '() '(-1 -2 1)))
2316 (test-span '(1 2 -1) '(1 2) '(-1)))
2319 (test-span '(-1 1 -2) '() '(-1 1 -2)))
2322 (test-span '(1 -1 -2) '(1) '(-1 -2)))
2325 (test-span '(-1 -2 -3) '() '(-1 -2 -3))))
2331 (with-test-prefix "span!"
2333 (define (test-span! lst want-v1 want-v2)
2336 (span! positive? lst))
2337 (lambda (got-v1 got-v2)
2338 (and (equal? got-v1 want-v1)
2339 (equal? got-v2 want-v2)))))
2342 (test-span! '() '() '()))
2345 (test-span! (list 1) '(1) '()))
2348 (test-span! (list -1) '() '(-1)))
2351 (test-span! (list 1 2) '(1 2) '()))
2354 (test-span! (list -1 1) '() '(-1 1)))
2357 (test-span! (list 1 -1) '(1) '(-1)))
2360 (test-span! (list -1 -2) '() '(-1 -2)))
2363 (test-span! (list 1 2 3) '(1 2 3) '()))
2366 (test-span! (list -1 1 2) '() '(-1 1 2)))
2369 (test-span! (list 1 -1 2) '(1) '(-1 2)))
2372 (test-span! (list -1 -2 1) '() '(-1 -2 1)))
2375 (test-span! (list 1 2 -1) '(1 2) '(-1)))
2378 (test-span! (list -1 1 -2) '() '(-1 1 -2)))
2381 (test-span! (list 1 -1 -2) '(1) '(-1 -2)))
2384 (test-span! (list -1 -2 -3) '() '(-1 -2 -3))))
2390 (with-test-prefix "take!"
2392 (pass-if-exception "() -1" exception:out-of-range
2394 (pass-if (equal? '() (take! '() 0)))
2395 (pass-if-exception "() 1" exception:wrong-type-arg
2398 (pass-if-exception "(1) -1" exception:out-of-range
2400 (pass-if (equal? '() (take! '(1) 0)))
2401 (pass-if (equal? '(1) (take! '(1) 1)))
2402 (pass-if-exception "(1) 2" exception:wrong-type-arg
2405 (pass-if-exception "(4 5) -1" exception:out-of-range
2407 (pass-if (equal? '() (take! '(4 5) 0)))
2408 (pass-if (equal? '(4) (take! '(4 5) 1)))
2409 (pass-if (equal? '(4 5) (take! '(4 5) 2)))
2410 (pass-if-exception "(4 5) 3" exception:wrong-type-arg
2413 (pass-if-exception "(4 5 6) -1" exception:out-of-range
2414 (take! '(4 5 6) -1))
2415 (pass-if (equal? '() (take! '(4 5 6) 0)))
2416 (pass-if (equal? '(4) (take! '(4 5 6) 1)))
2417 (pass-if (equal? '(4 5) (take! '(4 5 6) 2)))
2418 (pass-if (equal? '(4 5 6) (take! '(4 5 6) 3)))
2419 (pass-if-exception "(4 5 6) 4" exception:wrong-type-arg
2420 (take! '(4 5 6) 4)))
2427 (with-test-prefix "take-right"
2429 (pass-if-exception "() -1" exception:out-of-range
2430 (take-right '() -1))
2431 (pass-if (equal? '() (take-right '() 0)))
2432 (pass-if-exception "() 1" exception:wrong-type-arg
2435 (pass-if-exception "(1) -1" exception:out-of-range
2436 (take-right '(1) -1))
2437 (pass-if (equal? '() (take-right '(1) 0)))
2438 (pass-if (equal? '(1) (take-right '(1) 1)))
2439 (pass-if-exception "(1) 2" exception:wrong-type-arg
2440 (take-right '(1) 2))
2442 (pass-if-exception "(4 5) -1" exception:out-of-range
2443 (take-right '(4 5) -1))
2444 (pass-if (equal? '() (take-right '(4 5) 0)))
2445 (pass-if (equal? '(5) (take-right '(4 5) 1)))
2446 (pass-if (equal? '(4 5) (take-right '(4 5) 2)))
2447 (pass-if-exception "(4 5) 3" exception:wrong-type-arg
2448 (take-right '(4 5) 3))
2450 (pass-if-exception "(4 5 6) -1" exception:out-of-range
2451 (take-right '(4 5 6) -1))
2452 (pass-if (equal? '() (take-right '(4 5 6) 0)))
2453 (pass-if (equal? '(6) (take-right '(4 5 6) 1)))
2454 (pass-if (equal? '(5 6) (take-right '(4 5 6) 2)))
2455 (pass-if (equal? '(4 5 6) (take-right '(4 5 6) 3)))
2456 (pass-if-exception "(4 5 6) 4" exception:wrong-type-arg
2457 (take-right '(4 5 6) 4)))
2463 (with-test-prefix "tenth"
2464 (pass-if-exception "() -1" exception:out-of-range
2465 (tenth '(a b c d e f g h i)))
2466 (pass-if (eq? 'j (tenth '(a b c d e f g h i j))))
2467 (pass-if (eq? 'j (tenth '(a b c d e f g h i j k)))))
2473 (with-test-prefix "xcons"
2474 (pass-if (equal? '(y . x) (xcons 'x 'y))))