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

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

divide

File size: 17.5 KB
Line 
1;;; rt.lisp
2;;;
3;;; Copyright (C) 2003 Peter Graves
4;;; $Id: rt.lisp,v 1.109 2003-09-04 16:21: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(unless (find-package :cl-test)
107  (make-package :cl-test)
108  (use-package "COMMON-LISP" :cl-test))
109
110(in-package :cl-test)
111(use-package :rt)
112
113(defvar *compiled-and-loaded-files* nil)
114
115(defun compile-and-load (filename &key force)
116  (let* ((pathname (concatenate 'string rt::*prefix* filename))
117         (former-data (assoc pathname *compiled-and-loaded-files*
118           :test #'equal))
119   (source-write-time (file-write-date pathname)))
120    (unless (and (not force)
121     former-data
122     (>= (cadr former-data) source-write-time))
123      (if former-data
124    (setf (cadr former-data) source-write-time)
125          (push (list pathname source-write-time) *compiled-and-loaded-files*))
126      (load pathname))))
127
128(in-package :cl-user)
129
130(defun do-tests (&rest args)
131  (let ((rt::*passed* 0) (rt::*failed* 0)
132        (suffix ".lsp")
133        (tests (or args (list "abs"
134                              "acons"
135                              "adjoin"
136                              "and"
137                              "append"
138                              "apply"
139                              "aref"
140                              "array"
141                              "array-as-class"
142                              "array-dimension"
143                              "array-dimensions"
144                              "array-displacement"
145                              "array-in-bounds-p"
146                              "array-misc"
147                              "array-rank"
148                              "array-row-major-index"
149                              "array-t"
150                              "array-total-size"
151                              "arrayp"
152                              "assoc"
153                              "assoc-if"
154                              "assoc-if-not"
155                              "atom"
156                              "bit"
157                              "bit-vector"
158                              "bit-vector-p"
159                              "block"
160                              "boundp"
161                              "butlast"
162                              "call-arguments-limit"
163                              "case"
164                              "catch"
165                              "ccase"
166                              "ceiling"
167                              "char-compare"
168                              "char-schar"
169                              "character"
170                              "cl-symbols"
171                              "coerce"
172                              "complement"
173                              "concatenate"
174                              "cond"
175                              "cons"
176                              "cons-test-01"
177                              "cons-test-03"
178                              "cons-test-05"
179                              "consp"
180                              "constantly"
181                              "constantp"
182                              "copy-alist"
183                              "copy-list"
184                              "copy-seq"
185                              "copy-symbol"
186                              "copy-tree"
187                              "count"
188                              "count-if"
189                              "count-if-not"
190                              "ctypecase"
191                              "cxr"
192                              "defconstant"
193                              "defmacro"
194                              "defparameter"
195                              "defun"
196                              "defvar"
197                              "destructuring-bind"
198                              "divide"
199                              "ecase"
200                              "elt"
201                              "endp"
202                              "epsilons"
203                              "eql"
204                              "equal"
205                              "equalp"
206                              "error"
207                              "etypecase"
208                              "eval"
209                              "evenp"
210                              "every"
211                              "expt"
212                              "fboundp"
213                              "fceiling"
214                              "fdefinition"
215                              "ffloor"
216                              "fill"
217                              "fill-pointer"
218                              "fill-strings"
219                              "find"
220                              "find-if"
221                              "find-if-not"
222                              "flet"
223                              "floor"
224                              "fmakunbound"
225                              "fround"
226                              "ftruncate"
227                              "funcall"
228                              "function"
229                              "function-lambda-expression"
230                              "functionp"
231                              "gcd"
232                              "gensym"
233                              "get-properties"
234                              "getf"
235                              "handler-bind"
236                              "handler-case"
237                              "hash-table"
238                              "identity"
239                              "if"
240                              "intersection"
241                              "iteration"
242                              "keywordp"
243                              "labels"
244                              "lambda"
245                              "lambda-list-keywords"
246                              "lambda-parameters-limit"
247                              "last"
248                              "ldiff"
249                              "length"
250                              "let"
251                              "list"
252                              "list-length"
253                              "listp"
254                              "loop"
255                              "loop1"
256                              "loop2"
257                              "loop3"
258                              "loop4"
259                              "loop5"
260                              "loop6"
261                              "loop7"
262                              "loop8"
263                              "loop9"
264                              "loop10"
265                              "loop11"
266                              "loop12"
267                              "loop13"
268                              "loop14"
269                              "loop15"
270                              "loop16"
271                              "loop17"
272                              "make-array"
273                              "make-list"
274                              "make-sequence"
275                              "make-string"
276                              "make-symbol"
277                              "map"
278                              "map-into"
279                              "mapc"
280                              "mapcan"
281                              "mapcar"
282                              "mapcon"
283                              "mapl"
284                              "maplist"
285                              "max"
286                              "member"
287                              "member-if"
288                              "member-if-not"
289                              "merge"
290                              "min"
291                              "minus"
292                              "minusp"
293                              "mismatch"
294                              "multiple-value-bind"
295                              "multiple-value-call"
296                              "multiple-value-list"
297                              "multiple-value-prog1"
298                              "multiple-value-setq"
299                              "nbutlast"
300                              "nconc"
301                              "nil"
302                              "nintersection"
303                              "not-and-null"
304                              "notany"
305                              "notevery"
306                              "nreconc"
307                              "nreverse"
308                              "nset-difference"
309                              "nset-exclusive-or"
310                              "nstring-capitalize"
311                              "nstring-downcase"
312                              "nstring-upcase"
313                              "nsublis"
314                              "nsubst"
315                              "nsubst-if"
316                              "nsubst-if-not"
317                              "nsubstitute"
318                              "nsubstitute-if"
319                              "nsubstitute-if-not"
320                              "nth"
321                              "nth-value"
322                              "nthcdr"
323                              "number-comparison"
324                              "nunion"
325                              "oddp"
326                              "oneminus"
327                              "oneplus"
328                              "or"
329                              "packages"
330                              "pairlis"
331                              "places"
332                              "plus"
333                              "plusp"
334                              "pop"
335                              "position"
336                              "position-if"
337                              "position-if-not"
338                              "prog"
339                              "prog1"
340                              "prog2"
341                              "progn"
342                              "progv"
343                              "psetf"
344                              "psetq"
345                              "push"
346                              "pushnew"
347                              "rassoc"
348                              "rassoc-if"
349                              "rassoc-if-not"
350                              "rational"
351                              "rationalize"
352                              "reduce"
353                              "remf"
354                              "remove"
355                              "remove-duplicates"
356                              "replace"
357                              "rest"
358                              "return"
359                              "revappend"
360                              "reverse"
361                              "rotatef"
362                              "round"
363                              "row-major-aref"
364                              "rplaca"
365                              "rplacd"
366                              "sbit"
367                              "search-bitvector"
368                              "search-list"
369                              "search-string"
370                              "search-vector"
371                              "set-difference"
372                              "set-exclusive-or"
373                              "shiftf"
374                              "simple-array"
375                              "simple-array-t"
376                              "simple-bit-vector"
377                              "simple-bit-vector-p"
378                              "simple-vector-p"
379                              "some"
380                              "sort"
381                              "special-operator-p"
382                              "string"
383                              "string-capitalize"
384                              "string-comparisons"
385                              "string-downcase"
386                              "string-left-trim"
387                              "string-right-trim"
388                              "string-trim"
389                              "string-upcase"
390                              "sublis"
391                              "subseq"
392                              "subsetp"
393                              "subst"
394                              "subst-if"
395                              "subst-if-not"
396                              "substitute"
397                              "substitute-if"
398                              "substitute-if-not"
399                              "subtypep"
400                              "svref"
401                              "symbol-name"
402                              "t"
403                              "tagbody"
404                              "tailp"
405                              "times"
406                              "tree-equal"
407                              "truncate"
408                              "typecase"
409                              "union"
410                              "unless"
411                              "unwind-protect"
412                              "values"
413                              "values-list"
414                              "vector"
415                              "vector-pop"
416                              "vector-push"
417                              "vector-push-extend"
418                              "vectorp"
419                              "when"
420                              "zerop"))))
421    (dolist (test tests)
422      (load (concatenate 'string rt::*prefix* test suffix)))
423    (format t "~A tests: ~A passed, ~A failed~%"
424            (+ rt::*passed* rt::*failed*)
425            rt::*passed*
426            rt::*failed*)
427    (format t "*compile-tests* was ~A~%" rt::*compile-tests*))
428  (values))
429
430(defun do-all-tests (&optional (compile-tests t))
431  (let ((rt::*compile-tests* compile-tests))
432    (time (do-tests))))
433
434#+armedbear
435(when (and (find-package "JVM")
436           (fboundp 'jvm::jvm-compile))
437  (mapcar #'jvm::jvm-compile '(sys::list-remove-duplicates*
438                               sys::vector-remove-duplicates*
439                               remove-duplicates
440                               union
441                               nunion
442                               intersection
443                               nintersection
444                               subsetp
445                               copy-tree)))
446
447(load (concatenate 'string rt::*prefix* "char-aux.lsp"))
448(load (concatenate 'string rt::*prefix* "cl-symbols-aux.lsp"))
449(load (concatenate 'string rt::*prefix* "cl-symbol-names.lsp"))
450(load (concatenate 'string rt::*prefix* "ansi-aux-macros.lsp"))
451(load (concatenate 'string rt::*prefix* "universe.lsp"))
452(load (concatenate 'string rt::*prefix* "ansi-aux.lsp"))
453(load (concatenate 'string rt::*prefix* "array-aux.lsp"))
454(load (concatenate 'string rt::*prefix* "subseq-aux.lsp"))
455(load (concatenate 'string rt::*prefix* "cons-aux.lsp"))
456(load (concatenate 'string rt::*prefix* "numbers-aux.lsp"))
457(load (concatenate 'string rt::*prefix* "string-aux.lsp"))
458
459#+armedbear
460(when (and (find-package "JVM")
461           (fboundp 'jvm::jvm-compile))
462  (mapcar #'jvm::jvm-compile '(rt::equalp-with-case
463                               cl-test::make-scaffold-copy
464                               cl-test::check-scaffold-copy
465                               cl-test::is-intersection)))
Note: See TracBrowser for help on using the repository browser.