X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=tests%2Fseq.lisp;h=6538f21b979556e332422df5e33e6340341916a7;hb=HEAD;hp=c39b0ce174b26e5ed5de32ab90703fb637ac748e;hpb=d28977241d642ea32277945b81a99c7171458433;p=jscl.git diff --git a/tests/seq.lisp b/tests/seq.lisp index c39b0ce..6538f21 100644 --- a/tests/seq.lisp +++ b/tests/seq.lisp @@ -37,6 +37,10 @@ (test (= (position 1 #(1 1 3) :test-not #'=) 2)) (test (= (position 1 '(1 1 3) :test-not #'=) 2)) +;; POSITION-IF, POSITION-IF-NOT +(test (= 2 (position-if #'oddp '((1) (2) (3) (4)) :start 1 :key #'car))) +(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!) + ; REMOVE-IF (test (equal (remove-if #'zerop '(1 0 2 0 3)) '(1 2 3))) (test (equal (remove-if-not #'zerop '(1 0 2 0 3)) '(0 0))) @@ -51,3 +55,40 @@ (test (equal (subseq nums 2 4) '(3 4))) ; Test that nums hasn't been altered: SUBSEQ should construct fresh lists (test (equal nums '(1 2 3 4 5)))) + +;;; REDUCE +(test (equal (reduce (lambda (x y) `(+ ,x ,y)) + '(1 2 3 4)) + '(+ (+ (+ 1 2) 3) 4))) + +(test (equal (reduce (lambda (x y) `(+ ,x ,y)) + '(1 2 3 4) + :from-end t) + '(+ 1 (+ 2 (+ 3 4))))) + +(test (equal (reduce #'+ nil) 0)) +(test (equal (reduce #'+ '(1)) 1)) +(test (equal (reduce #'+ nil :initial-value 1) 1)) + +(test (equal (reduce #'+ '() + :key #'1+ + :initial-value 100) + 100)) + +(test (equal (reduce #'+ '(100) :key #'1+) + 101)) + +; MISMATCH +(test (= (mismatch '(1 2 3) '(1 2 3 4 5 6)) 3)) +(test (= (mismatch '(1 2 3) #(1 2 3 4 5 6)) 3)) +(test (= (mismatch #(1 2 3) '(1 2 3 4 5 6)) 3)) +(test (= (mismatch #(1 2 3) #(1 2 3 4 5 6)) 3)) + +; SEARCH +(test (= (search '(1 2 3) '(4 5 6 1 2 3)) 3)) +(test (= (search '(1 2 3) #(4 5 6 1 2 3)) 3)) +(test (= (search #(1 2 3) '(4 5 6 1 2 3)) 3)) +(test (= (search #(1 2 3) #(4 5 6 1 2 3)) 3)) +(test (not (search '(foo) '(1 2 3)))) +(test (= (search '(1) '(4 5 6 1 2 3)) 3)) +(test (= (search #(1) #(4 5 6 1 2 3)) 3))