1 | ;-*- Mode: Lisp -*- |
---|
2 | ;;;; Author: Paul Dietz |
---|
3 | ;;;; Created: Tue Aug 19 06:50:44 2003 |
---|
4 | ;;;; Contains: Tests of CEILING |
---|
5 | |
---|
6 | (in-package :cl-test) |
---|
7 | |
---|
8 | (compile-and-load "numbers-aux.lsp") |
---|
9 | (compile-and-load "ceiling-aux.lsp") |
---|
10 | |
---|
11 | (deftest ceiling.error.1 |
---|
12 | (signals-error (ceiling) program-error) |
---|
13 | t) |
---|
14 | |
---|
15 | (deftest ceiling.error.2 |
---|
16 | (signals-error (ceiling 1.0 1 nil) program-error) |
---|
17 | t) |
---|
18 | |
---|
19 | ;;; |
---|
20 | |
---|
21 | (deftest ceiling.1 |
---|
22 | (ceiling.1-fn) |
---|
23 | nil) |
---|
24 | |
---|
25 | (deftest ceiling.2 |
---|
26 | (ceiling.2-fn) |
---|
27 | nil) |
---|
28 | |
---|
29 | (deftest ceiling.3 |
---|
30 | (ceiling.3-fn 2.0s4) |
---|
31 | nil) |
---|
32 | |
---|
33 | (deftest ceiling.4 |
---|
34 | (ceiling.3-fn 2.0f4) |
---|
35 | nil) |
---|
36 | |
---|
37 | (deftest ceiling.5 |
---|
38 | (ceiling.3-fn 2.0d4) |
---|
39 | nil) |
---|
40 | |
---|
41 | (deftest ceiling.6 |
---|
42 | (ceiling.3-fn 2.0l4) |
---|
43 | nil) |
---|
44 | |
---|
45 | (deftest ceiling.7 |
---|
46 | (ceiling.7-fn) |
---|
47 | nil) |
---|
48 | |
---|
49 | (deftest ceiling.8 |
---|
50 | (ceiling.8-fn) |
---|
51 | nil) |
---|
52 | |
---|
53 | (deftest ceiling.9 |
---|
54 | (ceiling.9-fn) |
---|
55 | nil) |
---|
56 | |
---|
57 | (deftest ceiling.10 |
---|
58 | (loop for x in (remove-if #'zerop *reals*) |
---|
59 | for (q r) = (multiple-value-list (ceiling x x)) |
---|
60 | unless (and (eql q 1) |
---|
61 | (zerop r) |
---|
62 | (if (rationalp x) (eql r 0) |
---|
63 | (eql r (float 0 x)))) |
---|
64 | collect x) |
---|
65 | nil) |
---|
66 | |
---|
67 | (deftest ceiling.11 |
---|
68 | (loop for x in (remove-if #'zerop *reals*) |
---|
69 | for (q r) = (multiple-value-list (ceiling (- x) x)) |
---|
70 | unless (and (eql q -1) |
---|
71 | (zerop r) |
---|
72 | (if (rationalp x) (eql r 0) |
---|
73 | (eql r (float 0 x)))) |
---|
74 | collect x) |
---|
75 | nil) |
---|
76 | |
---|
77 | (deftest ceiling.12 |
---|
78 | (let* ((radix (float-radix 1.0s0)) |
---|
79 | (rad (float radix 1.0s0)) |
---|
80 | (rrad (/ 1.0s0 rad))) |
---|
81 | (loop for i from 1 to 1000 |
---|
82 | for x = (+ i rrad) |
---|
83 | for (q r) = (multiple-value-list (ceiling x)) |
---|
84 | unless (and (eql q (1+ i)) |
---|
85 | (eql r (- rrad 1))) |
---|
86 | collect (list i x q r))) |
---|
87 | nil) |
---|
88 | |
---|
89 | (deftest ceiling.13 |
---|
90 | (let* ((radix (float-radix 1.0s0)) |
---|
91 | (rad (float radix 1.0s0)) |
---|
92 | (rrad (/ 1.0s0 rad))) |
---|
93 | (loop for i from 1 to 1000 |
---|
94 | for x = (- i rrad) |
---|
95 | for (q r) = (multiple-value-list (ceiling x)) |
---|
96 | unless (and (eql q i) |
---|
97 | (eql r (- rrad 1))) |
---|
98 | collect (list i x q r))) |
---|
99 | nil) |
---|
100 | |
---|
101 | (deftest ceiling.14 |
---|
102 | (let* ((radix (float-radix 1.0f0)) |
---|
103 | (rad (float radix 1.0f0)) |
---|
104 | (rrad (/ 1.0f0 rad))) |
---|
105 | (loop for i from 1 to 1000 |
---|
106 | for x = (+ i rrad) |
---|
107 | for (q r) = (multiple-value-list (ceiling x)) |
---|
108 | unless (and (eql q (1+ i)) |
---|
109 | (eql r (- rrad 1))) |
---|
110 | collect (list i x q r))) |
---|
111 | nil) |
---|
112 | |
---|
113 | (deftest ceiling.15 |
---|
114 | (let* ((radix (float-radix 1.0f0)) |
---|
115 | (rad (float radix 1.0f0)) |
---|
116 | (rrad (/ 1.0f0 rad))) |
---|
117 | (loop for i from 1 to 1000 |
---|
118 | for x = (- i rrad) |
---|
119 | for (q r) = (multiple-value-list (ceiling x)) |
---|
120 | unless (and (eql q i) |
---|
121 | (eql r (- rrad 1))) |
---|
122 | collect (list i x q r))) |
---|
123 | nil) |
---|
124 | |
---|
125 | (deftest ceiling.16 |
---|
126 | (let* ((radix (float-radix 1.0d0)) |
---|
127 | (rad (float radix 1.0d0)) |
---|
128 | (rrad (/ 1.0d0 rad))) |
---|
129 | (loop for i from 1 to 1000 |
---|
130 | for x = (+ i rrad) |
---|
131 | for (q r) = (multiple-value-list (ceiling x)) |
---|
132 | unless (and (eql q (1+ i)) |
---|
133 | (eql r (- rrad 1))) |
---|
134 | collect (list i x q r))) |
---|
135 | nil) |
---|
136 | |
---|
137 | (deftest ceiling.17 |
---|
138 | (let* ((radix (float-radix 1.0d0)) |
---|
139 | (rad (float radix 1.0d0)) |
---|
140 | (rrad (/ 1.0d0 rad))) |
---|
141 | (loop for i from 1 to 1000 |
---|
142 | for x = (- i rrad) |
---|
143 | for (q r) = (multiple-value-list (ceiling x)) |
---|
144 | unless (and (eql q i) |
---|
145 | (eql r (- rrad 1))) |
---|
146 | collect (list i x q r))) |
---|
147 | nil) |
---|
148 | |
---|
149 | (deftest ceiling.18 |
---|
150 | (let* ((radix (float-radix 1.0l0)) |
---|
151 | (rad (float radix 1.0l0)) |
---|
152 | (rrad (/ 1.0l0 rad))) |
---|
153 | (loop for i from 1 to 1000 |
---|
154 | for x = (+ i rrad) |
---|
155 | for (q r) = (multiple-value-list (ceiling x)) |
---|
156 | unless (and (eql q (1+ i)) |
---|
157 | (eql r (- rrad 1))) |
---|
158 | collect (list i x q r))) |
---|
159 | nil) |
---|
160 | |
---|
161 | (deftest ceiling.19 |
---|
162 | (let* ((radix (float-radix 1.0l0)) |
---|
163 | (rad (float radix 1.0l0)) |
---|
164 | (rrad (/ 1.0l0 rad))) |
---|
165 | (loop for i from 1 to 1000 |
---|
166 | for x = (- i rrad) |
---|
167 | for (q r) = (multiple-value-list (ceiling x)) |
---|
168 | unless (and (eql q i) |
---|
169 | (eql r (- rrad 1))) |
---|
170 | collect (list i x q r))) |
---|
171 | nil) |
---|
172 | |
---|
173 | ;;; To add: tests that involve adding/subtracting EPSILON constants |
---|
174 | ;;; (suitably scaled) to floated integers. |
---|
175 | |
---|
176 | |
---|