subtypep-array.lsp 8.39 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

10 11 12 13
;;; *array-element-types* is defined in ansi-aux.lsp

(deftest subtypep.array.1
  (let ((array-types (cons (find-class 'array)
sds's avatar
sds committed
14
                           '(array (array) (array *) (array * *)))))
15
    (loop for tp1 in array-types append
sds's avatar
sds committed
16 17 18
          (loop for tp2 in array-types
                unless (subtypep tp1 tp2)
                collect (list tp1 tp2))))
19 20 21 22 23 24 25 26 27 28
  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)
sds's avatar
sds committed
29 30 31 32 33 34 35 36
        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)
37 38 39 40
  nil)

(deftest subtypep.array.4
  (loop for i from 0 below (min 16 array-rank-limit)
sds's avatar
sds committed
41 42 43 44 45 46
        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)
47 48 49 50 51 52 53
  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)
sds's avatar
sds committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
         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))
74 75
  nil)

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

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

99 100 101
(deftest subtypep.array.8
  (let ((limit (min 16 array-rank-limit)))
    (loop for i below limit
sds's avatar
sds committed
102 103 104 105 106 107 108
          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))))
109 110 111 112 113
  nil)

(deftest subtypep.array.9
  (let ((limit (min 16 array-rank-limit)))
    (loop for i below limit
sds's avatar
sds committed
114 115 116 117 118 119 120
          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))))
121 122
  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 144 145
  (or (subtypep* 'string '(vector character))
      (subtypep* 'string '(vector base-char))
      (subtypep* 'string '(vector extended-char)))
146
  nil t)
147

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

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

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

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

166
(deftest vector-of-character-is-string.6
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 216 217
  (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)

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

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

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

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

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

241
(deftest simple-1d-array-of-character-is-simple-string.6
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 290 291
  (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)