Tests for modified sequence functions
authorOwen Rodley <Strigoides@gmail.com>
Sat, 18 May 2013 04:00:09 +0000 (16:00 +1200)
committerOwen Rodley <Strigoides@gmail.com>
Sat, 18 May 2013 04:02:49 +0000 (16:02 +1200)
tests/seq.lisp

index 1f2ffc2..c39b0ce 100644 (file)
@@ -1,19 +1,51 @@
+; Functions used as :KEY argument in tests
+(defvar halve  (lambda (x) (/ x 2)))
+(defvar double (lambda (x) (* x 2)))
+
+; FIND
 (test (find 1 #(2 1 3)))
+(test (find 1 '(2 1 3)))
 (test (not (find 1 #(2 2 2))))
+(test (not (find 1 '(2 2 2))))
+(test (not (find 1 #(1 1 1) :test-not #'=)))
+(test (not (find 1 '(1 1 1) :test-not #'=)))
+(test (not (find 1 #(1 2 3) :key double)))
+(test (not (find 1 '(1 2 3) :key double)))
+
+; REMOVE
 (test (not (find 1 (remove 1 #(1 2 3 1)))))
+(test (not (find 1 (remove 1 '(1 2 3 1)))))
+(test (not (find 2 (remove 1 #(1 2 3 1) :key halve))))
+(test (not (find 2 (remove 1 '(1 2 3 1) :key halve))))
+;; TODO: Rewrite this test when EQUALP exists and works on vectors
+(test (equal (length (remove '(1 2) #((1 2) (1 2)) :test #'equal)) 0))
+(test (null          (remove '(1 2) '((1 2) (1 2)) :test #'equal)))
+(test (find 2 (remove 2 #(1 2 3) :test-not #'=)))
+(test (find 2 (remove 2 '(1 2 3) :test-not #'=)))
 
-(test (find 1 (list 2 1 3)))
-(test (not (find 1 (list 2 2 2))))
-(test (not (find 1 (remove 1 (list 1 2 3 1)))))
+; POSITION
+(test (= (position 1 #(1 2 3))  0))
+(test (= (position 1 '(1 2 3))  0))
+(test (= (position 1 #(1 2 3 1)) 0))
+(test (= (position 1 '(1 2 3 1)) 0))
+(test (not (position 1 #(2 3 4))))
+(test (not (position 1 '(2 3 4))))
+(test (= (position 1 '(1 2 3) :key halve) 1))
+(test (= (position 1 #(1 2 3) :key halve) 1))
+(test (= (position '(1 2) '((1 2) (3 4)) :test #'equal) 0))
+(test (= (position '(1 2) #((1 2) (3 4)) :test #'equal) 0))
+(test (= (position 1 #(1 1 3) :test-not #'=) 2))
+(test (= (position 1 '(1 1 3) :test-not #'=) 2))
 
+; 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)))
-
 ;; TODO: Rewrite these tests when EQUALP exists and works on vectors
 (let ((v1 (remove-if #'zerop #(1 0 2 0 3))))
   (test (and (= (aref v1 0) 1) (= (aref v1 1) 2) (= (aref v1 2) 3)))) 
 (test (every #'zerop (remove-if-not #'zerop #(1 0 2 0 3))))
 
+; SUBSEQ
 (let ((nums '(1 2 3 4 5)))
   (test (equal (subseq nums 3) '(4 5)))
   (test (equal (subseq nums 2 4) '(3 4)))