subtypep-integer.lsp 11.5 KB
Newer Older
1 2 3 4 5 6 7
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sat Feb 15 11:54:05 2003
;;;; Contains: Tests for subtype relationships on integer types

(in-package :cl-test)

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

10 11 12 13 14 15
(deftest subtypep.fixnum-or-bignum
  (check-equivalence '(or fixnum bignum) 'integer)
  nil)

(deftest subtypep.fixnum.integer
  (check-equivalence `(integer ,most-negative-fixnum ,most-positive-fixnum)
sds's avatar
sds committed
16
                     'fixnum)
17 18 19 20 21
  nil)

(deftest subtypep.bignum.integer
  (check-equivalence
   `(or (integer * (,most-negative-fixnum))
sds's avatar
sds committed
22
        (integer (,most-positive-fixnum) *))
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
   'bignum)
  nil)

;;;;;;;

(deftest subtypep.integer.1
  (subtypep* '(integer 0 10) '(integer 0 20))
  t t)

(deftest subtypep.integer.2
  (subtypep* '(integer 0 10) '(integer 0 (10)))
  nil t)

(deftest subtypep.integer.3
  (subtypep* '(integer 10 100) 'integer)
  t t)

40 41 42 43 44 45 46 47 48 49 50 51
(deftest subtypep.integer.3a
  (subtypep* '(integer 10 100) '(integer))
  t t)

(deftest subtypep.integer.3b
  (subtypep* '(integer 10 100) '(integer *))
  t t)

(deftest subtypep.integer.3c
  (subtypep* '(integer 10 100) '(integer * *))
  t t)

52 53 54 55
(deftest subtypep.integer.4
  (subtypep* 'integer '(integer 10 100))
  nil t)

56 57 58 59 60 61 62 63 64 65 66 67
(deftest subtypep.integer.4a
  (subtypep* '(integer) '(integer 10 100))
  nil t)

(deftest subtypep.integer.4b
  (subtypep* '(integer *) '(integer 10 100))
  nil t)

(deftest subtypep.integer.4c
  (subtypep* '(integer * *) '(integer 10 100))
  nil t)

68 69 70 71
(deftest subtypep.integer.5
  (subtypep* '(integer 10 *) 'integer)
  t t)

72 73 74 75 76 77 78 79 80 81 82 83
(deftest subtypep.integer.5a
  (subtypep* '(integer 10 *) '(integer))
  t t)

(deftest subtypep.integer.5b
  (subtypep* '(integer 10 *) '(integer *))
  t t)

(deftest subtypep.integer.5c
  (subtypep* '(integer 10 *) '(integer * *))
  t t)

84 85 86 87
(deftest subtypep.integer.6
  (subtypep* 'integer '(integer 10 *))
  nil t)

88 89 90 91 92 93 94 95 96 97 98 99
(deftest subtypep.integer.6a
  (subtypep* '(integer) '(integer 10 *))
  nil t)

(deftest subtypep.integer.6b
  (subtypep* '(integer *) '(integer 10 *))
  nil t)

(deftest subtypep.integer.6c
  (subtypep* '(integer * *) '(integer 10 *))
  nil t)

100 101 102 103
(deftest subtypep.integer.7
  (subtypep* '(integer 10) 'integer)
  t t)

104 105 106 107 108 109 110 111 112 113 114 115
(deftest subtypep.integer.7a
  (subtypep* '(integer 10) '(integer))
  t t)

(deftest subtypep.integer.7b
  (subtypep* '(integer 10) '(integer *))
  t t)

(deftest subtypep.integer.7c
  (subtypep* '(integer 10) '(integer * *))
  t t)

116 117 118 119
(deftest subtypep.integer.8
  (subtypep* 'integer '(integer 10))
  nil t)

120 121 122 123 124 125 126 127 128 129 130 131
(deftest subtypep.integer.8a
  (subtypep* '(integer) '(integer 10))
  nil t)

(deftest subtypep.integer.8b
  (subtypep* '(integer *) '(integer 10))
  nil t)

(deftest subtypep.integer.8c
  (subtypep* '(integer * *) '(integer 10))
  nil t)

132 133 134 135
(deftest subtypep.integer.9
  (subtypep* '(integer * 10) 'integer)
  t t)

136 137 138 139 140 141 142 143 144 145 146 147
(deftest subtypep.integer.9a
  (subtypep* '(integer * 10) '(integer))
  t t)

(deftest subtypep.integer.9b
  (subtypep* '(integer * 10) '(integer *))
  t t)

(deftest subtypep.integer.9c
  (subtypep* '(integer * 10) '(integer * *))
  t t)

148 149 150 151
(deftest subtypep.integer.10
  (subtypep* 'integer '(integer * 10))
  nil t)

152 153 154 155 156 157 158 159 160 161 162 163
(deftest subtypep.integer.10a
  (subtypep* '(integer) '(integer * 10))
  nil t)

(deftest subtypep.integer.10b
  (subtypep* '(integer *) '(integer * 10))
  nil t)

(deftest subtypep.integer.10c
  (subtypep* '(integer * *) '(integer * 10))
  nil t)

164 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 216 217 218 219 220 221 222
(deftest subtypep.integer.11
  (subtypep* '(integer 10) '(integer 5))
  t t)

(deftest subtypep.integer.12
  (subtypep* '(integer 5) '(integer 10))
  nil t)

(deftest subtypep.integer.13
  (subtypep* '(integer 10 *) '(integer 5))
  t t)

(deftest subtypep.integer.14
  (subtypep* '(integer 5) '(integer 10 *))
  nil t)

(deftest subtypep.integer.15
  (subtypep* '(integer 10) '(integer 5 *))
  t t)

(deftest subtypep.integer.16
  (subtypep* '(integer 5 *) '(integer 10))
  nil t)

(deftest subtypep.integer.17
  (subtypep* '(integer 10 *) '(integer 5 *))
  t t)

(deftest subtypep.integer.18
  (subtypep* '(integer 5 *) '(integer 10 *))
  nil t)

(deftest subtypep.integer.19
  (subtypep* '(integer * 5) '(integer * 10))
  t t)

(deftest subtypep.integer.20
  (subtypep* '(integer * 10) '(integer * 5))
  nil t)

(deftest subtypep.integer.21
  (subtypep* '(integer 10 *) '(integer * 10))
  nil t)

(deftest subtypep.integer.22
  (subtypep* '(integer * 10) '(integer 10 *))
  nil t)

(deftest subtypep.integer.23
  (check-equivalence '(integer (9)) '(integer 10))
  nil)

(deftest subtypep.integer.24
  (check-equivalence '(integer * (11)) '(integer * 10))
  nil)

(deftest subtypep.integer.25
  (check-equivalence
   '(and (or (integer 0 10) (integer 20 30))
sds's avatar
sds committed
223
         (or (integer 5 15) (integer 25 35)))
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
   '(or (integer 5 10) (integer 25 30)))
  nil)

(deftest subtypep.integer.26
  (check-equivalence
   '(and (integer 0 10) (integer 5 15))
   '(integer 5 10))
  nil)

(deftest subtypep.integer.27
  (check-equivalence
   '(or (integer 0 10) (integer 5 15))
   '(integer 0 15))
  nil)

(deftest subtypep.integer.28
  (check-equivalence
   '(and integer (not (eql 10)))
   '(or (integer * 9) (integer 11 *)))
  nil)

(deftest subtypep.integer.29
  (check-equivalence
   '(and integer (not (integer 1 10)))
   '(or (integer * 0) (integer 11 *)))
  nil)

(deftest subtypep.integer.30
  (check-equivalence
   '(and (integer -100 100) (not (integer 1 10)))
   '(or (integer -100 0) (integer 11 100)))
  nil)

257 258 259
;;;  Relations between integer and real types

(deftest subtypep.integer.real.1
260 261 262 263 264
  (check-equivalence
   '(and integer (real 4 10))
   '(integer 4 10))
  nil)

265
(deftest subtypep.integer.real.2
266 267 268 269 270
  (check-equivalence
   '(and (integer 4 *) (real * 10))
   '(integer 4 10))
  nil)

271
(deftest subtypep.integer.real.3
272 273 274 275
  (check-equivalence
   '(and (integer * 10) (real 4))
   '(integer 4 10))
  nil)
276 277 278

(deftest subtypep.integer.real.4
  (loop for int-type in '(integer (integer) (integer *) (integer * *))
sds's avatar
sds committed
279 280 281 282 283
        append (loop for real-type in '(real (real) (real *) (real * *))
                     unless (equal (multiple-value-list
                                    (subtypep* int-type real-type))
                                   '(t t))
                     collect (list int-type real-type)))
284 285 286 287
  nil)

(deftest subtypep.integer.real.5
  (loop for int-type in '((integer 10) (integer 10 *))
sds's avatar
sds committed
288 289 290 291 292 293 294
        append (loop for real-type in '(real (real) (real *) (real * *)
                                             (real 10.0) (real 10.0 *)
                                             (real 10) (real 10 *))
                     unless (equal (multiple-value-list
                                    (subtypep* int-type real-type))
                                   '(t t))
                     collect (list int-type real-type)))
295 296 297 298
  nil)

(deftest subtypep.integer.real.6
  (loop for int-type in '((integer * 10) (integer * 5))
sds's avatar
sds committed
299 300 301 302 303 304 305
        append (loop for real-type in '(real (real) (real *) (real * *)
                                             (real * 10.0)
                                            (real * 10) (real * 1000000000000))
                     unless (equal (multiple-value-list
                                    (subtypep* int-type real-type))
                                   '(t t))
                     collect (list int-type real-type)))
306 307 308 309
  nil)

(deftest subtypep.integer.real.7
  (loop for int-type in '((integer 0 10) (integer 2 5))
sds's avatar
sds committed
310 311 312 313 314 315 316 317 318 319 320
        append (loop for real-type in '(real (real) (real *) (real * *)
                                            (real * 10) (real * 1000000000000)
                                            (real -10) (real -10.0)
                                            (real -10 *) (real -10.0 *)
                                            (real 0) (real 0.0)
                                            (real 0 10) (real * 10)
                                            (real 0 *) (real 0 10))
                     unless (equal (multiple-value-list
                                    (subtypep* int-type real-type))
                                   '(t t))
                     collect (list int-type real-type)))
321 322
  nil)

323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
(deftest subtypep.integer.real.8
  (check-equivalence
   '(and (integer 4) (real * 10))
   '(integer 4 10))
  nil)

(deftest subtypep.integer.real.9
  (check-equivalence
   '(and (integer * 10) (real 4))
   '(integer 4 10))
  nil)

(deftest subtypep.integer.real.10
  (check-equivalence
   '(and (integer 4) (real * (10)))
   '(integer 4 9))
  nil)

(deftest subtypep.integer.real.11
  (check-equivalence
   '(and (integer * 10) (real (4)))
   '(integer 5 10))
  nil)

347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371

;;; Between integer and rational types

(deftest subtypep.integer.rational.1
  (check-equivalence
   '(and integer (rational 4 10))
   '(integer 4 10))
  nil)

(deftest subtypep.integer.rational.2
  (check-equivalence
   '(and (integer 4 *) (rational * 10))
   '(integer 4 10))
  nil)

(deftest subtypep.integer.rational.3
  (check-equivalence
   '(and (integer * 10) (rational 4))
   '(integer 4 10))
  nil)



(deftest subtypep.integer.rational.4
  (loop for int-type in '(integer (integer) (integer *) (integer * *))
sds's avatar
sds committed
372 373 374 375 376 377
        append (loop for rational-type
                     in '(rational (rational) (rational *) (rational * *))
                     unless (equal (multiple-value-list
                                    (subtypep* int-type rational-type))
                                   '(t t))
                     collect (list int-type rational-type)))
378 379 380 381
  nil)

(deftest subtypep.integer.rational.5
  (loop for int-type in '((integer 10) (integer 10 *))
sds's avatar
sds committed
382 383 384 385 386 387 388 389
        append (loop for rational-type
                     in '(rational (rational) (rational *) (rational * *)
                                   (rational 19/2) (rational 19/2 *)
                                   (rational 10) (rational 10 *))
                     unless (equal (multiple-value-list
                                    (subtypep* int-type rational-type))
                                   '(t t))
                     collect (list int-type rational-type)))
390 391 392 393
  nil)

(deftest subtypep.integer.rational.6
  (loop for int-type in '((integer * 10) (integer * 5))
sds's avatar
sds committed
394 395 396 397 398 399 400 401
        append (loop for rational-type
                     in '(rational (rational) (rational *) (rational * *)
                                   (rational * 21/2)
                                   (rational * 10) (rational * 1000000000000))
                     unless (equal (multiple-value-list
                                    (subtypep* int-type rational-type))
                                   '(t t))
                     collect (list int-type rational-type)))
402 403 404 405
  nil)

(deftest subtypep.integer.rational.7
  (loop for int-type in '((integer 0 10) (integer 2 5))
sds's avatar
sds committed
406 407 408 409 410 411 412 413 414 415 416 417
        append (loop for rational-type in
                     '(rational (rational) (rational *) (rational * *)
                                (rational * 10) (rational * 1000000000000)
                                (rational -1) (rational -1/2)
                                (rational -1 *) (rational -1/2 *)
                                (rational 0)
                                (rational 0 10) (rational * 10)
                                (rational 0 *) (rational 0 10))
                     unless (equal (multiple-value-list
                                    (subtypep* int-type rational-type))
                                   '(t t))
                     collect (list int-type rational-type)))
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436
  nil)

(deftest subtypep.integer.rational.8
  (check-equivalence
   '(and integer (rational (4) 10))
   '(integer 5 10))
  nil)

(deftest subtypep.integer.rational.9
  (check-equivalence
   '(and (integer 4 *) (rational * (10)))
   '(integer 4 9))
  nil)

(deftest subtypep.integer.rational.10
  (check-equivalence
   '(and (integer * 10) (rational (4)))
   '(integer 5 10))
  nil)