1 ; Functions used as :KEY argument in tests
2 (defvar halve (lambda (x) (/ x 2)))
3 (defvar double (lambda (x) (* x 2)))
6 (test (find 1 #(2 1 3)))
7 (test (find 1 '(2 1 3)))
8 (test (not (find 1 #(2 2 2))))
9 (test (not (find 1 '(2 2 2))))
10 (test (not (find 1 #(1 1 1) :test-not #'=)))
11 (test (not (find 1 '(1 1 1) :test-not #'=)))
12 (test (not (find 1 #(1 2 3) :key double)))
13 (test (not (find 1 '(1 2 3) :key double)))
16 (test (not (find 1 (remove 1 #(1 2 3 1)))))
17 (test (not (find 1 (remove 1 '(1 2 3 1)))))
18 (test (not (find 2 (remove 1 #(1 2 3 1) :key halve))))
19 (test (not (find 2 (remove 1 '(1 2 3 1) :key halve))))
20 ;; TODO: Rewrite this test when EQUALP exists and works on vectors
21 (test (equal (length (remove '(1 2) #((1 2) (1 2)) :test #'equal)) 0))
22 (test (null (remove '(1 2) '((1 2) (1 2)) :test #'equal)))
23 (test (find 2 (remove 2 #(1 2 3) :test-not #'=)))
24 (test (find 2 (remove 2 '(1 2 3) :test-not #'=)))
27 (test (= (position 1 #(1 2 3)) 0))
28 (test (= (position 1 '(1 2 3)) 0))
29 (test (= (position 1 #(1 2 3 1)) 0))
30 (test (= (position 1 '(1 2 3 1)) 0))
31 (test (not (position 1 #(2 3 4))))
32 (test (not (position 1 '(2 3 4))))
33 (test (= (position 1 '(1 2 3) :key halve) 1))
34 (test (= (position 1 #(1 2 3) :key halve) 1))
35 (test (= (position '(1 2) '((1 2) (3 4)) :test #'equal) 0))
36 (test (= (position '(1 2) #((1 2) (3 4)) :test #'equal) 0))
37 (test (= (position 1 #(1 1 3) :test-not #'=) 2))
38 (test (= (position 1 '(1 1 3) :test-not #'=) 2))
40 ;; POSITION-IF, POSITION-IF-NOT
41 (test (= 2 (position-if #'oddp '((1) (2) (3) (4)) :start 1 :key #'car)))
42 (test (= 4 (position-if-not #'integerp '(1 2 3 4 X)))) ;; (hyperspec example used "5.0", but we don't have a full numeric tower yet!)
45 (test (equal (remove-if #'zerop '(1 0 2 0 3)) '(1 2 3)))
46 (test (equal (remove-if-not #'zerop '(1 0 2 0 3)) '(0 0)))
47 ;; TODO: Rewrite these tests when EQUALP exists and works on vectors
48 (let ((v1 (remove-if #'zerop #(1 0 2 0 3))))
49 (test (and (= (aref v1 0) 1) (= (aref v1 1) 2) (= (aref v1 2) 3))))
50 (test (every #'zerop (remove-if-not #'zerop #(1 0 2 0 3))))
53 (let ((nums '(1 2 3 4 5)))
54 (test (equal (subseq nums 3) '(4 5)))
55 (test (equal (subseq nums 2 4) '(3 4)))
56 ; Test that nums hasn't been altered: SUBSEQ should construct fresh lists
57 (test (equal nums '(1 2 3 4 5))))
60 (test (equal (reduce (lambda (x y) `(+ ,x ,y))
62 '(+ (+ (+ 1 2) 3) 4)))
64 (test (equal (reduce (lambda (x y) `(+ ,x ,y))
67 '(+ 1 (+ 2 (+ 3 4)))))
69 (test (equal (reduce #'+ nil) 0))
70 (test (equal (reduce #'+ '(1)) 1))
71 (test (equal (reduce #'+ nil :initial-value 1) 1))
73 (test (equal (reduce #'+ '()
78 (test (equal (reduce #'+ '(100) :key #'1+)