1 ;; Tests for list functions
4 (test (equal (cons 1 2) '(1 . 2)))
5 (test (equal (cons 1 nil) '(1)))
6 (test (equal (cons nil 2) '(NIL . 2)))
7 (test (equal (cons nil nil) '(NIL)))
8 (test (equal (cons 1 (cons 2 (cons 3 (cons 4 nil)))) '(1 2 3 4)))
9 (test (equal (cons 'a 'b) '(A . B)))
10 (test (equal (cons 'a (cons 'b (cons 'c '()))) '(A B C)))
11 (test (equal (cons 'a '(b c d)) '(A B C D)))
14 (test (not (consp 'nil)))
15 (test (not (consp nil)))
16 (test (not (consp ())))
17 (test (not (consp '())))
18 (test (consp (cons 1 2)))
22 (test (not (atom (cons 1 2))))
28 (let ((some-list (list* 'one 'two 'three 'four)))
29 (test (equal (rplaca some-list 'uno) '(UNO TWO THREE . FOUR)))
30 (test (equal some-list '(UNO TWO THREE . FOUR))))
33 (let ((some-list (list* 'one 'two 'three 'four)))
34 (test (equal (rplacd (last some-list) (list 'IV)) '(THREE IV)))
35 (test (equal some-list '(ONE TWO THREE IV))))
38 (test (let* ((foo (list '(1 2) '(3 4)))
39 (bar (copy-tree foo)))
40 ;; (SETF (CAR (CAR FOO)) 0) doesn't work in the test for some reason,
41 ;; despite working fine in the REPL
43 (not (= (car (car foo))
47 (test (tree-equal '(1 2 3) '(1 2 3)))
48 (test (tree-equal '(1 (2 (3 4) 5) 6) '(1 (2 (3 4) 5) 6)))
49 (test (tree-equal (cons 1 2) (cons 2 3)
50 :test (lambda (a b) (not (= a b)))))
53 (let ((nums '(1 2 3 4 5 6 7 8 9 10)))
54 (test (= (first nums) 1))
55 (test (= (second nums) 2))
56 (test (= (third nums) 3))
57 (test (= (fourth nums) 4))
58 (test (= (fifth nums) 5))
59 (test (= (sixth nums) 6))
60 (test (= (seventh nums) 7))
61 (test (= (eighth nums) 8))
62 (test (= (ninth nums) 9))
63 (test (= (tenth nums) 10)))
66 (let* ((a (list 1 2 3))
70 (test (tailp 'a (cons 'b 'a)))
73 (test (equal '((1 . 2) (3 . 4))
74 (acons 1 2 '((3 . 4)))))
75 (test (equal '((1 . 2)) (acons 1 2 ())))
78 (test (equal '((1 . 3) (0 . 2))
79 (pairlis '(0 1) '(2 3))))
80 (test (equal '((1 . 2) (a . b))
81 (pairlis '(1) '(2) '((a . b)))))
84 (let* ((alist '((1 . 2) (3 . 4)))
85 (copy (copy-alist alist)))
86 (test (not (eql alist copy)))
87 (test (not (eql (car alist) (car copy))))
88 (test (equal alist copy)))
91 (let ((alist '((1 . 2) (3 . 4))))
92 (test (equal (assoc 1 alist) '(1 . 2)))
93 (test (equal (rassoc 2 alist) '(1 . 2)))
94 (test (not (assoc 2 alist)))
95 (test (not (rassoc 1 alist))))
98 (test (equal (member 2 '(1 2 3)) '(2 3)))
99 (test (not (member 4 '(1 2 3))))
100 (test (equal (member 4 '((1 . 2) (3 . 4)) :key #'cdr) '((3 . 4))))
101 (test (member '(2) '((1) (2) (3)) :test #'equal))
104 (test (equal (adjoin 1 '(2 3)) '(1 2 3)))
105 (test (equal (adjoin 1 '(1 2 3)) '(1 2 3)))
106 (test (equal (adjoin '(1) '((1) (2)) :test #'equal) '((1) (2))))
109 (test (equal (intersection '(1 2) '(2 3)) '(2)))
110 (test (not (intersection '(1 2 3) '(4 5 6))))
111 (test (equal (intersection '((1) (2)) '((2) (3)) :test #'equal) '((2))))
116 (test (let* ((foo '(1 2 3))
122 (test (equal (mapcar #'+ '(1 2) '(3) '(4 5 6)) '(8)))
125 (test (equal (mapc #'+ '(1 2) '(3) '(4 5 6)) '(1 2)))
127 (mapc (lambda (x y z) (print (list x y z)) (push (+ x y z) foo)) '(1 2) '(3) '(4 5 6))