2
;;;; Author: Paul Dietz
3
;;;; Created: Sun Jun 15 10:49:39 2003
4
;;;; Contains: Tests of DEFINE-METHOD-COMBINATION
8
(defclass dmc-class-01a () ())
9
(defclass dmc-class-01b (dmc-class-01a) ())
10
(defclass dmc-class-01c (dmc-class-01a) ())
11
(defclass dmc-class-01d (dmc-class-01b dmc-class-01c) ())
12
(defclass dmc-class-01e (dmc-class-01c dmc-class-01b) ())
13
(defclass dmc-class-01f (dmc-class-01d) ())
14
(defclass dmc-class-01g (dmc-class-01a) ())
15
(defclass dmc-class-01h (dmc-class-01f dmc-class-01g) ())
17
(eval-when (:load-toplevel :compile-toplevel :execute)
18
(report-and-ignore-errors
20
(define-method-combination times
21
:documentation "Multiplicative method combination, version 1"
24
(defgeneric dmc-gf-01 (x) (:method-combination times))
26
(defmethod dmc-gf-01 times ((x integer)) 2)
27
(defmethod dmc-gf-01 times ((x rational)) 3)
28
(defmethod dmc-gf-01 times ((x real)) 5)
29
(defmethod dmc-gf-01 times ((x number)) 7)
30
(defmethod dmc-gf-01 times ((x complex)) 11)
33
(deftest define-method-combination-01.1
41
(deftest define-method-combination-01.2
43
(eval '(locally (declare (optimize (safety 3)))
48
(deftest define-method-combination-01.3
52
(deftest define-method-combination-01.4
53
(let ((doc (documentation *dmc-times* 'method-combination)))
55
(equalt doc "Multiplicative method combination, version 1")))
58
(eval-when (:load-toplevel :compile-toplevel :execute)
59
(report-and-ignore-errors
60
(defgeneric dmc-gf-02 (x) (:method-combination times))
62
(defmethod dmc-gf-02 times ((x integer)) 2)
63
(defmethod dmc-gf-02 :around ((x rational)) (1- (call-next-method)))
64
(defmethod dmc-gf-02 times ((x real)) 3)
65
(defmethod dmc-gf-02 times ((x number)) 5)
66
(defmethod dmc-gf-02 :around ((x (eql 1.0s0))) 1)
69
(deftest define-method-combination-02.1
78
(eval-when (:load-toplevel :compile-toplevel :execute)
79
(report-and-ignore-errors
80
(defgeneric dmc-gf-03 (x) (:method-combination times))))
82
(deftest define-method-combination-03.1
86
(eval '(defmethod dmc-gf-03 ((x integer)) t))
90
(dolist (meth (compute-applicable-methods #'dmc-gf-03 (list 1)))
91
(remove-method #'dmc-gf-03 meth)))
94
(deftest define-method-combination-03.2
98
(eval '(defmethod dmc-gf-03 :before ((x cons)) t))
99
(eval '(dmc-gf-03 (cons 'a 'b)))
102
(dolist (meth (compute-applicable-methods #'dmc-gf-03 (list '(a))))
103
(remove-method #'dmc-gf-03 meth)))
106
(deftest define-method-combination-03.3
110
(eval '(defmethod dmc-gf-03 :after ((x symbol)) t))
111
(eval '(dmc-gf-03 'a))
114
(dolist (meth (compute-applicable-methods #'dmc-gf-03 (list 'a)))
115
(remove-method #'dmc-gf-03 meth)))
118
(eval-when (:load-toplevel :compile-toplevel :execute)
119
(report-and-ignore-errors
120
(define-method-combination times2
122
:identity-with-one-argument t)
124
(defgeneric dmc-gf-04 (x) (:method-combination times2))
126
(defmethod dmc-gf-04 times2 ((x dmc-class-01b)) 2)
127
(defmethod dmc-gf-04 times2 ((x dmc-class-01c)) 3)
128
(defmethod dmc-gf-04 times2 ((x dmc-class-01d)) 5)
129
(defmethod dmc-gf-04 times2 ((x symbol)) nil)
132
(deftest define-method-combination-04.1
133
(dmc-gf-04 (make-instance 'dmc-class-01h))
136
(deftest define-method-combination-04.2
137
(dmc-gf-04 (make-instance 'dmc-class-01e))
140
(deftest define-method-combination-04.3
144
(eval-when (:load-toplevel :compile-toplevel :execute)
145
(report-and-ignore-errors
146
(defvar *dmc-times-5*
147
(define-method-combination times-5 :operator *))))
149
(deftest define-method-combination-05.1
150
(let* ((doc1 (setf (documentation *dmc-times-5* 'method-combination)
152
(doc2 (documentation *dmc-times-5* 'method-combination)))
156
(equalt doc2 "foo"))))
159
;; Operator name defaults to the method combination name.
161
(eval-when (:load-toplevel :compile-toplevel :execute)
162
(defun times-7 (&rest args) (apply #'* args))
163
(report-and-ignore-errors
164
(defvar *dmc-times-7*
165
(define-method-combination times-7))
166
(defgeneric dmc-gf-07 (x) (:method-combination times))
168
(defmethod dmc-gf-07 times ((x integer)) 2)
169
(defmethod dmc-gf-07 times ((x rational)) 3)
170
(defmethod dmc-gf-07 times ((x real)) 5)
171
(defmethod dmc-gf-07 times ((x number)) 7)
172
(defmethod dmc-gf-07 times ((x complex)) 11)
175
(deftest define-method-combination-07.1