diff --git a/test-suite/tests/srfi-1.test b/test-suite/tests/srfi-1.test index 3b3b7add7..dd55c1335 100644 --- a/test-suite/tests/srfi-1.test +++ b/test-suite/tests/srfi-1.test @@ -200,7 +200,80 @@ (pass-if "(1) (2) / 9 9" (equal? '(1 2) (append-map noop '((1) (2)) '(9 9)))))) - + +;; +;; append-reverse +;; + +(with-test-prefix "append-reverse" + + ;; return a list which is the cars and cdrs of LST + (define (list-contents lst) + (if (null? lst) + '() + (cons* (car lst) (cdr lst) (list-contents (cdr lst))))) + + (define (valid-append-reverse revhead tail want) + (let ((revhead-contents (list-contents revhead)) + (got (append-reverse revhead tail))) + (and (equal? got want) + ;; revhead unchanged + (equal? revhead-contents (list-contents revhead))))) + + (pass-if-exception "too few args (0)" exception:wrong-num-args + (append-reverse)) + + (pass-if-exception "too few args (1)" exception:wrong-num-args + (append-reverse '(x))) + + (pass-if-exception "too many args (3)" exception:wrong-num-args + (append-reverse '() '() #f)) + + (pass-if (valid-append-reverse '() '() '())) + (pass-if (valid-append-reverse '() '(1 2 3) '(1 2 3))) + + (pass-if (valid-append-reverse '(1) '() '(1))) + (pass-if (valid-append-reverse '(1) '(2) '(1 2))) + (pass-if (valid-append-reverse '(1) '(2 3) '(1 2 3))) + + (pass-if (valid-append-reverse '(1 2) '() '(2 1))) + (pass-if (valid-append-reverse '(1 2) '(3) '(2 1 3))) + (pass-if (valid-append-reverse '(1 2) '(3 4) '(2 1 3 4))) + + (pass-if (valid-append-reverse '(1 2 3) '() '(3 2 1))) + (pass-if (valid-append-reverse '(1 2 3) '(4) '(3 2 1 4))) + (pass-if (valid-append-reverse '(1 2 3) '(4 5) '(3 2 1 4 5)))) + +;; +;; append-reverse! +;; + +(with-test-prefix "append-reverse!" + + (pass-if-exception "too few args (0)" exception:wrong-num-args + (append-reverse!)) + + (pass-if-exception "too few args (1)" exception:wrong-num-args + (append-reverse! '(x))) + + (pass-if-exception "too many args (3)" exception:wrong-num-args + (append-reverse! '() '() #f)) + + (pass-if (equal? '() (append-reverse! '() '()))) + (pass-if (equal? '(1 2 3) (append-reverse! '() '(1 2 3)))) + + (pass-if (equal? '(1) (append-reverse! '(1) '()))) + (pass-if (equal? '(1 2) (append-reverse! '(1) '(2)))) + (pass-if (equal? '(1 2 3) (append-reverse! '(1) '(2 3)))) + + (pass-if (equal? '(2 1) (append-reverse! '(1 2) '()))) + (pass-if (equal? '(2 1 3) (append-reverse! '(1 2) '(3)))) + (pass-if (equal? '(2 1 3 4) (append-reverse! '(1 2) '(3 4)))) + + (pass-if (equal? '(3 2 1) (append-reverse! '(1 2 3) '()))) + (pass-if (equal? '(3 2 1 4) (append-reverse! '(1 2 3) '(4)))) + (pass-if (equal? '(3 2 1 4 5) (append-reverse! '(1 2 3) '(4 5))))) + ;; ;; assoc ;;