Debian Codegraph @

src/tests/universe.lisp

raw
1 ;;;; -*- Mode: Lisp; Syntax: Common-Lisp; indent-tabs-mode: nil -*-
2 ;;;; vim: set filetype=lisp tabstop=8 shiftwidth=2 expandtab:
3
4 ;;;; Author: Paul Dietz
5 ;;;; Created: Thu Apr 9 19:32:56 1998
6 ;;;; Contains: A global variable containing a list of
7 ;;;; as many kinds of CL objects as we can think of
8 ;;;; This list is used to test many other CL functions
9
10 (in-package :cl-test)
11
12 (defparameter *condition-types*
13 '(arithmetic-error
14 cell-error
15 condition
16 control-error
17 division-by-zero
18 end-of-file
19 error
20 file-error
21 floating-point-inexact
22 floating-point-invalid-operation
23 floating-point-underflow
24 floating-point-overflow
25 package-error
26 parse-error
27 print-not-readable
28 program-error
29 reader-error
30 serious-condition
31 simple-condition
32 simple-error
33 simple-type-error
34 simple-warning
35 storage-condition
36 stream-error
37 style-warning
38 type-error
39 unbound-slot
40 unbound-variable
41 undefined-function
42 warning))
43
44 (defparameter *condition-objects*
45 (locally (declare (optimize safety))
46 (loop for tp in *condition-types* append
47 (handler-case (list (make-condition tp))
48 (error () nil)))))
49
50 (defparameter *standard-package-names*
51 '("COMMON-LISP" "COMMON-LISP-USER" "KEYWORD"))
52
53 (defparameter *package-objects*
54 (locally (declare (optimize safety))
55 (loop for pname in *standard-package-names* append
56 (handler-case (let ((pkg (find-package pname)))
57 (and pkg (list pkg)))
58 (error () nil)))))
59
60 (defparameter *integers*
61 (remove-duplicates
62 `(
63 0
64 ;; Integers near the fixnum/bignum boundaries
65 ,@(loop for i from -5 to 5 collect (+ i most-positive-fixnum))
66 ,@(loop for i from -5 to 5 collect (+ i most-negative-fixnum))
67 ;; Powers of two, negatives, and off by one.
68 ,@(loop for i from 1 to 64 collect (ash 1 i))
69 ,@(loop for i from 1 to 64 collect (1- (ash 1 i)))
70 ,@(loop for i from 1 to 64 collect (ash -1 i))
71 ,@(loop for i from 1 to 64 collect (1+ (ash -1 i)))
72 ;; A big integer
73 ,(expt 17 50)
74 ;; Some arbitrarily chosen integers
75 12387131 1272314 231 -131 -561823 23713 -1234611312123 444121 991)))
76
77 (defparameter *floats*
78 (append
79 (loop for sym in '(pi
80 most-positive-short-float
81 least-positive-short-float
82 least-positive-normalized-short-float
83 most-positive-double-float
84 least-positive-double-float
85 least-positive-normalized-double-float
86 most-positive-long-float
87 least-positive-long-float
88 least-positive-normalized-long-float
89 most-positive-single-float
90 least-positive-single-float
91 least-positive-normalized-single-float
92 most-negative-short-float
93 least-negative-short-float
94 least-negative-normalized-short-float
95 most-negative-single-float
96 least-negative-single-float
97 least-negative-normalized-single-float
98 most-negative-double-float
99 least-negative-double-float
100 least-negative-normalized-double-float
101 most-negative-long-float
102 least-negative-long-float
103 least-negative-normalized-long-float
104 short-float-epsilon
105 short-float-negative-epsilon
106 single-float-epsilon
107 single-float-negative-epsilon
108 double-float-epsilon
109 double-float-negative-epsilon
110 long-float-epsilon
111 long-float-negative-epsilon)
112 when (boundp sym) collect (symbol-value sym))
113 (list
114 0.0 -0.0 1.0 -1.0 313123.13 283143.231 -314781.9
115 1.31283d2 834.13812D-45
116 8131238.1E14 -4618926.231e-2
117 -37818.131F3 81.318231f-19
118 1.31273s3 12361.12S-7
119 6124.124l0 13123.1L-23)))
120
121 #+ieee-floating-point
122 (defparameter *ieee-fp.inf*
123 (list ext:short-float-negative-infinity
124 ext:single-float-negative-infinity
125 ext:double-float-negative-infinity
126 ext:long-float-negative-infinity
127 ext:short-float-positive-infinity
128 ext:single-float-positive-infinity
129 ext:double-float-positive-infinity
130 ext:long-float-positive-infinity))
131
132 #+ieee-floating-point
133 (defparameter *ieee-fp.nan*
134 (list (coerce (ext:nan) 'single-float)
135 (coerce (ext:nan) 'double-float)
136 (coerce (ext:nan) 'long-float)))
137
138 (defparameter *ratios*
139 '(1/3 1/1000 1/1000000000000000 -10/3 -1000/7 -987129387912381/13612986912361
140 189729874978126783786123/1234678123487612347896123467851234671234))
141
142 (defparameter *complexes*
143 '(#C(0.0 0.0)
144 #C(1.0 0.0)
145 #C(0.0 1.0)
146 #C(1.0 1.0)
147 #C(-1.0 -1.0)
148 #C(1289713.12312 -9.12681271)
149 #C(1.0D100 1.0D100)
150 #C(-1.0D-100 -1.0D-100)
151 #C(10.0s0 20.0s0)
152 #C(100.0l0 200.0l0)
153 #C(1.0s0 2.0f0)
154 #C(1.0s0 3.0d0)
155 #C(1.0s0 4.0l0)
156 #C(1.0f0 5.0d0)
157 #C(1.0f0 6.0l0)
158 #C(1.0d0 7.0l0)
159 #C(1.0f0 2.0s0)
160 #C(1.0d0 3.0s0)
161 #C(1.0l0 4.0s0)
162 #C(1.0d0 5.0f0)
163 #C(1.0l0 6.0f0)
164 #C(1.0l0 7.0d0)
165 #C(1/2 1/3)
166 #C(42 12)))
167
168 (defparameter *numbers*
169 (append *integers*
170 *floats*
171 *ratios*
172 *complexes*))
173
174 (defparameter *reals* (append *integers* *floats* *ratios*))
175
176 (defparameter *rationals* (append *integers* *ratios*))
177
178 (defun try-to-read-chars (&rest namelist)
179 (declare (optimize safety))
180 (loop
181 for name in namelist append
182 (handler-case
183 (list (read-from-string
184 (concatenate 'string "\#\\" name)))
185 (error () nil))))
186
187 (defparameter *characters*
188 (remove-duplicates
189 `(#\Newline
190 #\Space
191 ,@(try-to-read-chars "Rubout"
192 "Page"
193 "Tab"
194 "Backspace"
195 "Return"
196 "Linefeed"
197 "Null")
198 #\a #\A #\0 #\9 #\. #\( #\) #\[ #\]
199 )))
200
201
202 (defparameter *strings*
203 (append
204 (and (code-char 0)
205 (list
206 (make-string 1 :initial-element (code-char 0))
207 (make-string 10 :initial-element (code-char 0))))
208 (list
209 "" "A" "a" "0" "abcdef"
210 "~!@#$%^&*()_+`1234567890-=<,>.?/:;\"'{[}]|\\ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWYXZ"
211 (make-string 100000 :initial-element #\g)
212 (let ((s (make-string 256)))
213 (loop
214 for i from 0 to 255
215 do (let ((c (code-char i)))
216 (when c
217 (setf (elt s i) c))))
218 s)
219 ;; Specialized strings
220 (make-array 3
221 :element-type 'character
222 :displaced-to (make-array 5 :element-type 'character
223 :initial-contents "abcde")
224 :displaced-index-offset 1)
225 (make-array 10 :initial-element #\x
226 :fill-pointer 5
227 :element-type 'character)
228 (make-array 10 :initial-element #\x
229 :element-type 'base-char)
230 (make-array 3 :initial-element #\y
231 :adjustable t
232 :element-type 'base-char)
233 )))
234
235 (defparameter *conses*
236 (list
237 (list 'a 'b)
238 (list nil)
239 (list 1 2 3 4 5 6)))
240
241 (defparameter *circular-conses*
242 (list
243 (let ((s (copy-list '(a b c d))))
244 (nconc s s)
245 s)
246 (let ((s (list nil)))
247 (setf (car s) s)
248 s)
249 (let ((s (list nil)))
250 (setf (car s) s)
251 (setf (cdr s) s))))
252
253 (defparameter *booleans* '(nil t))
254 (defparameter *keywords* '(:a :b :|| :|a| :|1234|))
255 (defparameter *uninterned-symbols*
256 (list '#:nil '#:t '#:foo '#:||))
257 (defparameter *cl-test-symbols*
258 `(,(intern "a" :cl-test)
259 ,(intern "" :cl-test)
260 ,@(and (code-char 0)
261 (list (intern (make-string 1 :initial-element (code-char 0)) :cl-test)))
262 ,@(and (code-char 0)
263 (let* ((s (make-string 10 :initial-element (code-char 0)))
264 (s2 (copy-seq s))
265 (s3 (copy-seq s)))
266 (setf (subseq s 3 4) "a")
267 (setf (subseq s2 4 5) "a")
268 (setf (subseq s3 4 5) "a")
269 (setf (subseq s3 7 8) "b")
270 (list (intern s :cl-test)
271 (intern s2 :cl-test)
272 (intern s3 :cl-test))))
273 ))
274
275 (defparameter *cl-user-symbols*
276 '(cl-user::foo
277 cl-user::x
278 cl-user::cons
279 cl-user::lambda
280 cl-user::*print-readably*
281 cl-user::push))
282
283 (defparameter *symbols*
284 (append *booleans* *keywords* *uninterned-symbols*
285 *cl-test-symbols*
286 *cl-user-symbols*))
287
288 (defparameter *array-dimensions*
289 (loop
290 for i from 0 to 8 collect
291 (loop for j from 1 to i collect 2)))
292
293 (defparameter *default-array-target* (make-array '(300)))
294
295 (defparameter *arrays*
296 (append
297 (list (make-array '10))
298 (mapcar #'make-array *array-dimensions*)
299
300 ;; typed arrays
301 (loop for tp in '(fixnum float bit character base-char
302 (signed-byte 8) (unsigned-byte 8))
303 for element in '(18 16.0f0 0 #\x #\y 127 200)
304 append
305 (loop
306 for d in *array-dimensions*
307 collect (make-array d :element-type tp
308 :initial-element element)))
309
310 ;; More typed arrays
311 (loop for i from 1 to 64
312 append
313 (list (make-array 10 :element-type `(unsigned-byte ,i)
314 :initial-element 1)
315 (make-array 10 :element-type `(signed-byte ,i)
316 :initial-element 0)))
317
318 ;; adjustable arrays
319 (loop
320 for d in *array-dimensions*
321 collect (make-array d :adjustable t))
322
323 ;; Displaced arrays
324 (loop
325 for d in *array-dimensions*
326 for i from 1
327 collect (make-array d :displaced-to *default-array-target*
328 :displaced-index-offset i))
329
330 (list
331 #()
332 #*
333 #*00000
334 #*1010101010101101
335 (make-array 10 :element-type 'bit
336 :initial-contents '(0 1 1 0 1 1 1 1 0 1)
337 :fill-pointer 8)
338 (make-array 5 :element-type 'bit
339 :displaced-to #*0111000110
340 :displaced-index-offset 3)
341 (make-array 10 :element-type 'bit
342 :initial-contents '(1 1 0 0 1 1 1 0 1 1)
343 :adjustable t)
344 )
345
346 ;; Integer arrays
347 (list
348 (make-array '(10) :element-type '(integer 0 (256))
349 :initial-contents '(8 9 10 11 12 1 2 3 4 5))
350 (make-array '(10) :element-type '(integer -128 (128))
351 :initial-contents '(8 9 -10 11 -12 1 -2 -3 4 5))
352 (make-array '(6) :element-type '(integer 0 (#.(ash 1 16)))
353 :initial-contents '(5 9 100 1312 23432 87))
354 (make-array '(4) :element-type '(integer 0 (#.(ash 1 28)))
355 :initial-contents '(100000 231213 8123712 19))
356 (make-array '(4) :element-type '(integer 0 (#.(ash 1 32)))
357 :initial-contents '(#.(1- (ash 1 32)) 0 872312 10000000))
358
359 (make-array nil :element-type '(integer 0 (256))
360 :initial-element 14)
361 (make-array '(2 2) :element-type '(integer 0 (256))
362 :initial-contents '((34 98)(14 119)))
363 )
364
365 ;; Float arrays
366 (list
367 (make-array '(5) :element-type 'short-float
368 :initial-contents '(1.0s0 2.0s0 3.0s0 4.0s0 5.0s0))
369 (make-array '(5) :element-type 'single-float
370 :initial-contents '(1.0f0 2.0f0 3.0f0 4.0f0 5.0f0))
371 (make-array '(5) :element-type 'double-float
372 :initial-contents '(1.0d0 2.0d0 3.0d0 4.0d0 5.0d0))
373 (make-array '(5) :element-type 'long-float
374 :initial-contents '(1.0l0 2.0l0 3.0l0 4.0l0 5.0l0))
375 )
376
377 ;; The ever-popular NIL array
378 (locally (declare (optimize safety))
379 (handler-case
380 (list (make-array '(0) :element-type nil))
381 (error () nil)))
382
383 ;; more kinds of arrays here later?
384 ))
385
386 (defparameter *hash-tables*
387 (list
388 (make-hash-table)
389 (make-hash-table :test #'eq)
390 (make-hash-table :test #'eql)
391 (make-hash-table :test #'equal)
392 #-(or CMU ECL) (make-hash-table :test #'equalp)
393 ))
394
395 (defparameter *pathnames*
396 (locally
397 (declare (optimize safety))
398 (loop for form in '((make-pathname :name "foo")
399 (make-pathname :name "FOO" :case :common)
400 (make-pathname :name "bar")
401 (make-pathname :name "foo" :type "txt")
402 (make-pathname :name "bar" :type "txt")
403 (make-pathname :name "XYZ" :type "TXT" :case :common)
404 (make-pathname :name nil)
405 (make-pathname :name :wild)
406 (make-pathname :name nil :type "txt")
407 (make-pathname :name :wild :type "txt")
408 (make-pathname :name :wild :type "TXT" :case :common)
409 (make-pathname :name :wild :type "abc" :case :common)
410 (make-pathname :directory :wild)
411 (make-pathname :type :wild)
412 (make-pathname :version :wild)
413 (make-pathname :version :newest))
414 append (ignore-errors (eval `(list ,form))))))
415
416 (eval-when (:compile-toplevel :load-toplevel :execute)
417 (locally
418 (declare (optimize safety))
419 (ignore-errors
420 (setf (logical-pathname-translations "CLTESTROOT")
421 `(("**;*.*.*" ,(make-pathname :directory '(:absolute :wild-inferiors)
422 :name :wild :type :wild)))))
423 (ignore-errors
424 (setf (logical-pathname-translations "CLTEST")
425 `(("**;*.*.*" ,(make-pathname
426 :directory (append
427 (pathname-directory
428 (truename (make-pathname)))
429 '(:wild-inferiors))
430 :name :wild :type :wild)))))
431 ))
432
433 (defparameter *logical-pathnames*
434 (locally
435 (declare (optimize safety))
436 (append
437 (ignore-errors (list (logical-pathname "CLTESTROOT:")))
438 )))
439
440 (defparameter *streams*
441 (remove-duplicates
442 (remove-if
443 #'null
444 (list
445 *debug-io*
446 *error-output*
447 *query-io*
448 *standard-input*
449 *standard-output*
450 *terminal-io*
451 *trace-output*))))
452
453 (defparameter *readtables*
454 (list *readtable*
455 (copy-readtable)))
456
457 (defstruct foo-structure
458 x y z)
459
460 (defstruct bar-structure
461 x y z)
462
463 (defparameter *structures*
464 (list
465 (make-foo-structure :x 1 :y 'a :z nil)
466 (make-foo-structure :x 1 :y 'a :z nil)
467 (make-bar-structure :x 1 :y 'a :z nil)
468 ))
469
470 (defun meaningless-user-function-for-universe (x y z)
471 (list (+ x 1) (+ y 2) (+ z 3)))
472
473 (defgeneric meaningless-user-generic-function-for-universe (x y z)
474 (:method ((x integer) (y integer) (z integer)) (+ x y z)))
475
476 #+ (or)
477 (eval-when (:load-toplevel :execute)
478 (compile 'meaningless-user-function-for-universe)
479 (compile 'meaningless-user-generic-function-for-universe))
480
481 (defparameter *functions*
482 (list #'cons #'car #'append #'values
483 (macro-function 'cond)
484 #'meaningless-user-function-for-universe
485 #'meaningless-user-generic-function-for-universe
486 #'(lambda (x) x)
487 (compile nil '(lambda (x) x))))
488
489 (defparameter *methods*
490 (list
491 #+(or (not :gcl) :ansi-cl )
492 (find-method #'meaningless-user-generic-function-for-universe nil
493 (mapcar #'find-class '(integer integer integer)))
494 ;; Add more methods here
495 ))
496
497
498 (defparameter *random-states*
499 (list (make-random-state)))
500
501 (defparameter *universe*
502 (remove-duplicates
503 (append
504 *symbols*
505 *numbers*
506 *characters*
507 (mapcar #'copy-seq *strings*)
508 *conses*
509 *condition-objects*
510 *package-objects*
511 *arrays*
512 *hash-tables*
513 *pathnames*
514 *logical-pathnames*
515 *streams*
516 *readtables*
517 *structures*
518 *functions*
519 *random-states*
520 *methods*
521 nil)))
522
523 (defparameter *mini-universe*
524 (remove-duplicates
525 (append
526 (mapcar #'first
527 (list *symbols*
528 *numbers*
529 *characters*
530 (list (copy-seq (first *strings*)))
531 *conses*
532 *condition-objects*
533 *package-objects*
534 *arrays*
535 *hash-tables*
536 *pathnames*
537 *logical-pathnames*
538 *streams*
539 *readtables*
540 *structures*
541 *functions*
542 *random-states*
543 *methods*))
544 '(;;; Others to fill in gaps
545 1.2s0 1.3f0 1.5d0 1.8l0 3/5 10000000000000000000000))))
546
547 (defparameter *classes*
548 (remove-duplicates (mapcar #'class-of *universe*)))
549
550 (defparameter *built-in-classes*
551 (remove-if-not #'(lambda (x) (typep x 'built-in-class))
552 *classes*))