source: trunk/source/tests/ansi-tests/max.lsp @ 8991

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

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

File size: 4.1 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Sun Aug  3 15:55:17 2003
4;;;; Contains: Tests of MAX
5
6(in-package :cl-test)
7
8(compile-and-load "numbers-aux.lsp")
9
10;;; Error tests
11
12(deftest max.error.1
13  (signals-error (max) program-error)
14  t)
15
16(deftest max.error.2
17  (check-type-error #'max #'realp)
18  nil)
19
20(deftest max.error.3
21  (check-type-error #'(lambda (x) (max 0 x)) #'realp)
22  nil)
23
24;;; Non-error tests
25
26(deftest max.1
27  (loop for n in *reals*
28        when (or (not (eql (max n) n))
29                 (not (eql (max n n) n))
30                 (not (eql (max n n n) n))
31                 (not (eql (apply #'max (make-list
32                                         (min 256 (1- call-arguments-limit))
33                                         :initial-element n))
34                           n)))
35        collect n)
36  nil)
37
38(deftest max.2
39  (max.2-fn)
40  nil)
41
42(deftest max.3
43  (loop for x = (- (random 60000) 30000)
44        for y = (- (random 60000) 30000)
45        for m = (max x y)
46        for m2 = (if (>= x y) x y)
47        repeat 1000
48        unless (eql m m2)
49        collect (list x y m m2))
50  nil)
51
52(deftest max.4
53  (loop for x = (- (random 6000000) 3000000)
54        for y = (- (random 6000000) 3000000)
55        for m = (max x y)
56        for m2 = (if (>= x y) x y)
57        repeat 1000
58        unless (eql m m2)
59        collect (list x y m m2))
60  nil)
61
62(deftest max.5
63  (loop for x = (- (random 1000000000000) 500000000000)
64        for y = (- (random 1000000000000) 500000000000)
65        for m = (max x y)
66        for m2 = (if (>= x y) x y)
67        repeat 1000
68        unless (eql m m2)
69        collect (list x y m m2))
70  nil)
71
72(deftest max.6
73  (let ((m (max 2 1.0s0)))
74    (or (eqlt m 2)
75        (eqlt m 2.0s0)))
76  t)
77
78(deftest max.7
79  (max 0 1.0s0)
80  1.0s0)
81
82(deftest max.8
83  (let ((m (max 2 1.0f0)))
84    (or (eqlt m 2)
85        (eqlt m 2.0f0)))
86  t)
87
88(deftest max.9
89  (max 0 1.0f0)
90  1.0f0)
91
92(deftest max.10
93  (let ((m (max 2 1.0d0)))
94    (or (eqlt m 2)
95        (eqlt m 2.0d0)))
96  t)
97
98(deftest max.11
99  (max 0 1.0d0)
100  1.0d0)
101
102(deftest max.12
103  (let ((m (max 2 1.0l0)))
104    (or (eqlt m 2)
105        (eqlt m 2.0l0)))
106  t)
107
108(deftest max.13
109  (max 0 1.0l0)
110  1.0l0)
111
112(deftest max.15
113  (let ((m (max 1.0s0 0.0f0)))
114    (or (eqlt m 1.0s0)
115        (eqlt m 1.0f0)))
116  t)
117
118(deftest max.16
119  (max 0.0s0 1.0f0)
120  1.0f0)
121
122(deftest max.17
123  (let ((m (max 1.0s0 0.0d0)))
124    (or (eqlt m 1.0s0)
125        (eqlt m 1.0d0)))
126  t)
127
128(deftest max.18
129  (max 0.0s0 1.0d0)
130  1.0d0)
131
132(deftest max.19
133  (let ((m (max 1.0s0 0.0l0)))
134    (or (eqlt m 1.0s0)
135        (eqlt m 1.0l0)))
136  t)
137
138(deftest max.20
139  (max 0.0s0 1.0l0)
140  1.0l0)
141
142(deftest max.21
143  (let ((m (max 1.0f0 0.0d0)))
144    (or (eqlt m 1.0f0)
145        (eqlt m 1.0d0)))
146  t)
147
148(deftest max.22
149  (max 0.0f0 1.0d0)
150  1.0d0)
151
152(deftest max.23
153  (let ((m (max 1.0f0 0.0l0)))
154    (or (eqlt m 1.0f0)
155        (eqlt m 1.0l0)))
156  t)
157
158(deftest max.24
159  (max 0.0f0 1.0l0)
160  1.0l0)
161
162(deftest max.25
163  (let ((m (max 1.0d0 0.0l0)))
164    (or (eqlt m 1.0d0)
165        (eqlt m 1.0l0)))
166  t)
167
168(deftest max.26
169  (max 0.0d0 1.0l0)
170  1.0l0)
171
172(deftest max.27
173  (loop for i from 1 to (min 256 (1- call-arguments-limit))
174        for x = (make-list i :initial-element 0)
175        do (setf (elt x (random i)) 1)
176        unless (eql (apply #'max x) 1)
177        collect x)
178  nil)
179
180(deftest max.28
181  (let ((m (max 1/3 0.2s0)))
182    (or (eqlt m 1/3)
183        (eqlt m (float 1/3 0.2s0))))
184  t)
185
186(deftest max.29
187  (let ((m (max 1.0s0 3 2.0f0)))
188    (or (eqlt m 3)
189        (eqlt m 3.0f0)))
190  t)
191
192(deftest max.30
193  (let ((m (max 1.0d0 3 2.0f0)))
194    (or (eqlt m 3)
195        (eqlt m 3.0d0)))
196  t)
197
198(deftest max.31
199  (let ((m (max 1.0s0 3 2.0l0)))
200    (or (eqlt m 3)
201        (eqlt m 3.0l0)))
202  t)
203
204(deftest max.32
205  (let ((m (max 1.0l0 3 2.0s0)))
206    (or (eqlt m 3)
207        (eqlt m 3.0l0)))
208  t)
209
210(deftest max.33
211  (let ((m (max 1.0d0 3 2.0l0)))
212    (or (eqlt m 3)
213        (eqlt m 3.0l0)))
214  t)
215
216(deftest max.34
217  (let ((m (max 1.0l0 3 2.0d0)))
218    (or (eqlt m 3)
219        (eqlt m 3.0l0)))
220  t)
221
222(deftest max.order.1
223  (let ((i 0) x y)
224    (values
225     (max (progn (setf x (incf i)) 10)
226          (progn (setf y (incf i)) 20))
227     i x y))
228  20 2 1 2)
229
230(deftest max.order.2
231  (let ((i 0) x y z)
232    (values
233     (max (progn (setf x (incf i)) 10)
234          (progn (setf y (incf i)) 20)
235          (progn (setf z (incf i)) 30))
236     i x y z))
237  30 3 1 2 3)
238
239(deftest max.order.3
240  (let ((i 0) u v w x y z)
241    (values
242     (max (progn (setf u (incf i)) 10)
243          (progn (setf v (incf i)) 20)
244          (progn (setf w (incf i)) 30)
245          (progn (setf x (incf i)) 10)
246          (progn (setf y (incf i)) 20)
247          (progn (setf z (incf i)) 30))
248     i u v w x y z))
249  30 6 1 2 3 4 5 6)
Note: See TracBrowser for help on using the repository browser.