source: trunk/j/src/org/armedbear/lisp/rt.lisp @ 3620

Last change on this file since 3620 was 3620, checked in by piso, 20 years ago

random

File size: 18.2 KB
Line 
1;;; rt.lisp
2;;;
3;;; Copyright (C) 2003 Peter Graves
4;;; $Id: rt.lisp,v 1.119 2003-09-08 13:36:53 piso Exp $
5;;;
6;;; This program is free software; you can redistribute it and/or
7;;; modify it under the terms of the GNU General Public License
8;;; as published by the Free Software Foundation; either version 2
9;;; of the License, or (at your option) any later version.
10;;;
11;;; This program is distributed in the hope that it will be useful,
12;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with this program; if not, write to the Free Software
18;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20;;; Adapted from rt.lsp and ansi-aux.lsp in the GCL ANSI test suite.
21
22#+armedbear
23(require 'defstruct)
24
25#+armedbear
26(require 'loop)
27
28(unless (find-package :regression-test)
29  (make-package :regression-test :nicknames '(:rt))
30  (use-package :cl :rt))
31
32(in-package :rt)
33
34(export '(deftest))
35
36(defvar *prefix* "/home/peter/gcl/ansi-tests/")
37
38(defvar *compile-tests* nil)
39
40(defvar *passed* 0)
41(defvar *failed* 0)
42
43(defun equalp-with-case (x y)
44  (cond
45   ((eq x y) t)
46   ((consp x)
47    (and (consp y)
48   (equalp-with-case (car x) (car y))
49   (equalp-with-case (cdr x) (cdr y))))
50   ((and (typep x 'array)
51   (= (array-rank x) 0))
52    (equalp-with-case (aref x) (aref y)))
53   ((typep x 'vector)
54    (and (typep y 'vector)
55   (let ((x-len (length x))
56         (y-len (length y)))
57     (and (eql x-len y-len)
58    (loop
59     for e1 across x
60     for e2 across y
61     always (equalp-with-case e1 e2))))))
62   ((and (typep x 'array)
63   (typep y 'array)
64   (not (equal (array-dimensions x)
65         (array-dimensions y))))
66    nil)
67   ((typep x 'array)
68    (and (typep y 'array)
69   (let ((size (array-total-size x)))
70     (loop for i from 0 below size
71     always (equalp-with-case (row-major-aref x i)
72            (row-major-aref y i))))))
73   (t (eql x y))))
74
75(defmacro deftest (name &rest body)
76  (format t "Test ~s~%" `,name)
77  (finish-output)
78  (let* ((p body)
79   (properties
80    (loop while (keywordp (first p))
81            unless (cadr p)
82            do (error "Poorly formed deftest: ~A~%"
83                      (list* 'deftest name body))
84            append (list (pop p) (pop p))))
85   (form (pop p))
86   (values p))
87    (let* ((aborted nil)
88           (r (handler-case (multiple-value-list
89                             (if *compile-tests*
90                                 (funcall (compile nil `(lambda () ,form)))
91                                 (eval `,form)))
92                            (error (c) (setf aborted t) (list c))))
93           (passed (and (not aborted) (equalp-with-case r `,values))))
94      (unless passed
95        (format t "  Expected value: ~s~%"
96                (if (= (length `,values) 1)
97                    (car `,values)
98                    `,values))
99        (format t "    Actual value: ~s~%"
100                (if (= (length r) 1)
101                    (car r)
102                    r))
103        (finish-output))
104      (if passed (incf *passed*) (incf *failed*)))))
105
106(in-package :cl-user)
107
108(intern "==>" "CL-USER")
109
110(defvar *compiled-and-loaded-files* nil)
111
112(defun compile-and-load (filename &key force)
113  (let* ((pathname (concatenate 'string rt::*prefix* filename))
114         (former-data (assoc pathname *compiled-and-loaded-files*
115           :test #'equal))
116   (source-write-time (file-write-date pathname)))
117    (unless (and (not force)
118     former-data
119     (>= (cadr former-data) source-write-time))
120      (if former-data
121    (setf (cadr former-data) source-write-time)
122          (push (list pathname source-write-time) *compiled-and-loaded-files*))
123      (load pathname))))
124
125(defpackage :cl-test
126  (:use :cl :regression-test)
127  (:nicknames)
128  (:shadow #:handler-case #:handler-bind)
129  (:import-from "COMMON-LISP-USER" #:compile-and-load "==>")
130  (:export #:random-from-seq #:random-case #:coin #:random-permute))
131
132(load (concatenate 'string rt::*prefix* "ansi-aux-macros.lsp"))
133
134(defun do-tests (&rest args)
135  (let ((rt::*passed* 0) (rt::*failed* 0)
136        (suffix ".lsp")
137        (tests (or args (list "abs"
138                              "acons"
139                              "adjoin"
140                              "and"
141                              "append"
142                              "apply"
143                              "aref"
144                              "array"
145                              "array-as-class"
146                              "array-dimension"
147                              "array-dimensions"
148                              "array-displacement"
149                              "array-in-bounds-p"
150                              "array-misc"
151                              "array-rank"
152                              "array-row-major-index"
153                              "array-t"
154                              "array-total-size"
155                              "arrayp"
156                              "ash"
157                              "assoc"
158                              "assoc-if"
159                              "assoc-if-not"
160                              "atom"
161                              "bit"
162                              "bit-vector"
163                              "bit-vector-p"
164                              "block"
165                              "boundp"
166                              "butlast"
167                              "call-arguments-limit"
168                              "case"
169                              "catch"
170                              "ccase"
171                              "ceiling"
172                              "char-compare"
173                              "char-schar"
174                              "character"
175                              "cl-symbols"
176                              "coerce"
177                              "complement"
178                              "complex"
179                              "complexp"
180                              "concatenate"
181                              "cond"
182                              "cons"
183                              "cons-test-01"
184                              "cons-test-03"
185                              "cons-test-05"
186                              "consp"
187                              "constantly"
188                              "constantp"
189                              "copy-alist"
190                              "copy-list"
191                              "copy-seq"
192                              "copy-symbol"
193                              "copy-tree"
194                              "count"
195                              "count-if"
196                              "count-if-not"
197                              "ctypecase"
198                              "cxr"
199                              "defconstant"
200                              "defmacro"
201                              "defparameter"
202                              "defun"
203                              "defvar"
204                              "destructuring-bind"
205                              "divide"
206                              "ecase"
207                              "elt"
208                              "endp"
209                              "epsilons"
210                              "eql"
211                              "equal"
212                              "equalp"
213                              "error"
214                              "etypecase"
215                              "eval"
216                              "evenp"
217                              "every"
218                              "expt"
219                              "fboundp"
220                              "fceiling"
221                              "fdefinition"
222                              "ffloor"
223                              "fill"
224                              "fill-pointer"
225                              "fill-strings"
226                              "find"
227                              "find-if"
228                              "find-if-not"
229                              "flet"
230                              "floor"
231                              "fmakunbound"
232                              "fround"
233                              "ftruncate"
234                              "funcall"
235                              "function"
236                              "function-lambda-expression"
237                              "functionp"
238                              "gcd"
239                              "gensym"
240                              "get-properties"
241                              "getf"
242                              "handler-bind"
243                              "handler-case"
244                              "hash-table"
245                              "identity"
246                              "if"
247                              "imagpart"
248                              "integer-length"
249                              "integerp"
250                              "intersection"
251                              "isqrt"
252                              "iteration"
253                              "keywordp"
254                              "labels"
255                              "lambda"
256                              "lambda-list-keywords"
257                              "lambda-parameters-limit"
258                              "last"
259                              "ldiff"
260                              "length"
261                              "let"
262                              "list"
263                              "list-length"
264                              "listp"
265                              "loop"
266                              "loop1"
267                              "loop2"
268                              "loop3"
269                              "loop4"
270                              "loop5"
271                              "loop6"
272                              "loop7"
273                              "loop8"
274                              "loop9"
275                              "loop10"
276                              "loop11"
277                              "loop12"
278                              "loop13"
279                              "loop14"
280                              "loop15"
281                              "loop16"
282                              "loop17"
283                              "make-array"
284                              "make-list"
285                              "make-sequence"
286                              "make-string"
287                              "make-symbol"
288                              "map"
289                              "map-into"
290                              "mapc"
291                              "mapcan"
292                              "mapcar"
293                              "mapcon"
294                              "mapl"
295                              "maplist"
296                              "max"
297                              "member"
298                              "member-if"
299                              "member-if-not"
300                              "merge"
301                              "min"
302                              "minus"
303                              "minusp"
304                              "mismatch"
305                              "multiple-value-bind"
306                              "multiple-value-call"
307                              "multiple-value-list"
308                              "multiple-value-prog1"
309                              "multiple-value-setq"
310                              "nbutlast"
311                              "nconc"
312                              "nil"
313                              "nintersection"
314                              "not-and-null"
315                              "notany"
316                              "notevery"
317                              "nreconc"
318                              "nreverse"
319                              "nset-difference"
320                              "nset-exclusive-or"
321                              "nstring-capitalize"
322                              "nstring-downcase"
323                              "nstring-upcase"
324                              "nsublis"
325                              "nsubst"
326                              "nsubst-if"
327                              "nsubst-if-not"
328                              "nsubstitute"
329                              "nsubstitute-if"
330                              "nsubstitute-if-not"
331                              "nth"
332                              "nth-value"
333                              "nthcdr"
334                              "number-comparison"
335                              "numerator-denominator"
336                              "nunion"
337                              "oddp"
338                              "oneminus"
339                              "oneplus"
340                              "or"
341                              "packages"
342                              "pairlis"
343                              "parse-integer"
344                              "phase"
345                              "places"
346                              "plus"
347                              "plusp"
348                              "pop"
349                              "position"
350                              "position-if"
351                              "position-if-not"
352                              "prog"
353                              "prog1"
354                              "prog2"
355                              "progn"
356                              "progv"
357                              "psetf"
358                              "psetq"
359                              "push"
360                              "pushnew"
361                              "random"
362                              "rassoc"
363                              "rassoc-if"
364                              "rassoc-if-not"
365                              "rational"
366                              "rationalize"
367                              "rationalp"
368                              "realp"
369                              "realpart"
370                              "reduce"
371                              "remf"
372                              "remove"
373                              "remove-duplicates"
374                              "replace"
375                              "rest"
376                              "return"
377                              "revappend"
378                              "reverse"
379                              "rotatef"
380                              "round"
381                              "row-major-aref"
382                              "rplaca"
383                              "rplacd"
384                              "sbit"
385                              "search-bitvector"
386                              "search-list"
387                              "search-string"
388                              "search-vector"
389                              "set-difference"
390                              "set-exclusive-or"
391                              "shiftf"
392                              "signum"
393                              "simple-array"
394                              "simple-array-t"
395                              "simple-bit-vector"
396                              "simple-bit-vector-p"
397                              "simple-vector-p"
398                              "some"
399                              "sort"
400                              "special-operator-p"
401                              "string"
402                              "string-capitalize"
403                              "string-comparisons"
404                              "string-downcase"
405                              "string-left-trim"
406                              "string-right-trim"
407                              "string-trim"
408                              "string-upcase"
409                              "sublis"
410                              "subseq"
411                              "subsetp"
412                              "subst"
413                              "subst-if"
414                              "subst-if-not"
415                              "substitute"
416                              "substitute-if"
417                              "substitute-if-not"
418                              "subtypep"
419                              "svref"
420                              "symbol-name"
421                              "t"
422                              "tagbody"
423                              "tailp"
424                              "times"
425                              "tree-equal"
426                              "truncate"
427                              "typecase"
428                              "union"
429                              "unless"
430                              "unwind-protect"
431                              "values"
432                              "values-list"
433                              "vector"
434                              "vector-pop"
435                              "vector-push"
436                              "vector-push-extend"
437                              "vectorp"
438                              "when"
439                              "zerop"))))
440    (dolist (test tests)
441      (load (concatenate 'string rt::*prefix* test suffix)))
442    (format t "~A tests: ~A passed, ~A failed~%"
443            (+ rt::*passed* rt::*failed*)
444            rt::*passed*
445            rt::*failed*)
446    (format t "*compile-tests* was ~A~%" rt::*compile-tests*))
447  (values))
448
449(defun do-all-tests (&optional (compile-tests t))
450  (let ((rt::*compile-tests* compile-tests))
451    (time (do-tests))))
452
453#+armedbear
454(when (and (find-package "JVM")
455           (fboundp 'jvm::jvm-compile))
456  (mapcar #'jvm::jvm-compile '(sys::list-remove-duplicates*
457                               sys::vector-remove-duplicates*
458                               remove-duplicates
459                               union
460                               nunion
461                               intersection
462                               nintersection
463                               subsetp
464                               copy-tree)))
465
466(load (concatenate 'string rt::*prefix* "char-aux.lsp"))
467(load (concatenate 'string rt::*prefix* "cl-symbols-aux.lsp"))
468(load (concatenate 'string rt::*prefix* "cl-symbol-names.lsp"))
469(load (concatenate 'string rt::*prefix* "universe.lsp"))
470(load (concatenate 'string rt::*prefix* "ansi-aux.lsp"))
471(load (concatenate 'string rt::*prefix* "array-aux.lsp"))
472(load (concatenate 'string rt::*prefix* "subseq-aux.lsp"))
473(load (concatenate 'string rt::*prefix* "cons-aux.lsp"))
474(load (concatenate 'string rt::*prefix* "numbers-aux.lsp"))
475(load (concatenate 'string rt::*prefix* "string-aux.lsp"))
476
477#+armedbear
478(when (and (find-package "JVM")
479           (fboundp 'jvm::jvm-compile))
480  (mapcar #'jvm::jvm-compile '(rt::equalp-with-case
481                               cl-test::make-scaffold-copy
482                               cl-test::check-scaffold-copy
483                               cl-test::is-intersection)))
Note: See TracBrowser for help on using the repository browser.