1 | ;-*- Mode: Lisp -*- |
---|
2 | ;;;; Author: Paul Dietz |
---|
3 | ;;;; Created: Wed Aug 20 05:13:26 2003 |
---|
4 | ;;;; Contains: Tests of TRUNCATE |
---|
5 | |
---|
6 | (in-package :cl-test) |
---|
7 | |
---|
8 | (compile-and-load "numbers-aux.lsp") |
---|
9 | (compile-and-load "truncate-aux.lsp") |
---|
10 | |
---|
11 | (deftest truncate.error.1 |
---|
12 | (signals-error (truncate) program-error) |
---|
13 | t) |
---|
14 | |
---|
15 | (deftest truncate.error.2 |
---|
16 | (signals-error (truncate 1.0 1 nil) program-error) |
---|
17 | t) |
---|
18 | |
---|
19 | ;;; |
---|
20 | |
---|
21 | (deftest truncate.1 |
---|
22 | (truncate.1-fn) |
---|
23 | nil) |
---|
24 | |
---|
25 | (deftest truncate.2 |
---|
26 | (truncate.2-fn) |
---|
27 | nil) |
---|
28 | |
---|
29 | (deftest truncate.3 |
---|
30 | (truncate.3-fn 2.0s4) |
---|
31 | nil) |
---|
32 | |
---|
33 | (deftest truncate.4 |
---|
34 | (truncate.3-fn 2.0f4) |
---|
35 | nil) |
---|
36 | |
---|
37 | (deftest truncate.5 |
---|
38 | (truncate.3-fn 2.0d4) |
---|
39 | nil) |
---|
40 | |
---|
41 | (deftest truncate.6 |
---|
42 | (truncate.3-fn 2.0l4) |
---|
43 | nil) |
---|
44 | |
---|
45 | (deftest truncate.7 |
---|
46 | (truncate.7-fn) |
---|
47 | nil) |
---|
48 | |
---|
49 | (deftest truncate.8 |
---|
50 | (truncate.8-fn) |
---|
51 | nil) |
---|
52 | |
---|
53 | (deftest truncate.9 |
---|
54 | (truncate.9-fn) |
---|
55 | nil) |
---|
56 | |
---|
57 | (deftest truncate.10 |
---|
58 | (loop for x in (remove-if #'zerop *reals*) |
---|
59 | for (q r) = (multiple-value-list (truncate 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 truncate.11 |
---|
68 | (loop for x in (remove-if #'zerop *reals*) |
---|
69 | for (q r) = (multiple-value-list (truncate (- 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 truncate.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 (truncate x)) |
---|
84 | unless (and (eql q i) |
---|
85 | (eql r rrad)) |
---|
86 | collect (list i x q r))) |
---|
87 | nil) |
---|
88 | |
---|
89 | (deftest truncate.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 (truncate x)) |
---|
96 | unless (and (eql q (1- i)) |
---|
97 | (eql r rrad)) |
---|
98 | collect (list i x q r))) |
---|
99 | nil) |
---|
100 | |
---|
101 | (deftest truncate.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 (truncate x)) |
---|
108 | unless (and (eql q i) |
---|
109 | (eql r rrad)) |
---|
110 | collect (list i x q r))) |
---|
111 | nil) |
---|
112 | |
---|
113 | (deftest truncate.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 (truncate x)) |
---|
120 | unless (and (eql q (1- i)) |
---|
121 | (eql r rrad)) |
---|
122 | collect (list i x q r))) |
---|
123 | nil) |
---|
124 | |
---|
125 | (deftest truncate.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 (truncate x)) |
---|
132 | unless (and (eql q i) |
---|
133 | (eql r rrad)) |
---|
134 | collect (list i x q r))) |
---|
135 | nil) |
---|
136 | |
---|
137 | (deftest truncate.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 (truncate x)) |
---|
144 | unless (and (eql q (1- i)) |
---|
145 | (eql r rrad)) |
---|
146 | collect (list i x q r))) |
---|
147 | nil) |
---|
148 | |
---|
149 | (deftest truncate.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 (truncate x)) |
---|
156 | unless (and (eql q i) |
---|
157 | (eql r rrad)) |
---|
158 | collect (list i x q r))) |
---|
159 | nil) |
---|
160 | |
---|
161 | (deftest truncate.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 (truncate x)) |
---|
168 | unless (and (eql q (1- i)) |
---|
169 | (eql r rrad)) |
---|
170 | collect (list i x q r))) |
---|
171 | nil) |
---|