source: trunk/source/tests/ansi-tests/defgeneric-method-combination-min.lsp @ 8991

Last change on this file since 8991 was 8991, checked in by gz, 12 years ago

Check in the gcl ansi test suite (original, in preparation for making local changes)

File size: 5.7 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Sat May 24 21:31:55 2003
4;;;; Contains: Tests of DEFGENERIC with :method-combination MIN
5
6(in-package :cl-test)
7
8(declaim (special *x*))
9
10(compile-and-load "defgeneric-method-combination-aux.lsp")
11
12(deftest defgeneric-method-combination.min.1
13  (let ((*x* nil)
14        (fn
15         (eval '(defgeneric dg-mc.fun.min.1 (x)
16                  (:method-combination min)
17                  (:method min ((x integer)) (car (push 1 *x*)))
18                  (:method min ((x rational)) (car (push 2 *x*)))
19                  (:method min ((x number)) (car (push 3 *x*)))
20                  (:method min ((x t)) (car (push 4 *x*)))))))
21    (declare (type generic-function fn))
22    (flet ((%f (y)
23               (let ((*x* nil))
24                 (list (funcall fn y) *x*))))
25    (values (%f 1) (%f 2/3) (%f 1.54) (%f 'a))))
26  (1 (4 3 2 1)) (2 (4 3 2)) (3 (4 3)) (4 (4)))
27
28(deftest defgeneric-method-combination.min.2
29  (let ((*x* nil)
30        (fn
31         (eval '(defgeneric dg-mc.fun.min.2 (x)
32                  (:method-combination min :most-specific-first)
33                  (:method min ((x integer)) (car (push 1 *x*)))
34                  (:method min ((x rational)) (car (push 2 *x*)))
35                  (:method min ((x number)) (car (push 3 *x*)))
36                  (:method min ((x t)) (car (push 4 *x*)))))))
37    (declare (type generic-function fn))
38    (flet ((%f (y)
39               (let ((*x* nil))
40                 (list (funcall fn y) *x*))))
41    (values (%f 1) (%f 2/3) (%f 1.54) (%f 'a))))
42  (1 (4 3 2 1)) (2 (4 3 2)) (3 (4 3)) (4 (4)))
43
44(deftest defgeneric-method-combination.min.3
45  (let ((*x* nil)
46        (fn
47         (eval '(defgeneric dg-mc.fun.min.3 (x)
48                  (:method-combination min :most-specific-last)
49                  (:method min ((x integer)) (car (push 1 *x*)))
50                  (:method min ((x rational)) (car (push 2 *x*)))
51                  (:method min ((x number)) (car (push 3 *x*)))
52                  (:method min ((x t)) (car (push 4 *x*)))))))
53    (declare (type generic-function fn))
54    (flet ((%f (y)
55               (let ((*x* nil))
56                 (list (funcall fn y) *x*))))
57    (values (%f 1) (%f 2/3) (%f 1.54) (%f 'a))))
58  (1 (1 2 3 4)) (2 (2 3 4)) (3 (3 4)) (4 (4)))
59
60(deftest defgeneric-method-combination.min.4
61  (let ((fn
62         (eval '(defgeneric dg-mc.min.4 (x)
63                  (:method-combination min)
64                  (:method min ((x integer)) 1)
65                  (:method :around ((x rational)) 'foo)
66                  (:method min ((x number)) 2)
67                  (:method min ((x symbol)) 3)
68                  (:method min ((x t)) 4)))))
69    (declare (type generic-function fn))
70    (values
71     (funcall fn 0)
72     (funcall fn 4/3)
73     (funcall fn 1.54)
74     (funcall fn 'x)
75     (funcall fn '(a b c))))
76  foo foo 2 3 4)
77
78(deftest defgeneric-method-combination.min.5
79  (let ((fn
80         (eval '(defgeneric dg-mc.min.5 (x)
81                  (:method-combination min)
82                  (:method min ((x integer)) 1)
83                  (:method :around ((x rational))
84                           (list 'foo (call-next-method)))
85                  (:method min ((x number)) 2)
86                  (:method min ((x symbol)) 4)
87                  (:method min ((x t)) 8)))))
88    (declare (type generic-function fn))
89    (values
90     (funcall fn 0)
91     (funcall fn 4/3)
92     (funcall fn 1.54)
93     (funcall fn 'x)
94     (funcall fn '(a b c))))
95  (foo 1) (foo 2) 2 4 8)
96
97(deftest defgeneric-method-combination.min.6
98  (let ((fn
99         (eval '(defgeneric dg-mc.min.6 (x)
100                  (:method-combination min)
101                  (:method min ((x integer)) 1)
102                  (:method :around ((x rational))
103                           (list 'foo (call-next-method)))
104                  (:method :around ((x real))
105                           (list 'bar (call-next-method)))
106                  (:method min ((x number)) 2)
107                  (:method min ((x symbol)) 4)
108                  (:method min ((x t)) 8)))))
109    (declare (type generic-function fn))
110    (values
111     (funcall fn 0)
112     (funcall fn 4/3)
113     (funcall fn 1.54)
114     (funcall fn #c(1.0 2.0))
115     (funcall fn 'x)
116     (funcall fn '(a b c))))
117  (foo (bar 1)) (foo (bar 2)) (bar 2) 2 4 8)
118
119(deftest defgeneric-method-combination.min.7
120  (let ((fn
121         (eval '(defgeneric dg-mc.min.7 (x)
122                  (:method-combination min)
123                  (:method min ((x dgmc-class-04)) 1)
124                  (:method min ((x dgmc-class-03)) 2)
125                  (:method min ((x dgmc-class-02)) 4)
126                  (:method min ((x dgmc-class-01)) 8)))))
127    (declare (type generic-function fn))
128    (values
129     (funcall fn (make-instance 'dgmc-class-01))
130     (funcall fn (make-instance 'dgmc-class-02))
131     (funcall fn (make-instance 'dgmc-class-03))
132     (funcall fn (make-instance 'dgmc-class-04))))
133  8 4 2 1)
134
135(deftest defgeneric-method-combination.min.8
136  (let ((fn
137         (eval '(defgeneric dg-mc.min.8 (x)
138                  (:method-combination min)
139                  (:method min ((x (eql 1000))) 0)
140                  (:method :around ((x symbol)) (values))
141                  (:method :around ((x integer)) (values 'a 'b 'c))
142                  (:method :around ((x complex)) (call-next-method))
143                  (:method :around ((x number)) (values 1 2 3 4 5 6))
144                  (:method min ((x t)) 1)))))
145    (declare (type generic-function fn))
146    (values
147     (multiple-value-list (funcall fn 'a))
148     (multiple-value-list (funcall fn 10))
149     (multiple-value-list (funcall fn #c(9 8)))
150     (multiple-value-list (funcall fn '(a b c)))))
151  () (a b c) (1 2 3 4 5 6) (1))
152
153(deftest defgeneric-method-combination.min.9
154  (handler-case
155   (let ((fn (eval '(defgeneric dg-mc.min.9 (x)
156                      (:method-combination min)))))
157     (declare (type generic-function fn))
158     (funcall fn (list 'a)))
159   (error () :error))
160  :error)
161
162(deftest defgeneric-method-combination.min.10
163  (progn
164    (eval '(defgeneric dg-mc.min.10 (x)
165             (:method-combination min)
166             (:method ((x t)) 0)))
167    (handler-case
168     (dg-mc.min.10 'a)
169     (error () :error)))
170  :error)
171
172(deftest defgeneric-method-combination.min.11
173  (progn
174    (eval '(defgeneric dg-mc.min.11 (x)
175             (:method-combination min)
176             (:method nonsense ((x t)) 0)))
177    (handler-case
178     (dg-mc.min.11 0)
179     (error () :error)))
180  :error)
181
182(deftest defgeneric-method-combination.min.12
183  (let ((fn (eval '(defgeneric dg-mc.min.12 (x)
184                     (:method-combination min)
185                     (:method :around ((x t)) 1)
186                     (:method min ((x integer)) x)))))
187    (declare (type generic-function fn))
188    (handler-case (funcall fn 'a)
189                  (error () :error)))
190  :error)
191
Note: See TracBrowser for help on using the repository browser.