1
0
mirror of synced 2026-05-03 14:49:45 +00:00
Files
Interlisp.medley/internal/test/LANGUAGE/AUTO/15-2-APPEND.TEST

125 lines
5.5 KiB
Plaintext

;; Function To Be Tested: append
;;
;; Source: Steele's book Section 15.2: Lists Page: 268
;;
;; Created By: Karin M. Sye
;;
;; Creation Date: June 26,1986
;;
;; Last Update: June 26,1986
;;
;; Filed As: {eris}<lispcore>cml>test>append.test
;;
;;
;; Syntax: APPEND &rest lists
;;
;; Function Description: APPEND concatenates its arguments and returns a list.
;;
;; Argument(s): {list}* or a lisp object
;;
;; Returns: a list or a lisp object
;;
(do-test "test append - example copied from page 268 of CLtL"
(and
(EQUAL (APPEND '(A B C) '(D E F) NIL '(G))
'(A B C D E F G))
(EQUAL (APPEND '(A B C) 'D) '(A B C . D))
)
)
(do-test "test append0"
(and (eq (append nil nil nil nil () () () (not t) (and nil t) (null 'a)) nil)
(equal (append '(a b c) '(1 2 3 4) (list 10 20 30 40) `(aa bb cc dd) (last '(z x w q)))
'(a b c 1 2 3 4 10 20 30 40 aa bb cc dd q))
(equal (funcall #'append (rest '(a b c d e)) (nthcdr 4 '(1 2 3)) (make-list 10) (butlast '(a b c)))
'(b c d e nil nil nil nil nil nil nil nil nil nil a b))
(equal (setq a (append (cons 1 (cons 2 (cons 3 (cons 4 '()))))
(cons 11 (cons 22 (cons 33 (cons 44 '()))))
'(((((111 222 333 444 555)))))))
'(1 2 3 4 11 22 33 44 ((((111 222 333 444 555))))))
(equal (append a a a a a a a a a a a a a a a)
'(1 2 3 4 11 22 33 44 ((((111 222 333 444 555)))) 1 2 3 4 11 22 33 44 ((((111 222 333 444 555))))
1 2 3 4 11 22 33 44 ((((111 222 333 444 555)))) 1 2 3 4 11 22 33 44 ((((111 222 333 444 555))))
1 2 3 4 11 22 33 44 ((((111 222 333 444 555)))) 1 2 3 4 11 22 33 44 ((((111 222 333 444 555))))
1 2 3 4 11 22 33 44 ((((111 222 333 444 555)))) 1 2 3 4 11 22 33 44 ((((111 222 333 444 555))))
1 2 3 4 11 22 33 44 ((((111 222 333 444 555)))) 1 2 3 4 11 22 33 44 ((((111 222 333 444 555))))
1 2 3 4 11 22 33 44 ((((111 222 333 444 555)))) 1 2 3 4 11 22 33 44 ((((111 222 333 444 555))))
1 2 3 4 11 22 33 44 ((((111 222 333 444 555)))) 1 2 3 4 11 22 33 44 ((((111 222 333 444 555))))
1 2 3 4 11 22 33 44 ((((111 222 333 444 555)))) )) ))
(do-test "test append - nested append functions"
(and
(equal (append (list #\a #\b #\c #\d #\q #\w #\e)
(append '("append testing") (list 1 2) (append (cdr '(2 4 6 8)) (append (cddr '(1 3 5 7))) (append '(stop)))))
'(#\a #\b #\c #\d #\q #\w #\e "append testing" 1 2 4 6 8 5 7 stop))
;;
(equal (append '(1) (append '(2) (append '(3) (append '(4) (append '((5)) (append '(6) (append '(7) (append '(8) (append '(9)
(append '((10)) (append '(11) (append '(12) (append '(13) (append '(14) (append '((15)) (append '(16)
(append '(17)
(append '(18) (append '(19) (append '((20))))))))))))))))))))))
'(1 2 3 4 (5) 6 7 8 9 (10) 11 12 13 14 (15) 16 17 18 19 (20)))))
(do-test "test append - append copies the top-level list structure of each of its arguments except the last one"
(LET* ((a (list 1 2 3 4 5 6 7 8 9 10))
(aa (list 11 22 33))
(aaa (list 111 222 333 444 555))
(b (append a aa aaa)))
(and
(equal b '(1 2 3 4 5 6 7 8 9 10 11 22 33 111 222 333 444 555))
;
(rplacd (last a) '(11))
(equal a '(1 2 3 4 5 6 7 8 9 10 11))
(equal b '(1 2 3 4 5 6 7 8 9 10 11 22 33 111 222 333 444 555))
;
(rplacd (last aa) '(44))
(equal aa '(11 22 33 44))
(equal b '(1 2 3 4 5 6 7 8 9 10 11 22 33 111 222 333 444 555))
;
(rplacd (last aaa) '(666))
(equal aaa '(111 222 333 444 555 666))
(equal b '(1 2 3 4 5 6 7 8 9 10 11 22 33 111 222 333 444 555 666))
;;
;;
(progn (setq a (list 1 2 3 4 5 6 7 8 9 10)
b (append a))
(and (equal b '(1 2 3 4 5 6 7 8 9 10))
(rplacd (last a) '(22))
(equal b '(1 2 3 4 5 6 7 8 9 10 22)) ))
;;
;;
(progn (setq a (list 1 2 3 4 5 6 7 8 9 10)
b (append a nil))
(and (equal b '(1 2 3 4 5 6 7 8 9 10))
(rplacd (last a) '(22))
(equal a '(1 2 3 4 5 6 7 8 9 10 22))
(equal b '(1 2 3 4 5 6 7 8 9 10)) ))
;;
;;
(progn (setq a (list 2 4 '(6 8) 10)
b (append a nil))
(and (equal b '(2 4 (6 8) 10))
(rplacd (caddr a) '(9))
(equal a '(2 4 (6 9) 10))
(equal b '(2 4 (6 9) 10)) ))
)
))
(do-test "test append - The last argument may be any List object, which become the tail end of the constructed list"
(and (equal (append '(1 2 3 4) (+ 1 4)) '(1 2 3 4 . 5))
;
(equal (append '(nil) (list 'a 'b 'c)) '(nil a b c))
;
(equal (append '(1 2) "string") '(1 2 . "string"))
;
(progn (setq a (append '(1) #'(lambda (x) (gcd x 3))))
(= (funcall (cdr a) 6) 3))
;
(equal (append '(2) #\k) '(2 . #\k))
;
(prog2 (setq a (append '(3) '#(a b c d)))
(vectorp (cdr a)))
)
)
;;
;;
STOP