Commit 219a9ae3 authored by pfdietz's avatar pfdietz

Modified a number of sequence operator tests to check that the operators...

Modified a number of sequence operator tests to check that the operators behavior correctly on vectors (bit vectors, strings) with fill pointers.
parent 8f45c844
......@@ -259,69 +259,92 @@
:end 7 :start 2 :from-end t)
1)
;;; tests on bitstrings
(deftest count-if-bitstring.1
(deftest count-if-nonsimple-vector.17
(flet ((%f (x) (eqt x 'a)))
(let ((s (make-array 13 :initial-contents '(a b c d a e f a e f f a a)
:fill-pointer 6)))
(values (count-if #'%f s)
(count-if #'%f s :end nil)
(count-if #'%f s :end 4)
(count-if #'%f s :start 1)
(count-if #'%f s :start 1 :end 4)
(count-if #'%f s :start 1 :end 4 :from-end t))))
2 2 1 1 0 0)
;;; tests on bit-vectors
(deftest count-if-bit-vector.1
(count-if #'evenp #*001011101101)
5)
(deftest count-if-bitstring.2
(deftest count-if-bit-vector.2
(count-if #'identity #*001011101101)
12)
(deftest count-if-bitstring.3
(deftest count-if-bit-vector.3
(count-if #'(lambda (x) (break)) #*)
0)
(deftest count-if-bitstring.4
(deftest count-if-bit-vector.4
(count-if #'identity #*001011101101 :key #'zerop)
5)
(deftest count-if-bitstring.5
(deftest count-if-bit-vector.5
(count-if 'identity #*001011101101 :key #'zerop)
5)
(deftest count-if-bitstring.6
(deftest count-if-bit-vector.6
(count-if #'identity #*001011101101 :key 'zerop)
5)
(deftest count-if-bitstring.8
(deftest count-if-bit-vector.8
(count-if #'identity #*001011101101 :key 'oddp)
7)
(deftest count-if-bitstring.10
(deftest count-if-bit-vector.10
(count-if #'evenp #*001011101101 :key #'1+)
7)
(deftest count-if-bitstring.11
(deftest count-if-bit-vector.11
(let ((c 0))
(count-if #'evenp #*001011101101
:key #'(lambda (x) (+ x (incf c)))))
7)
(deftest count-if-bitstring.12
(deftest count-if-bit-vector.12
(let ((c 0))
(count-if #'evenp #*001011101101
:from-end t
:key #'(lambda (x) (+ x (incf c)))))
5)
(deftest count-if-bitstring.13
(deftest count-if-bit-vector.13
(count-if #'zerop #*0111011011100 :start 2)
4)
(deftest count-if-bitstring.14
(deftest count-if-bit-vector.14
(count-if #'zerop #*0111011011100 :end 7)
2)
(deftest count-if-bitstring.15
(deftest count-if-bit-vector.15
(count-if #'zerop #*0111011011100 :end 7 :start 2)
1)
(deftest count-if-bitstring.16
(deftest count-if-bit-vector.16
(count-if #'zerop #*0111011011100 :end 7 :start 2 :from-end t)
1)
(deftest count-if-bit-vector.17
(let ((s (make-array '(10) :initial-contents '(0 0 1 0 1 0 0 1 1 0)
:element-type 'bit
:fill-pointer 6)))
(values (count-if #'zerop s)
(count-if #'zerop s :end nil)
(count-if #'zerop s :end 4)
(count-if #'zerop s :start 5)
(count-if #'zerop s :start 1 :end 4)))
4 4 3 1 2)
;;; tests on strings
(deftest count-if-string.1
......@@ -382,6 +405,18 @@
"0111011011100" :end 7 :start 2 :from-end t)
1)
(deftest count-if-string.17
(let ((s (make-array '(10)
:initial-contents (coerce "00a0aa0a0a" 'list)
:element-type 'character
:fill-pointer 6)))
(values (count-if #'digit-char-p s)
(count-if #'digit-char-p s :end nil)
(count-if #'digit-char-p s :start 1)
(count-if #'digit-char-p s :end 2)
(count-if #'digit-char-p s :start 1 :end 2)))
3 3 2 2 1)
;;; Error tests
(deftest count-if-error.1
......
......@@ -260,6 +260,30 @@
:test #'(lambda (x y) t))
5)
(deftest count-filled-vector.17
(count 1 (make-array 8 :initial-contents '(1 1 1 1 1 1 1 1)
:fill-pointer 6))
6)
(deftest count-filled-vector.18
(count 1 (make-array 8 :initial-contents '(1 1 1 1 1 1 1 1)
:fill-pointer 6)
:start 2)
4)
(deftest count-filled-vector.19
(count 1 (make-array 8 :initial-contents '(1 1 1 1 1 1 1 1)
:fill-pointer 6)
:from-end 'foo)
6)
(deftest count-filled-vector.20
(count 1 (make-array 8 :initial-contents '(1 1 1 1 1 1 1 1)
:fill-pointer 6)
:start 2 :from-end 'yes)
4)
;;; Tests on bit vectors
(deftest count-bit-vector.1
......@@ -332,6 +356,35 @@
:test #'(lambda (x y) t))
5)
(deftest count-bit-vector.17
(count 1 (make-array 8 :initial-contents '(1 0 1 1 1 1 1 1)
:element-type 'bit
:fill-pointer 5))
4)
(deftest count-bit-vector.18
(count 1 (make-array 8 :initial-contents '(1 0 1 1 1 1 1 1)
:element-type 'bit
:fill-pointer 5)
:start 1)
3)
(deftest count-bit-vector.19
(count 1 (make-array 8 :initial-contents '(1 0 1 1 1 1 1 1)
:element-type 'bit
:fill-pointer 5)
:end nil)
4)
(deftest count-bit-vector.20
(count 1 (make-array 8 :initial-contents '(1 0 1 1 1 1 1 1)
:element-type 'bit
:fill-pointer 6)
:end 4)
3)
;;; Tests on strings
(deftest count-string.1
......@@ -406,6 +459,33 @@
:test #'(lambda (x y) t))
5)
(deftest count-string.17
(count #\a (make-array 10 :initial-contents (coerce "abaaacaaaa" 'list)
:fill-pointer 7
:element-type 'character))
5)
(deftest count-string.18
(count #\a (make-array 10 :initial-contents (coerce "abaaacaaaa" 'list)
:fill-pointer 7
:element-type 'character)
:start 1)
4)
(deftest count-string.19
(count #\a (make-array 10 :initial-contents (coerce "abaaacaaaa" 'list)
:fill-pointer 7
:element-type 'character)
:end nil)
5)
(deftest count-string.20
(count #\a (make-array 10 :initial-contents (coerce "abaaacaaaa" 'list)
:fill-pointer 7
:element-type 'character)
:start 2 :end 5)
3)
;;; Error tests
(deftest count-error.1
......
......@@ -271,6 +271,17 @@
(6 6)
(nil)))
(deftest find-if-vector.19
(let ((a (make-array '(10) :initial-contents '(1 2 3 4 5 6 7 8 9 10)
:fill-pointer 5)))
(values
(find-if #'evenp a)
(find-if #'evenp a :from-end t)
(find-if #'oddp a)
(find-if #'oddp a :from-end t)
))
2 4 1 5)
;;; Tests for bit vectors
(deftest find-if-bit-vector.1
......@@ -484,6 +495,18 @@
(nil #\6)
(#\6)))
(deftest find-if-string.19
(let ((a (make-array '(10) :initial-contents (coerce "123456789a" 'list)
:fill-pointer 5
:element-type 'character)))
(values
(find-if #'evendigitp a)
(find-if #'evendigitp a :from-end t)
(find-if #'odddigitp a)
(find-if #'odddigitp a :from-end t)
))
#\2 #\4 #\1 #\5)
;;; Error tests
(deftest find-if-error.1
......
......@@ -305,6 +305,21 @@
:start 2 :from-end t)
(a b))
(deftest find-vector.29
(let ((a (make-array '(10)
:initial-contents '(1 2 3 4 5 6 7 8 9 10)
:fill-pointer 5)))
(loop for i from 1 to 10 collect (find i a)))
(1 2 3 4 5 nil nil nil nil nil))
(deftest find-vector.30
(let ((a (make-array '(10)
:initial-contents (loop for i from 1 for e in '(1 2 3 4 5 5 4 3 2 1)
collect (list e i))
:fill-pointer 5)))
(loop for i from 1 to 5 collect (find i a :from-end t :key #'car)))
((1 1) (2 2) (3 3) (4 4) (5 5)))
;;; tests on bit vectors
(deftest find-bit-vector.1
......@@ -562,6 +577,22 @@
:start 2 :from-end t)
nil)
(deftest find-bit-vector.29
(let ((a
(make-array '(10) :initial-contents '(1 1 1 1 1 0 0 0 0 0)
:element-type 'bit
:fill-pointer 5)))
(values (find 0 a)
(find 0 a :from-end t)))
nil nil)
(deftest find-bit-vector.30
(let ((a (make-array '(10) :initial-contents '(1 1 1 1 0 0 0 0 0 0)
:element-type 'bit
:fill-pointer 5)))
(values (find 0 a) (find 0 a :from-end t)))
0 0)
;;; strings
(deftest find-string.1
......@@ -698,6 +729,18 @@
:start 0 :end 5 :from-end t)
#\c)
(deftest find-string.25
(let ((s (make-array '(10) :initial-contents (coerce "abcdefghij" 'list)
:element-type 'character
:fill-pointer 5)))
(values
(loop for e across "abcdefghij"
collect (find e s))
(loop for e across "abcdefghij"
collect (find e s :from-end t))))
(#\a #\b #\c #\d #\e nil nil nil nil nil)
(#\a #\b #\c #\d #\e nil nil nil nil nil))
;;; Error tests
(deftest find-error.1
......
......@@ -32,19 +32,35 @@
(let* ((x (make-array 5 :initial-contents '(1 2 3 4 5)
:fill-pointer t :adjustable t))
(y (nreverse x)))
(values y (equal (type-of x) (type-of y))))
(values y (equalt (type-of x) (type-of y))))
#(5 4 3 2 1)
t)
(deftest nreverse-bitstring.1
(deftest nreverse-nonsimple-vector.3
(let* ((x (make-array 10 :initial-contents '(1 2 3 4 5 6 7 8 9 10)
:fill-pointer 5))
(y (nreverse x)))
(values y (equalt (type-of x) (type-of y))))
#(5 4 3 2 1)
t)
(deftest nreverse-bit-vector.1
(nreverse #*)
#*)
(deftest nreverse-bitstring.2
(deftest nreverse-bit-vector.2
(let ((x (copy-seq #*000110110110)))
(nreverse x))
#*011011011000)
(deftest nreverse-bit-vector.3
(let* ((x (make-array 10 :initial-contents '(0 0 0 1 1 0 1 0 1 0)
:fill-pointer 5
:element-type 'bit))
(y (nreverse x)))
y)
#*11000)
(deftest nreverse-string.1
(nreverse "")
"")
......@@ -54,6 +70,22 @@
(nreverse x))
"011011011000")
(deftest nreverse-string.3
(let* ((x (make-array 10 :initial-contents (coerce "abcdefghij" 'list)
:fill-pointer 5
:element-type 'character))
(y (nreverse x)))
y)
"edcba")
(deftest nreverse-string.4
(let* ((x (make-array 10 :initial-contents (coerce "abcdefghij" 'list)
:fill-pointer 5
:element-type 'base-char))
(y (nreverse x)))
y)
"edcba")
(deftest nreverse-error.1
(catch-type-error (nreverse 'a))
type-error)
......
......@@ -129,6 +129,43 @@
(reduce #'+ #(1 2 3) :start 0 :end 0)
0)
(deftest reduce-array.14
(let ((a (make-array '(8) :initial-contents '(1 2 3 4 5 6 7 8)
:fill-pointer 4)))
(reduce #'+ a))
10)
(deftest reduce-array.15
(let ((a (make-array '(8) :initial-contents '(1 2 3 4 5 6 7 8)
:fill-pointer 4)))
(reduce #'+ a :end nil))
10)
(deftest reduce-array.16
(let ((a (make-array '(8) :initial-contents '(1 2 3 4 5 6 7 8)
:fill-pointer 4)))
(reduce #'+ a :from-end t))
10)
(deftest reduce-array.17
(let ((a (make-array '(8) :initial-contents '(1 2 3 4 5 6 7 8)
:fill-pointer 4)))
(reduce #'+ a :initial-value 1))
11)
(deftest reduce-array.18
(let ((a (make-array '(8) :initial-contents '(1 2 3 4 5 6 7 8)
:fill-pointer 4)))
(reduce #'+ a :initial-value 1 :start 2))
8)
(deftest reduce-array.19
(let ((a (make-array '(8) :initial-contents '(1 2 3 4 5 6 7 8)
:fill-pointer 4)))
(reduce #'+ a :end 3))
6)
;;;;;;;;
(deftest reduce-error.1
......@@ -190,6 +227,41 @@
(reduce #'+ "abc" :start 0 :end 0)
0)
(deftest reduce-string.14
(let ((s (make-array '(8) :initial-contents (coerce "abcdefgh" 'list)
:fill-pointer 6
:element-type 'character)))
(coerce (reduce #'(lambda (x y) (cons y x)) s :initial-value nil)
'string))
"fedcba")
(deftest reduce-string.15
(let ((s (make-array '(8) :initial-contents (coerce "abcdefgh" 'list)
:fill-pointer 6
:element-type 'character)))
(coerce (reduce #'(lambda (x y) (cons y x)) s :initial-value nil
:start 1)
'string))
"fedcb")
(deftest reduce-string.16
(let ((s (make-array '(8) :initial-contents (coerce "abcdefgh" 'list)
:fill-pointer 6
:element-type 'character)))
(coerce (reduce #'(lambda (x y) (cons y x)) s :end nil
:initial-value nil)
'string))
"fedcba")
(deftest reduce-string.17
(let ((s (make-array '(8) :initial-contents (coerce "abcdefgh" 'list)
:fill-pointer 6
:element-type 'character)))
(coerce (reduce #'(lambda (x y) (cons y x)) s :end 4
:initial-value nil)
'string))
"dcba")
;;;;;;;;
(deftest reduce-bitstring.1
......@@ -244,3 +316,38 @@
(deftest reduce-bitstring.13
(reduce #'+ #(1 1 1) :start 0 :end 0)
0)
(deftest reduce-bitstring.14
(let ((s (make-array '(8) :initial-contents '(0 0 1 0 1 1 0 1)
:fill-pointer 6
:element-type 'bit)))
(reduce #'+ s))
3)
(deftest reduce-bitstring.15
(let ((s (make-array '(8) :initial-contents '(0 0 1 0 1 1 0 1)
:fill-pointer 6
:element-type 'bit)))
(reduce #'+ s :start 3))
2)
(deftest reduce-bitstring.16
(let ((s (make-array '(8) :initial-contents '(0 0 1 0 1 1 0 1)
:fill-pointer 6
:element-type 'bit)))
(reduce #'+ s :start 3 :initial-value 10))
12)
(deftest reduce-bitstring.17
(let ((s (make-array '(8) :initial-contents '(0 0 1 0 1 1 0 1)
:fill-pointer 6
:element-type 'bit)))
(reduce #'+ s :end nil))
3)
(deftest reduce-bitstring.18
(let ((s (make-array '(8) :initial-contents '(1 1 1 1 1 1 1 1)
:fill-pointer 6
:element-type 'bit)))
(reduce #'+ s :start 2 :end 4))
2)
......@@ -38,16 +38,31 @@
#(5 4 3 2 1)
#(1 2 3 4 5))
(deftest reverse-bitstring.1
(deftest reverse-nonsimple-vector.3
(let* ((x (make-array 10 :initial-contents '(1 2 3 4 5 6 7 8 9 10)
:fill-pointer 5))
(y (reverse x)))
y)
#(5 4 3 2 1))
(deftest reverse-bit-vector.1
(reverse #*)
#*)
(deftest reverse-bitstring.2
(deftest reverse-bit-vector.2
(let ((x #*000110110110))
(values (reverse x) x))
#*011011011000
#*000110110110)
(deftest reverse-bit-vector.3
(let* ((x (make-array 10 :initial-contents '(0 0 0 1 1 0 1 0 1 0)
:fill-pointer 5
:element-type 'bit))
(y (reverse x)))
y)
#*11000)
(deftest reverse-string.1
(reverse "")
"")
......@@ -58,6 +73,22 @@
"011011011000"
"000110110110")
(deftest reverse-string.3
(let* ((x (make-array 10 :initial-contents (coerce "abcdefghij" 'list)
:fill-pointer 5
:element-type 'character))
(y (reverse x)))
y)
"edcba")
(deftest reverse-string.4
(let* ((x (make-array 10 :initial-contents (coerce "abcdefghij" 'list)
:fill-pointer 5
:element-type 'base-char))
(y (reverse x)))
y)
"edcba")
(deftest reverse-error.1
(catch-type-error (reverse 'a))
type-error)
......
......@@ -37,6 +37,12 @@
(sort a #'<))
#(1 2 3 4 5))
(deftest sort-vector.4
(let ((a (make-array 10 :initial-contents '(10 40 20 50 30 15 45 25 55 35)
:fill-pointer 5)))
(sort a #'<))
#(10 20 30 40 50))
(deftest sort-bit-vector.1
(let ((a (copy-seq #*10011101)))
(sort a #'<))
......@@ -48,6 +54,13 @@
#*11111000
#*11111000)
(deftest sort-bit-vector.3
(let ((a (make-array 10 :initial-contents '(1 0 0 1 1 1 1 0 1 1)
:element-type 'bit
:fill-pointer 5)))
(sort a #'<))
#*00111)
(deftest sort-string.1
(let ((a (copy-seq "10011101")))
(values (sort a #'char<) a))
......@@ -60,6 +73,14 @@
"11111000"
"11111000")
(deftest sort-string.3
(let ((a (make-array 10 :initial-contents (coerce "1001111011" 'list)
:element-type 'character
:fill-pointer 5)))
(sort a #'char<))
"00111")
......
......@@ -47,6 +47,12 @@
(stable-sort a #'<))
#(1 2 3 4 5))
(deftest stable-sort-vector.4
(let ((a (make-array 10 :initial-contents '(10 40 20 50 30 15 45 25 55 35)
:fill-pointer 5)))
(stable-sort a #'<))
#(10 20 30 40 50))
(deftest stable-sort-bit-vector.1
(let ((a (copy-seq #*10011101)))
(stable-sort a #'<))
......@@ -58,6 +64,13 @@
#*11111000
#*11111000)
(deftest stable-sort-bit-vector.3
(let ((a (make-array 10 :initial-contents '(1 0 0 1 1 1 1 0 1 1)
:element-type 'bit
:fill-pointer 5)))
(stable-sort a #'<))
#*00111)
(deftest stable-sort-string.1
(let ((a (copy-seq "10011101")))
(values (stable-sort a #'char<) a))
......@@ -66,10 +79,18 @@
(deftest stable-sort-string.2
(let ((a (copy-seq "10011101")))
(values (stable-sort a #'char< :key #'(lambda (c) (if (eql c #\0) #\1 #\0))) a))
(values (stable-sort a #'char<
:key #'(lambda (c) (if (eql c #\0) #\1 #\0))) a))
"11111000"
"11111000")
(deftest stable-sort-string.3
(let ((a (make-array 10 :initial-contents (coerce "1001111011" 'list)
:element-type 'character
:fill-pointer 5)))
(stable-sort a #'char<))
"00111")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment