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