min.lsp 4.58 KB
Newer Older
pfdietz's avatar
pfdietz committed
1 2 3 4 5 6 7 8 9 10
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Mon Aug  4 21:24:45 2003
;;;; Contains: Tests of MIN

(in-package :cl-test)

(compile-and-load "numbers-aux.lsp")

(deftest min.error.1
11 12
  (signals-error (min) program-error)
  t)
pfdietz's avatar
pfdietz committed
13 14

(deftest min.error.2
pfdietz's avatar
pfdietz committed
15
  (check-type-error #'min #'realp)
pfdietz's avatar
pfdietz committed
16 17
  nil)

pfdietz's avatar
pfdietz committed
18
(deftest min.error.3
pfdietz's avatar
pfdietz committed
19
  (check-type-error #'(lambda (x) (min 0 x)) #'realp)
pfdietz's avatar
pfdietz committed
20 21
  nil)

pfdietz's avatar
pfdietz committed
22 23
(deftest min.1
  (loop for n in *reals*
sds's avatar
sds committed
24 25 26 27 28 29 30 31
        when (or (not (eql (min n) n))
                 (not (eql (min n n) n))
                 (not (eql (min n n n) n))
                 (not (eql (apply #'min (make-list
                                         (min 256 (1- call-arguments-limit))
                                         :initial-element n))
                           n)))
        collect n)
pfdietz's avatar
pfdietz committed
32 33 34 35 36 37 38 39
  nil)

(deftest min.2
  (min.2-fn)
  nil)

(deftest min.3
  (loop for x = (- (random 60000) 30000)
sds's avatar
sds committed
40 41 42 43 44 45
        for y = (- (random 60000) 30000)
        for m = (min x y)
        for m2 = (if (<= x y) x y)
        repeat 1000
        unless (eql m m2)
        collect (list x y m m2))
pfdietz's avatar
pfdietz committed
46 47 48 49
  nil)

(deftest min.4
  (loop for x = (- (random 6000000) 3000000)
sds's avatar
sds committed
50 51 52 53 54 55
        for y = (- (random 6000000) 3000000)
        for m = (min x y)
        for m2 = (if (<= x y) x y)
        repeat 1000
        unless (eql m m2)
        collect (list x y m m2))
pfdietz's avatar
pfdietz committed
56 57 58 59
  nil)

(deftest min.5
  (loop for x = (- (random 1000000000000) 500000000000)
sds's avatar
sds committed
60 61 62 63 64 65
        for y = (- (random 1000000000000) 500000000000)
        for m = (min x y)
        for m2 = (if (<= x y) x y)
        repeat 1000
        unless (eql m m2)
        collect (list x y m m2))
pfdietz's avatar
pfdietz committed
66 67 68 69 70
  nil)

(deftest min.6
  (let ((m (min 0 1.0s0)))
    (or (eqlt m 0)
sds's avatar
sds committed
71
        (eqlt m 0.0s0)))
pfdietz's avatar
pfdietz committed
72 73 74 75 76 77 78 79 80
  t)

(deftest min.7
  (min 2 1.0s0)
  1.0s0)

(deftest min.8
  (let ((m (min 2 3.0f0)))
    (or (eqlt m 2)
sds's avatar
sds committed
81
        (eqlt m 2.0f0)))
pfdietz's avatar
pfdietz committed
82 83 84 85 86 87 88 89 90
  t)

(deftest min.9
  (min 2 1.0f0)
  1.0f0)

(deftest min.10
  (let ((m (min 2 10.0d0)))
    (or (eqlt m 2)
sds's avatar
sds committed
91
        (eqlt m 2.0d0)))
pfdietz's avatar
pfdietz committed
92 93 94 95 96 97 98 99 100
  t)

(deftest min.11
  (min 100 1.0d0)
  1.0d0)

(deftest min.12
  (let ((m (min 2 17.25l0)))
    (or (eqlt m 2)
sds's avatar
sds committed
101
        (eqlt m 2.0l0)))
pfdietz's avatar
pfdietz committed
102 103 104 105 106 107 108 109 110
  t)

(deftest min.13
  (min 2 1.0l0)
  1.0l0)

(deftest min.15
  (let ((m (min 1.0s0 2.0f0)))
    (or (eqlt m 1.0s0)
sds's avatar
sds committed
111
        (eqlt m 1.0f0)))
pfdietz's avatar
pfdietz committed
112 113 114 115 116 117 118 119 120
  t)

(deftest min.16
  (min 3.0s0 1.0f0)
  1.0f0)

(deftest min.17
  (let ((m (min 1.0s0 2.0d0)))
    (or (eqlt m 1.0s0)
sds's avatar
sds committed
121
        (eqlt m 1.0d0)))
pfdietz's avatar
pfdietz committed
122 123 124 125 126 127 128 129 130
  t)

(deftest min.18
  (min 5.0s0 1.0d0)
  1.0d0)

(deftest min.19
  (let ((m (min 1.0s0 2.0l0)))
    (or (eqlt m 1.0s0)
sds's avatar
sds committed
131
        (eqlt m 1.0l0)))
pfdietz's avatar
pfdietz committed
132 133 134 135 136 137 138 139 140
  t)

(deftest min.20
  (min 2.0s0 1.0l0)
  1.0l0)

(deftest min.21
  (let ((m (min 1.0f0 2.0d0)))
    (or (eqlt m 1.0f0)
sds's avatar
sds committed
141
        (eqlt m 1.0d0)))
pfdietz's avatar
pfdietz committed
142 143 144 145 146 147 148 149 150
  t)

(deftest min.22
  (min 18.0f0 1.0d0)
  1.0d0)

(deftest min.23
  (let ((m (min 1.0f0 100.0l0)))
    (or (eqlt m 1.0f0)
sds's avatar
sds committed
151
        (eqlt m 1.0l0)))
pfdietz's avatar
pfdietz committed
152 153 154 155 156 157 158 159 160
  t)

(deftest min.24
  (min 19.0f0 1.0l0)
  1.0l0)

(deftest min.25
  (let ((m (min 1.0d0 12.0l0)))
    (or (eqlt m 1.0d0)
sds's avatar
sds committed
161
        (eqlt m 1.0l0)))
pfdietz's avatar
pfdietz committed
162 163 164 165 166 167 168
  t)

(deftest min.26
  (min 15.0d0 1.0l0)
  1.0l0)

(deftest min.27
169
  (loop for i from 1 to (min 256 (1- call-arguments-limit))
sds's avatar
sds committed
170 171 172 173
        for x = (make-list i :initial-element 1)
        do (setf (elt x (random i)) 0)
        unless (eql (apply #'min x) 0)
        collect x)
pfdietz's avatar
pfdietz committed
174 175 176 177 178
  nil)

(deftest min.28
  (let ((m (min 1/3 0.8s0)))
    (or (eqlt m 1/3)
sds's avatar
sds committed
179
        (eqlt m (float 1/3 0.8s0))))
pfdietz's avatar
pfdietz committed
180 181 182 183 184
  t)

(deftest min.29
  (let ((m (min 1.0s0 -3 2.0f0)))
    (or (eqlt m -3)
sds's avatar
sds committed
185
        (eqlt m -3.0f0)))
pfdietz's avatar
pfdietz committed
186 187 188 189 190
  t)

(deftest min.30
  (let ((m (min 1.0d0 -3 2.0f0)))
    (or (eqlt m -3)
sds's avatar
sds committed
191
        (eqlt m -3.0d0)))
pfdietz's avatar
pfdietz committed
192 193 194 195 196
  t)

(deftest min.31
  (let ((m (min 1.0s0 -3 2.0l0)))
    (or (eqlt m -3)
sds's avatar
sds committed
197
        (eqlt m -3.0l0)))
pfdietz's avatar
pfdietz committed
198 199 200 201 202
  t)

(deftest min.32
  (let ((m (min 1.0l0 -3 2.0s0)))
    (or (eqlt m -3)
sds's avatar
sds committed
203
        (eqlt m -3.0l0)))
pfdietz's avatar
pfdietz committed
204 205 206 207 208
  t)

(deftest min.33
  (let ((m (min 1.0d0 -3 2.0l0)))
    (or (eqlt m -3)
sds's avatar
sds committed
209
        (eqlt m -3.0l0)))
pfdietz's avatar
pfdietz committed
210 211 212 213 214
  t)

(deftest min.34
  (let ((m (min 1.0l0 -3 2.0d0)))
    (or (eqlt m -3)
sds's avatar
sds committed
215
        (eqlt m -3.0l0)))
pfdietz's avatar
pfdietz committed
216 217 218 219 220 221
  t)

(deftest min.order.1
  (let ((i 0) x y)
    (values
     (min (progn (setf x (incf i)) 10)
sds's avatar
sds committed
222
          (progn (setf y (incf i)) 20))
pfdietz's avatar
pfdietz committed
223 224 225 226 227 228 229
     i x y))
  10 2 1 2)

(deftest min.order.2
  (let ((i 0) x y z)
    (values
     (min (progn (setf x (incf i)) 10)
sds's avatar
sds committed
230 231
          (progn (setf y (incf i)) 20)
          (progn (setf z (incf i)) 30))
pfdietz's avatar
pfdietz committed
232 233 234 235 236 237 238
     i x y z))
  10 3 1 2 3)

(deftest min.order.3
  (let ((i 0) u v w x y z)
    (values
     (min (progn (setf u (incf i)) 10)
sds's avatar
sds committed
239 240 241 242 243
          (progn (setf v (incf i)) 20)
          (progn (setf w (incf i)) 30)
          (progn (setf x (incf i)) 10)
          (progn (setf y (incf i)) 20)
          (progn (setf z (incf i)) 30))
pfdietz's avatar
pfdietz committed
244 245
     i u v w x y z))
  10 6 1 2 3 4 5 6)