1 | ;-*- Mode: Lisp -*- |
---|
2 | ;;;; Author: Paul Dietz |
---|
3 | ;;;; Created: Thu Jan 23 06:32:02 2003 |
---|
4 | ;;;; Contains: Tests of VECTOR (type and function) |
---|
5 | |
---|
6 | (in-package :cl-test) |
---|
7 | |
---|
8 | ;;; More tests of type vector in make-array.lsp |
---|
9 | |
---|
10 | (deftest vector.type.1 |
---|
11 | (notnot-mv (typep #(a b c) 'vector)) |
---|
12 | t) |
---|
13 | |
---|
14 | (deftest vector.type.2 |
---|
15 | (notnot-mv (typep #() 'vector)) |
---|
16 | t) |
---|
17 | |
---|
18 | (deftest vector.type.3 |
---|
19 | (notnot-mv (typep "" 'vector)) |
---|
20 | t) |
---|
21 | |
---|
22 | (deftest vector.type.4 |
---|
23 | (notnot-mv (typep "abcdef" 'vector)) |
---|
24 | t) |
---|
25 | |
---|
26 | (deftest vector.type.5 |
---|
27 | (notnot-mv (typep #* 'vector)) |
---|
28 | t) |
---|
29 | |
---|
30 | (deftest vector.type.6 |
---|
31 | (notnot-mv (typep #*011011101011 'vector)) |
---|
32 | t) |
---|
33 | |
---|
34 | (deftest vector.type.7 |
---|
35 | (typep #0aNIL 'vector) |
---|
36 | nil) |
---|
37 | |
---|
38 | (deftest vector.type.8 |
---|
39 | (typep #2a((a b c d)) 'vector) |
---|
40 | nil) |
---|
41 | |
---|
42 | (deftest vector.type.9 |
---|
43 | (subtypep* 'vector 'array) |
---|
44 | t t) |
---|
45 | |
---|
46 | (deftest vector.type.10 |
---|
47 | (notnot-mv (typep #(a b c) '(vector *))) |
---|
48 | t) |
---|
49 | |
---|
50 | (deftest vector.type.11 |
---|
51 | (notnot-mv (typep #(a b c) '(vector t))) |
---|
52 | t) |
---|
53 | |
---|
54 | (deftest vector.type.12 |
---|
55 | (notnot-mv (typep "abcde" '(vector *))) |
---|
56 | t) |
---|
57 | |
---|
58 | (deftest vector.type.13 |
---|
59 | (typep "abcdef" '(vector t)) |
---|
60 | nil) |
---|
61 | |
---|
62 | (deftest vector.type.14 |
---|
63 | (notnot-mv (typep #*00110 '(vector *))) |
---|
64 | t) |
---|
65 | |
---|
66 | (deftest vector.type.15 |
---|
67 | (typep #*00110 '(vector t)) |
---|
68 | nil) |
---|
69 | |
---|
70 | (deftest vector.type.16 |
---|
71 | (notnot-mv (typep #(a b c) '(vector * 3))) |
---|
72 | t) |
---|
73 | |
---|
74 | (deftest vector.type.17 |
---|
75 | (typep #(a b c) '(vector * 2)) |
---|
76 | nil) |
---|
77 | |
---|
78 | (deftest vector.type.18 |
---|
79 | (typep #(a b c) '(vector * 4)) |
---|
80 | nil) |
---|
81 | |
---|
82 | (deftest vector.type.19 |
---|
83 | (notnot-mv (typep #(a b c) '(vector t 3))) |
---|
84 | t) |
---|
85 | |
---|
86 | (deftest vector.type.20 |
---|
87 | (typep #(a b c) '(vector t 2)) |
---|
88 | nil) |
---|
89 | |
---|
90 | (deftest vector.type.21 |
---|
91 | (typep #(a b c) '(vector t 4)) |
---|
92 | nil) |
---|
93 | |
---|
94 | (deftest vector.type.23 |
---|
95 | (notnot-mv (typep #(a b c) '(vector t *))) |
---|
96 | t) |
---|
97 | |
---|
98 | (deftest vector.type.23a |
---|
99 | (notnot-mv (typep "abcde" '(vector * 5))) |
---|
100 | t) |
---|
101 | |
---|
102 | (deftest vector.type.24 |
---|
103 | (typep "abcde" '(vector * 4)) |
---|
104 | nil) |
---|
105 | |
---|
106 | (deftest vector.type.25 |
---|
107 | (typep "abcde" '(vector * 6)) |
---|
108 | nil) |
---|
109 | |
---|
110 | (deftest vector.type.26 |
---|
111 | (notnot-mv (typep "abcde" '(vector * *))) |
---|
112 | t) |
---|
113 | |
---|
114 | (deftest vector.type.27 |
---|
115 | (typep "abcde" '(vector t 5)) |
---|
116 | nil) |
---|
117 | |
---|
118 | (deftest vector.type.28 |
---|
119 | (typep "abcde" '(vector t 4)) |
---|
120 | nil) |
---|
121 | |
---|
122 | (deftest vector.type.29 |
---|
123 | (typep "abcde" '(vector t 6)) |
---|
124 | nil) |
---|
125 | |
---|
126 | (deftest vector.type.30 |
---|
127 | (typep "abcde" '(vector t *)) |
---|
128 | nil) |
---|
129 | |
---|
130 | (deftest vector.type.31 |
---|
131 | (let ((s (coerce "abc" 'simple-base-string))) |
---|
132 | (notnot-mv (typep s '(vector base-char)))) |
---|
133 | t) |
---|
134 | |
---|
135 | (deftest vector.type.32 |
---|
136 | (let ((s (coerce "abc" 'simple-base-string))) |
---|
137 | (notnot-mv (typep s '(vector base-char 3)))) |
---|
138 | t) |
---|
139 | |
---|
140 | (deftest vector.type.33 |
---|
141 | (let ((s (coerce "abc" 'simple-base-string))) |
---|
142 | (typep s '(vector base-char 2))) |
---|
143 | nil) |
---|
144 | |
---|
145 | (deftest vector.type.34 |
---|
146 | (let ((s (coerce "abc" 'simple-base-string))) |
---|
147 | (typep s '(vector base-char 4))) |
---|
148 | nil) |
---|
149 | |
---|
150 | (deftest vector.type.35 |
---|
151 | (let ((s (coerce "abc" 'simple-base-string))) |
---|
152 | (notnot-mv (typep s 'vector))) |
---|
153 | t) |
---|
154 | |
---|
155 | (deftest vector.type.36 |
---|
156 | (let ((s (coerce "abc" 'simple-base-string))) |
---|
157 | (notnot-mv (typep s '(vector *)))) |
---|
158 | t) |
---|
159 | |
---|
160 | (deftest vector.type.37 |
---|
161 | (let ((s (coerce "abc" 'simple-base-string))) |
---|
162 | (notnot-mv (typep s '(vector * 3)))) |
---|
163 | t) |
---|
164 | |
---|
165 | (deftest vector.type.38 |
---|
166 | (let ((s (coerce "abc" 'simple-base-string))) |
---|
167 | (notnot-mv (typep s '(vector * *)))) |
---|
168 | t) |
---|
169 | |
---|
170 | (deftest vector.type.39 |
---|
171 | (let ((s (coerce "abc" 'simple-base-string))) |
---|
172 | (typep s '(vector t))) |
---|
173 | nil) |
---|
174 | |
---|
175 | (deftest vector.type.40 |
---|
176 | (let ((s (coerce "abc" 'simple-base-string))) |
---|
177 | (typep s '(vector t *))) |
---|
178 | nil) |
---|
179 | |
---|
180 | (deftest vector.type.41 |
---|
181 | (notnot-mv (typep (make-array '10 :element-type 'short-float) 'vector)) |
---|
182 | t) |
---|
183 | |
---|
184 | (deftest vector.type.42 |
---|
185 | (notnot-mv (typep (make-array '10 :element-type 'single-float) 'vector)) |
---|
186 | t) |
---|
187 | |
---|
188 | (deftest vector.type.43 |
---|
189 | (notnot-mv (typep (make-array '10 :element-type 'double-float) 'vector)) |
---|
190 | t) |
---|
191 | |
---|
192 | (deftest vector.type.44 |
---|
193 | (notnot-mv (typep (make-array '10 :element-type 'long-float) 'vector)) |
---|
194 | t) |
---|
195 | |
---|
196 | |
---|
197 | ;;; Tests of vector as class |
---|
198 | |
---|
199 | (deftest vector-as-class.1 |
---|
200 | (notnot-mv (find-class 'vector)) |
---|
201 | t) |
---|
202 | |
---|
203 | (deftest vector-as-class.2 |
---|
204 | (notnot-mv (typep #() (find-class 'vector))) |
---|
205 | t) |
---|
206 | |
---|
207 | (deftest vector-as-class.3 |
---|
208 | (notnot-mv (typep #(a b c) (find-class 'vector))) |
---|
209 | t) |
---|
210 | |
---|
211 | (deftest vector-as-class.4 |
---|
212 | (notnot-mv (typep "" (find-class 'vector))) |
---|
213 | t) |
---|
214 | |
---|
215 | (deftest vector-as-class.5 |
---|
216 | (notnot-mv (typep "abcd" (find-class 'vector))) |
---|
217 | t) |
---|
218 | |
---|
219 | (deftest vector-as-class.6 |
---|
220 | (notnot-mv (typep #* (find-class 'vector))) |
---|
221 | t) |
---|
222 | |
---|
223 | (deftest vector-as-class.7 |
---|
224 | (notnot-mv (typep #*01101010100 (find-class 'vector))) |
---|
225 | t) |
---|
226 | |
---|
227 | (deftest vector-as-class.8 |
---|
228 | (typep #0aNIL (find-class 'vector)) |
---|
229 | nil) |
---|
230 | |
---|
231 | (deftest vector-as-class.9 |
---|
232 | (typep #2a((a b)(c d)) (find-class 'vector)) |
---|
233 | nil) |
---|
234 | |
---|
235 | (deftest vector-as-class.10 |
---|
236 | (typep (make-array '(1 0)) (find-class 'vector)) |
---|
237 | nil) |
---|
238 | |
---|
239 | (deftest vector-as-class.11 |
---|
240 | (typep (make-array '(0 1)) (find-class 'vector)) |
---|
241 | nil) |
---|
242 | |
---|
243 | (deftest vector-as-class.12 |
---|
244 | (typep 1 (find-class 'vector)) |
---|
245 | nil) |
---|
246 | |
---|
247 | (deftest vector-as-class.13 |
---|
248 | (typep nil (find-class 'vector)) |
---|
249 | nil) |
---|
250 | |
---|
251 | (deftest vector-as-class.14 |
---|
252 | (typep 'x (find-class 'vector)) |
---|
253 | nil) |
---|
254 | |
---|
255 | (deftest vector-as-class.15 |
---|
256 | (typep '(a b c) (find-class 'vector)) |
---|
257 | nil) |
---|
258 | |
---|
259 | (deftest vector-as-class.16 |
---|
260 | (typep 10.0 (find-class 'vector)) |
---|
261 | nil) |
---|
262 | |
---|
263 | (deftest vector-as-class.17 |
---|
264 | (typep 3/5 (find-class 'vector)) |
---|
265 | nil) |
---|
266 | |
---|
267 | (deftest vector-as-class.18 |
---|
268 | (typep (1+ most-positive-fixnum) (find-class 'vector)) |
---|
269 | nil) |
---|
270 | |
---|
271 | ;;;; Tests of the function VECTOR |
---|
272 | |
---|
273 | (deftest vector.1 |
---|
274 | (vector) |
---|
275 | #()) |
---|
276 | |
---|
277 | (deftest vector.2 |
---|
278 | (vector 1 2 3) |
---|
279 | #(1 2 3)) |
---|
280 | |
---|
281 | (deftest vector.3 |
---|
282 | (let* ((len (min 1000 (1- call-arguments-limit))) |
---|
283 | (args (make-int-list len)) |
---|
284 | (v (apply #'vector args))) |
---|
285 | (and |
---|
286 | (typep v '(vector t)) |
---|
287 | (typep v '(vector t *)) |
---|
288 | (typep v `(vector t ,len)) |
---|
289 | (typep v 'simple-vector) |
---|
290 | (typep v `(simple-vector ,len)) |
---|
291 | (eql (length v) len) |
---|
292 | (loop for i from 0 |
---|
293 | for e across v |
---|
294 | always (eql i e)) |
---|
295 | t)) |
---|
296 | t) |
---|
297 | |
---|
298 | (deftest vector.4 |
---|
299 | (notnot-mv (typep (vector) '(vector t 0))) |
---|
300 | t) |
---|
301 | |
---|
302 | (deftest vector.5 |
---|
303 | (notnot-mv (typep (vector) 'simple-vector)) |
---|
304 | t) |
---|
305 | |
---|
306 | (deftest vector.6 |
---|
307 | (notnot-mv (typep (vector) '(simple-vector 0))) |
---|
308 | t) |
---|
309 | |
---|
310 | (deftest vector.7 |
---|
311 | (notnot-mv (typep (vector 1 2 3) 'simple-vector)) |
---|
312 | t) |
---|
313 | |
---|
314 | (deftest vector.8 |
---|
315 | (notnot-mv (typep (vector 1 2 3) '(simple-vector 3))) |
---|
316 | t) |
---|
317 | |
---|
318 | (deftest vector.9 |
---|
319 | (typep (vector #\a #\b #\c) 'string) |
---|
320 | nil) |
---|
321 | |
---|
322 | (deftest vector.10 |
---|
323 | (notnot-mv (typep (vector 1 2 3) '(simple-vector *))) |
---|
324 | t) |
---|
325 | |
---|
326 | (deftest vector.order.1 |
---|
327 | (let ((i 0) a b c) |
---|
328 | (values |
---|
329 | (vector (setf a (incf i)) (setf b (incf i)) (setf c (incf i))) |
---|
330 | i a b c)) |
---|
331 | #(1 2 3) 3 1 2 3) |
---|