vector.lsp 6.33 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Thu Jan 23 06:32:02 2003
;;;; Contains: Tests of VECTOR (type and function)

(in-package :cl-test)

;;; More tests of type vector in make-array.lsp

(deftest vector.type.1
11
  (notnot-mv (typep #(a b c) 'vector))
12 13 14
  t)

(deftest vector.type.2
15
  (notnot-mv (typep #() 'vector))
16 17 18
  t)

(deftest vector.type.3
19
  (notnot-mv (typep "" 'vector))
20 21 22
  t)

(deftest vector.type.4
23
  (notnot-mv (typep "abcdef" 'vector))
24 25 26
  t)

(deftest vector.type.5
27
  (notnot-mv (typep #* 'vector))
28 29 30
  t)

(deftest vector.type.6
31
  (notnot-mv (typep #*011011101011 'vector))
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
  t)

(deftest vector.type.7
  (typep #0aNIL 'vector)
  nil)

(deftest vector.type.8
  (typep #2a((a b c d)) 'vector)
  nil)

(deftest vector.type.9
  (subtypep* 'vector 'array)
  t t)

(deftest vector.type.10
47
  (notnot-mv (typep #(a b c) '(vector *)))
48 49 50
  t)

(deftest vector.type.11
51
  (notnot-mv (typep #(a b c) '(vector t)))
52 53 54
  t)

(deftest vector.type.12
55
  (notnot-mv (typep "abcde" '(vector *)))
56 57 58 59 60 61 62
  t)

(deftest vector.type.13
  (typep "abcdef" '(vector t))
  nil)

(deftest vector.type.14
63
  (notnot-mv (typep #*00110 '(vector *)))
64 65 66 67 68 69
  t)

(deftest vector.type.15
  (typep #*00110 '(vector t))
  nil)

70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
(deftest vector.type.16
  (notnot-mv (typep #(a b c) '(vector * 3)))
  t)

(deftest vector.type.17
  (typep #(a b c) '(vector * 2))
  nil)

(deftest vector.type.18
  (typep #(a b c) '(vector * 4))
  nil)

(deftest vector.type.19
  (notnot-mv (typep #(a b c) '(vector t 3)))
  t)
85

86 87 88 89 90 91 92 93 94 95
(deftest vector.type.20
  (typep #(a b c) '(vector t 2))
  nil)

(deftest vector.type.21
  (typep #(a b c) '(vector t 4))
  nil)

(deftest vector.type.23
  (notnot-mv (typep #(a b c) '(vector t *)))
pfdietz's avatar
pfdietz committed
96
  t)
97 98 99 100

(deftest vector.type.23a
  (notnot-mv (typep "abcde" '(vector * 5)))
  t)
101

102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
(deftest vector.type.24
  (typep "abcde" '(vector * 4))
  nil)

(deftest vector.type.25
  (typep "abcde" '(vector * 6))
  nil)

(deftest vector.type.26
  (notnot-mv (typep "abcde" '(vector * *)))
  t)

(deftest vector.type.27
  (typep "abcde" '(vector t 5))
  nil)

(deftest vector.type.28
  (typep "abcde" '(vector t 4))
  nil)

(deftest vector.type.29
  (typep "abcde" '(vector t 6))
  nil)

(deftest vector.type.30
  (typep "abcde" '(vector t *))
  nil)
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179

(deftest vector.type.31
  (let ((s (coerce "abc" 'simple-base-string)))
    (notnot-mv (typep s '(vector base-char))))
  t)

(deftest vector.type.32
  (let ((s (coerce "abc" 'simple-base-string)))
    (notnot-mv (typep s '(vector base-char 3))))
  t)

(deftest vector.type.33
  (let ((s (coerce "abc" 'simple-base-string)))
    (typep s '(vector base-char 2)))
  nil)

(deftest vector.type.34
  (let ((s (coerce "abc" 'simple-base-string)))
    (typep s '(vector base-char 4)))
  nil)

(deftest vector.type.35
  (let ((s (coerce "abc" 'simple-base-string)))
    (notnot-mv (typep s 'vector)))
  t)

(deftest vector.type.36
  (let ((s (coerce "abc" 'simple-base-string)))
    (notnot-mv (typep s '(vector *))))
  t)

(deftest vector.type.37
  (let ((s (coerce "abc" 'simple-base-string)))
    (notnot-mv (typep s '(vector * 3))))
  t)

(deftest vector.type.38
  (let ((s (coerce "abc" 'simple-base-string)))
    (notnot-mv (typep s '(vector * *))))
  t)

(deftest vector.type.39
  (let ((s (coerce "abc" 'simple-base-string)))
    (typep s '(vector t)))
  nil)

(deftest vector.type.40
  (let ((s (coerce "abc" 'simple-base-string)))
    (typep s '(vector t *)))
  nil)

180 181 182
(deftest vector.type.41
  (notnot-mv (typep (make-array '10 :element-type 'short-float) 'vector))
  t)
sds's avatar
sds committed
183

184 185 186
(deftest vector.type.42
  (notnot-mv (typep (make-array '10 :element-type 'single-float) 'vector))
  t)
sds's avatar
sds committed
187

188 189 190
(deftest vector.type.43
  (notnot-mv (typep (make-array '10 :element-type 'double-float) 'vector))
  t)
sds's avatar
sds committed
191

192 193 194
(deftest vector.type.44
  (notnot-mv (typep (make-array '10 :element-type 'long-float) 'vector))
  t)
195 196 197 198 199 200 201 202 203 204 205


;;; Tests of vector as class

(deftest vector-as-class.1
  (notnot-mv (find-class 'vector))
  t)

(deftest vector-as-class.2
  (notnot-mv (typep #() (find-class 'vector)))
  t)
sds's avatar
sds committed
206

207 208 209
(deftest vector-as-class.3
  (notnot-mv (typep #(a b c) (find-class 'vector)))
  t)
sds's avatar
sds committed
210

211 212 213
(deftest vector-as-class.4
  (notnot-mv (typep "" (find-class 'vector)))
  t)
sds's avatar
sds committed
214

215 216 217
(deftest vector-as-class.5
  (notnot-mv (typep "abcd" (find-class 'vector)))
  t)
sds's avatar
sds committed
218

219 220 221
(deftest vector-as-class.6
  (notnot-mv (typep #* (find-class 'vector)))
  t)
sds's avatar
sds committed
222

223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
(deftest vector-as-class.7
  (notnot-mv (typep #*01101010100 (find-class 'vector)))
  t)

(deftest vector-as-class.8
  (typep #0aNIL (find-class 'vector))
  nil)

(deftest vector-as-class.9
  (typep #2a((a b)(c d)) (find-class 'vector))
  nil)

(deftest vector-as-class.10
  (typep (make-array '(1 0)) (find-class 'vector))
  nil)

(deftest vector-as-class.11
  (typep (make-array '(0 1)) (find-class 'vector))
  nil)

(deftest vector-as-class.12
  (typep 1 (find-class 'vector))
  nil)

(deftest vector-as-class.13
  (typep nil (find-class 'vector))
  nil)

(deftest vector-as-class.14
  (typep 'x (find-class 'vector))
  nil)

(deftest vector-as-class.15
  (typep '(a b c) (find-class 'vector))
  nil)

(deftest vector-as-class.16
  (typep 10.0 (find-class 'vector))
  nil)

(deftest vector-as-class.17
  (typep 3/5 (find-class 'vector))
  nil)

(deftest vector-as-class.18
  (typep (1+ most-positive-fixnum) (find-class 'vector))
  nil)
270

271 272 273 274 275 276 277 278 279 280 281 282
;;;; Tests of the function VECTOR

(deftest vector.1
  (vector)
  #())

(deftest vector.2
  (vector 1 2 3)
  #(1 2 3))

(deftest vector.3
  (let* ((len (min 1000 (1- call-arguments-limit)))
sds's avatar
sds committed
283 284
         (args (make-int-list len))
         (v (apply #'vector args)))
285 286 287 288 289 290 291 292
    (and
     (typep v '(vector t))
     (typep v '(vector t *))
     (typep v `(vector t ,len))
     (typep v 'simple-vector)
     (typep v `(simple-vector ,len))
     (eql (length v) len)
     (loop for i from 0
sds's avatar
sds committed
293 294
           for e across v
           always (eql i e))
295 296 297 298 299 300
     t))
  t)

(deftest vector.4
  (notnot-mv (typep (vector) '(vector t 0)))
  t)
sds's avatar
sds committed
301

302 303 304
(deftest vector.5
  (notnot-mv (typep (vector) 'simple-vector))
  t)
sds's avatar
sds committed
305

306 307 308
(deftest vector.6
  (notnot-mv (typep (vector) '(simple-vector 0)))
  t)
sds's avatar
sds committed
309

310 311 312
(deftest vector.7
  (notnot-mv (typep (vector 1 2 3) 'simple-vector))
  t)
sds's avatar
sds committed
313

314 315 316 317 318 319 320
(deftest vector.8
  (notnot-mv (typep (vector 1 2 3) '(simple-vector 3)))
  t)

(deftest vector.9
  (typep (vector #\a #\b #\c) 'string)
  nil)
321 322 323 324 325

(deftest vector.10
  (notnot-mv (typep (vector 1 2 3) '(simple-vector *)))
  t)

326 327 328 329 330 331
(deftest vector.order.1
  (let ((i 0) a b c)
    (values
     (vector (setf a (incf i)) (setf b (incf i)) (setf c (incf i)))
     i a b c))
  #(1 2 3) 3 1 2 3)