subtypep-array.lsp 7.67 KB
Newer Older
1
2
3
4
5
6
7
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sat Mar  1 16:23:57 2003
;;;; Contains: Tests of SUBTYPEP on array types

(in-package :cl-test)

8
9
(compile-and-load "types-aux.lsp")

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
;;; *array-element-types* is defined in ansi-aux.lsp

(deftest subtypep.array.1
  (let ((array-types (cons (find-class 'array)
			   '(array (array) (array *) (array * *)))))
    (loop for tp1 in array-types append
	  (loop for tp2 in array-types
		unless (subtypep tp1 tp2)
		collect (list tp1 tp2))))
  nil)

(deftest subtypep.array.2
  (and (subtypep* '(array t) '(array t *))
       (subtypep* '(array t *) '(array t))
       t)
  t)

(deftest subtypep.array.3
  (loop for i from 0 below (min 16 array-rank-limit)
	for type = `(array * ,i)
	for type2 = `(array * ,(make-list i :initial-element '*))
	unless (and (subtypep type 'array)
		    (subtypep type '(array))
		    (subtypep type '(array *))
		    (subtypep type '(array * *))
		    (subtypep type type2))
	collect type)
  nil)

(deftest subtypep.array.4
  (loop for i from 0 below (min 16 array-rank-limit)
	for type = `(array t ,i)
	for type2 = `(array t ,(make-list i :initial-element '*))
	unless (and (subtypep type '(array t))
		    (subtypep type '(array t *))
		    (subtypep type type2))
	collect type)
  nil)

(deftest subtypep.array.5
  (loop
   for element-type in (cons '* *array-element-types*)
   nconc
   (loop for i from 0 below (min 16 array-rank-limit)
	 for type = `(array ,element-type ,i)
	 for type2 = `(array ,element-type ,(make-list i :initial-element '0))
	 for type3 = `(array ,element-type ,(make-list i :initial-element '1))
	 unless
	 (and (subtypep type2 type)
	      (subtypep type3 type)
	      (loop for j from 0 to i
		    always
		    (and
		     (subtypep
		      `(array ,element-type
			      (,@(make-list j :initial-element '*)
				 ,@(make-list (- i j) :initial-element 2)))
		      type)
		     (subtypep
		      `(array ,element-type
			      (,@(make-list j :initial-element 2)
				 ,@(make-list (- i j) :initial-element '*)))
		      type))))   
	 collect type))
  nil)

pfdietz's avatar
pfdietz committed
76
(deftest subtypep.array.6
77
78
79
80
81
82
83
84
85
  (loop
   for etype in (cons '* *array-element-types*)
   append
   (check-equivalence
    `(and (array ,etype (* 10 * * *))
	  (array ,etype (* * * 29 *)))
    `(array ,etype (* 10 * 29 *))))
  nil)

pfdietz's avatar
pfdietz committed
86
(deftest subtypep.array.7
87
88
89
90
91
92
93
94
95
96
97
98
  (let ((etypes *array-element-types*))
    (loop
     for etp1 in etypes
     for uaetp1 = (upgraded-array-element-type etp1)
     append
     (loop for etp2 in etypes
	   for uaetp2 = (upgraded-array-element-type etp2)
	   when (equal (multiple-value-list (subtypep* uaetp1 uaetp2))
		       '(nil t))
	   append (check-disjointness `(array ,etp1) `(array ,etp2)))))
  nil)

99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
(deftest subtypep.array.8
  (let ((limit (min 16 array-rank-limit)))
    (loop for i below limit
	  for type1 = `(array t ,i)
	  nconc
	  (loop for j below limit
		for type2 = `(array t ,j)
		when (and (/= i j)
			  (subtypep type1 type2))
		collect (list type1 type2))))
  nil)

(deftest subtypep.array.9
  (let ((limit (min 16 array-rank-limit)))
    (loop for i below limit
	  for type1 = `(array t ,(make-list i :initial-element 1))
	  nconc
	  (loop for j below limit
		for type2 = `(array t ,(make-list j :initial-element 1))
		when (and (/= i j)
			  (subtypep type1 type2))
		collect (list type1 type2))))
  nil)

123
124
125
(deftest subtypep.array.10
  (subtypep* '(array t nil) 'integer)
  nil t)
126

127
128
129
130
131
132
133
134
135
136
137
(deftest subtypep.array.11
  (subtypep* '(array t nil) '(array t (*)))
  nil t)

(deftest subtypep.array.12
  (subtypep* '(array t nil) '(array t 1))
  nil t)

(deftest subtypep.array.13
  (subtypep* '(array bit nil) '(array bit 1))
  nil t)
138
139
140

;;;; Tests on the definitions of various vector types

141
(deftest string-is-not-vector-of-character.1
142
  :notes (:nil-vectors-are-strings)
143
  (subtypep* 'string '(vector character))
144
  nil t)
145

146
(deftest vector-of-character-is-string.2
147
148
149
  (subtypep* '(vector character) 'string)
  t t)

150
(deftest string-is-not-vector-of-character.3
151
  :notes (:nil-vectors-are-strings)
152
  (subtypep* '(string *) '(vector character))
153
  nil t)
154

155
(deftest vector-of-character-is-string.4
156
157
158
  (subtypep* '(vector character) '(string *))
  t t)

159
(deftest string-is-not-vector-of-character.5
160
  :notes (:nil-vectors-are-strings)
161
  (subtypep* '(string 17) '(vector character 17))
162
  nil t)
163

164
(deftest vector-of-character-is-string.6
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
  (subtypep* '(vector character 17) '(string 17))
  t t)

(deftest base-string-is-vector-of-base-char.1
  (subtypep* 'base-string '(vector base-char))
  t t)

(deftest base-string-is-vector-of-base-char.2
  (subtypep* '(vector base-char) 'base-string)
  t t)

(deftest base-string-is-vector-of-base-char.3
  (subtypep* '(base-string *) '(vector base-char))
  t t)

(deftest base-string-is-vector-of-base-char.4
  (subtypep* '(vector base-char) '(base-string *))
  t t)

(deftest base-string-is-vector-of-base-char.5
  (subtypep* '(base-string 17) '(vector base-char 17))
  t t)

(deftest base-string-is-vector-of-base-char.6
  (subtypep* '(vector base-char 17) '(base-string 17))
  t t)

(deftest simple-base-string-is-simple-1d-array-of-base-char.1
  (subtypep* 'simple-base-string '(simple-array base-char (*)))
  t t)

(deftest simple-base-string-is-simple-1d-array-of-base-char.2
  (subtypep* '(simple-array base-char (*)) 'simple-base-string)
  t t)

(deftest simple-base-string-is-simple-1d-array-of-base-char.3
  (subtypep* '(simple-base-string *) '(simple-array base-char (*)))
  t t)

(deftest simple-base-string-is-simple-1d-array-of-base-char.4
  (subtypep* '(simple-array base-char (*)) '(simple-base-string *))
  t t)

(deftest simple-base-string-is-simple-1d-array-of-base-char.5
  (subtypep* '(simple-base-string 17) '(simple-array base-char (17)))
  t t)

(deftest simple-base-string-is-simple-1d-array-of-base-char.6
  (subtypep* '(simple-array base-char (17)) '(simple-base-string 17))
  t t)

216
(deftest simple-string-is-not-simple-1d-array-of-character.1
217
  :notes (:nil-vectors-are-strings)
218
  (subtypep* 'simple-string '(simple-array character (*)))
219
  nil t)
220

221
(deftest simple-1d-array-of-character-is-simple-string.2
222
223
224
  (subtypep* '(simple-array character (*)) 'simple-string)
  t t)

225
(deftest simple-string-is-not-simple-1d-array-of-character.3
226
  :notes (:nil-vectors-are-strings)
227
  (subtypep* '(simple-string *) '(simple-array character (*)))
228
  nil t)
229

230
(deftest simple-1d-array-of-character-is-simple-string.4
231
232
233
  (subtypep* '(simple-array character (*)) '(simple-string *))
  t t)

234
(deftest simple-string-is-not-simple-1d-array-of-character.5
235
  :notes (:nil-vectors-are-strings)
236
  (subtypep* '(simple-string 17) '(simple-array character (17)))
237
  nil t)
238

239
(deftest simple-1d-array-of-character-is-simple-string.6
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
  (subtypep* '(simple-array character (17)) '(simple-string 17))
  t t)

(deftest vector-is-1d-array.1
  (subtypep* 'vector '(array * (*)))
  t t)

(deftest vector-is-1d-array.2
  (subtypep* '(array * (*)) 'vector)
  t t)

(deftest vector-is-1d-array.3
  (subtypep* '(vector *) '(array * (*)))
  t t)

(deftest vector-is-1d-array.4
  (subtypep* '(array * (*)) '(vector *))
  t t)

(deftest vector-is-1d-array.5
  (subtypep* '(vector * 17) '(array * (17)))
  t t)

(deftest vector-is-1d-array.6
  (subtypep* '(array * (17)) '(vector * 17))
  t t)

(deftest simple-vector-is-simple-1d-array.1
  (subtypep* 'simple-vector '(simple-array t (*)))
  t t)

(deftest simple-vector-is-simple-1d-array.2
  (subtypep* '(simple-array t (*)) 'simple-vector)
  t t)

(deftest simple-vector-is-simple-1d-array.3
  (subtypep* '(simple-vector *) '(simple-array t (*)))
  t t)

(deftest simple-vector-is-simple-1d-array.4
  (subtypep* '(simple-array t (*)) '(simple-vector *))
  t t)

(deftest simple-vector-is-simple-1d-array.5
  (subtypep* '(simple-vector 17) '(simple-array t (17)))
  t t)

(deftest simple-vector-is-simple-1d-array.6
  (subtypep* '(simple-array t (17)) '(simple-vector 17))
  t t)