source: trunk/source/tests/ansi-tests/print-integers.lsp @ 8991

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

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

File size: 17.8 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Mon Feb 23 06:26:25 2004
4;;;; Contains: Printing tests for integers
5
6(in-package :cl-test)
7
8(compile-and-load "printer-aux.lsp")
9
10;;; Tests with *print-base*
11
12(def-print-test print.integers.1 1 "1")
13(def-print-test print.integers.2 2 "2")
14(def-print-test print.integers.3 3 "3")
15(def-print-test print.integers.4 4 "4")
16(def-print-test print.integers.5 5 "5")
17(def-print-test print.integers.6 6 "6")
18(def-print-test print.integers.7 7 "7")
19(def-print-test print.integers.8 8 "8")
20(def-print-test print.integers.9 9 "9")
21
22(def-print-test print.integers.10 -0 "0")
23(def-print-test print.integers.11 -1 "-1")
24(def-print-test print.integers.12 -2 "-2")
25(def-print-test print.integers.13 -3 "-3")
26(def-print-test print.integers.14 -4 "-4")
27(def-print-test print.integers.15 -5 "-5")
28(def-print-test print.integers.16 -6 "-6")
29(def-print-test print.integers.17 -7 "-7")
30(def-print-test print.integers.18 -8 "-8")
31(def-print-test print.integers.19 -9 "-9")
32
33(def-print-test print.integers.20 (expt 10 20) "100000000000000000000")
34(def-print-test print.integers.21 (- (expt 10 20)) "-100000000000000000000")
35
36(def-print-test print.integers.base.2.0 0 "0" (*print-base* 2))
37(def-print-test print.integers.base.2.1 1 "1" (*print-base* 2))
38(def-print-test print.integers.base.2.2 2 "10" (*print-base* 2))
39(def-print-test print.integers.base.2.3 3 "11" (*print-base* 2))
40(def-print-test print.integers.base.2.4 -1 "-1" (*print-base* 2))
41(def-print-test print.integers.base.2.5 -2 "-10" (*print-base* 2))
42(def-print-test print.integers.base.2.6 -3 "-11" (*print-base* 2))
43(def-print-test print.integers.base.2.7 255 "11111111" (*print-base* 2))
44(def-print-test print.integers.base.2.8 -252 "-11111100" (*print-base* 2))
45(def-print-test print.integers.base.2.9 (expt 2 40)
46  "10000000000000000000000000000000000000000" (*print-base* 2))
47(def-print-test print.integers.base.2.10 (- (expt 2 40))
48  "-10000000000000000000000000000000000000000" (*print-base* 2))
49
50(def-print-test print.integers.base.3.0 0 "0" (*print-base* 3))
51(def-print-test print.integers.base.3.1 1 "1" (*print-base* 3))
52(def-print-test print.integers.base.3.2 2 "2" (*print-base* 3))
53(def-print-test print.integers.base.3.3 3 "10" (*print-base* 3))
54(def-print-test print.integers.base.3.4 -1 "-1" (*print-base* 3))
55(def-print-test print.integers.base.3.5 -2 "-2" (*print-base* 3))
56(def-print-test print.integers.base.3.6 -3 "-10" (*print-base* 3))
57(def-print-test print.integers.base.3.7 80 "2222" (*print-base* 3))
58(def-print-test print.integers.base.3.8 -78 "-2220" (*print-base* 3))
59(def-print-test print.integers.base.3.9 (expt 3 40)
60  "10000000000000000000000000000000000000000" (*print-base* 3))
61(def-print-test print.integers.base.3.10 (- (expt 3 40))
62  "-10000000000000000000000000000000000000000" (*print-base* 3))
63
64(def-print-test print.integers.base.4.0 0 "0" (*print-base* 4))
65(def-print-test print.integers.base.4.1 1 "1" (*print-base* 4))
66(def-print-test print.integers.base.4.2 2 "2" (*print-base* 4))
67(def-print-test print.integers.base.4.3 3 "3" (*print-base* 4))
68(def-print-test print.integers.base.4.4 4 "10" (*print-base* 4))
69(def-print-test print.integers.base.4.5 5 "11" (*print-base* 4))
70(def-print-test print.integers.base.4.6 -1 "-1" (*print-base* 4))
71(def-print-test print.integers.base.4.7 -2 "-2" (*print-base* 4))
72(def-print-test print.integers.base.4.8 -3 "-3" (*print-base* 4))
73(def-print-test print.integers.base.4.9 -4 "-10" (*print-base* 4))
74(def-print-test print.integers.base.4.10 -5 "-11" (*print-base* 4))
75(def-print-test print.integers.base.4.11 255 "3333" (*print-base* 4))
76(def-print-test print.integers.base.4.12 -255 "-3333" (*print-base* 4))
77(def-print-test print.integers.base.4.13 (expt 4 40)
78  "10000000000000000000000000000000000000000" (*print-base* 4))
79(def-print-test print.integers.base.4.14 (- (expt 4 40))
80  "-10000000000000000000000000000000000000000" (*print-base* 4))
81
82(def-print-test print.integers.base.7.0 0 "0" (*print-base* 7))
83(def-print-test print.integers.base.7.1 1 "1" (*print-base* 7))
84(def-print-test print.integers.base.7.2 2 "2" (*print-base* 7))
85(def-print-test print.integers.base.7.3 16 "22" (*print-base* 7))
86(def-print-test print.integers.base.7.4 66 "123" (*print-base* 7))
87(def-print-test print.integers.base.7.5 -1 "-1" (*print-base* 7))
88(def-print-test print.integers.base.7.6 -7 "-10" (*print-base* 7))
89(def-print-test print.integers.base.7.7 -48 "-66" (*print-base* 7))
90(def-print-test print.integers.base.7.8 (expt 7 40)
91  "10000000000000000000000000000000000000000" (*print-base* 7))
92(def-print-test print.integers.base.7.9 (- (expt 7 40))
93  "-10000000000000000000000000000000000000000" (*print-base* 7))
94
95(def-print-test print.integers.base.11.0 0 "0" (*print-base* 11))
96(def-print-test print.integers.base.11.1 1 "1" (*print-base* 11))
97(def-print-test print.integers.base.11.2 2 "2" (*print-base* 11))
98(def-print-test print.integers.base.11.3 10 "A" (*print-base* 11))
99(def-print-test print.integers.base.11.4 11 "10" (*print-base* 11))
100(def-print-test print.integers.base.11.5 121 "100" (*print-base* 11))
101(def-print-test print.integers.base.11.6 -1 "-1" (*print-base* 11))
102(def-print-test print.integers.base.11.7 -10 "-A" (*print-base* 11))
103(def-print-test print.integers.base.11.8 -21 "-1A" (*print-base* 11))
104(def-print-test print.integers.base.11.9 -110 "-A0" (*print-base* 11))
105(def-print-test print.integers.base.11.10 (expt 11 40)
106  "10000000000000000000000000000000000000000" (*print-base* 11))
107(def-print-test print.integers.base.11.11 (- (expt 11 40))
108  "-10000000000000000000000000000000000000000" (*print-base* 11))
109
110(def-print-test print.integers.base.16.0 0 "0" (*print-base* 16))
111(def-print-test print.integers.base.16.1 1 "1" (*print-base* 16))
112(def-print-test print.integers.base.16.2 2 "2" (*print-base* 16))
113(def-print-test print.integers.base.16.3 12 "C" (*print-base* 16))
114(def-print-test print.integers.base.16.4 17 "11" (*print-base* 16))
115(def-print-test print.integers.base.16.5 256 "100" (*print-base* 16))
116(def-print-test print.integers.base.16.6 -1 "-1" (*print-base* 16))
117(def-print-test print.integers.base.16.7 -14 "-E" (*print-base* 16))
118(def-print-test print.integers.base.16.8 -30 "-1E" (*print-base* 16))
119(def-print-test print.integers.base.16.9 -208 "-D0" (*print-base* 16))
120(def-print-test print.integers.base.16.10 (expt 16 40)
121  "10000000000000000000000000000000000000000" (*print-base* 16))
122(def-print-test print.integers.base.16.11 (- (expt 16 40))
123  "-10000000000000000000000000000000000000000" (*print-base* 16))
124
125(def-print-test print.integers.base.36.0 0 "0" (*print-base* 36))
126(def-print-test print.integers.base.36.1 1 "1" (*print-base* 36))
127(def-print-test print.integers.base.36.2 2 "2" (*print-base* 36))
128(def-print-test print.integers.base.36.3 12 "C" (*print-base* 36))
129(def-print-test print.integers.base.36.4 37 "11" (*print-base* 36))
130(def-print-test print.integers.base.36.5 (* 36 36) "100" (*print-base* 36))
131(def-print-test print.integers.base.36.6 -1 "-1" (*print-base* 36))
132(def-print-test print.integers.base.36.7 -14 "-E" (*print-base* 36))
133(def-print-test print.integers.base.36.8 -35 "-Z" (*print-base* 36))
134(def-print-test print.integers.base.36.9 -37 "-11" (*print-base* 36))
135(def-print-test print.integers.base.36.10 (- 2 (* 36 36)) "-ZY" (*print-base* 36))
136(def-print-test print.integers.base.36.11 (expt 36 40)
137  "10000000000000000000000000000000000000000" (*print-base* 36))
138(def-print-test print.integers.base.36.12 (- (expt 36 40))
139  "-10000000000000000000000000000000000000000" (*print-base* 36))
140
141;;; With *print-radix*
142
143(def-print-test print.integers.radix.0 0 "0." (*print-radix* t))
144(def-print-test print.integers.radix.1 1 "1." (*print-radix* t))
145(def-print-test print.integers.radix.2 123456 "123456." (*print-radix* t))
146(def-print-test print.integers.radix.3 123456789 "123456789." (*print-radix* t))
147(def-print-test print.integers.radix.4 -5 "-5." (*print-radix* t))
148(def-print-test print.integers.radix.5 -249213 "-249213." (*print-radix* t))
149(def-print-test print.integers.radix.6 -917512001 "-917512001." (*print-radix* t))
150
151(def-print-test print.integers.radix.base.2.0 0 "#b0" (*print-radix* t) (*print-base* 2))
152(def-print-test print.integers.radix.base.2.1 1 "#b1" (*print-radix* t) (*print-base* 2))
153(def-print-test print.integers.radix.base.2.2 2 "#b10" (*print-radix* t) (*print-base* 2))
154(def-print-test print.integers.radix.base.2.3 3 "#b11" (*print-radix* t) (*print-base* 2))
155(def-print-test print.integers.radix.base.2.4 -1 "#b-1" (*print-radix* t) (*print-base* 2))
156(def-print-test print.integers.radix.base.2.5 -2 "#b-10" (*print-radix* t) (*print-base* 2))
157(def-print-test print.integers.radix.base.2.6 -3 "#b-11" (*print-radix* t) (*print-base* 2))
158(def-print-test print.integers.radix.base.2.7 256 "#b100000000" (*print-radix* t) (*print-base* 2))
159(def-print-test print.integers.radix.base.2.8 -256 "#b-100000000" (*print-radix* t) (*print-base* 2))
160(def-print-test print.integers.radix.base.2.9 (expt 2 100)
161  (concatenate 'string "#b1" (make-string 100 :initial-element #\0))
162  (*print-radix* t) (*print-base* 2))
163(def-print-test print.integers.radix.base.2.10 (- (expt 2 200))
164  (concatenate 'string "#b-1" (make-string 200 :initial-element #\0))
165  (*print-radix* t) (*print-base* 2))
166
167(def-print-test print.integers.radix.base.3.0 0 "#3r0" (*print-radix* t) (*print-base* 3))
168(def-print-test print.integers.radix.base.3.1 1 "#3r1" (*print-radix* t) (*print-base* 3))
169(def-print-test print.integers.radix.base.3.2 2 "#3r2" (*print-radix* t) (*print-base* 3))
170(def-print-test print.integers.radix.base.3.3 4 "#3r11" (*print-radix* t) (*print-base* 3))
171(def-print-test print.integers.radix.base.3.4 -1 "#3r-1" (*print-radix* t) (*print-base* 3))
172(def-print-test print.integers.radix.base.3.5 -2 "#3r-2" (*print-radix* t) (*print-base* 3))
173(def-print-test print.integers.radix.base.3.6 -4 "#3r-11" (*print-radix* t) (*print-base* 3))
174(def-print-test print.integers.radix.base.3.7 6561 "#3r100000000" (*print-radix* t) (*print-base* 3))
175(def-print-test print.integers.radix.base.3.8 -81 "#3r-10000" (*print-radix* t) (*print-base* 3))
176(def-print-test print.integers.radix.base.3.9 (expt 3 100)
177  (concatenate 'string "#3r1" (make-string 100 :initial-element #\0))
178  (*print-radix* t) (*print-base* 3))
179(def-print-test print.integers.radix.base.3.10 (- 1 (expt 3 200))
180  (concatenate 'string "#3r-" (make-string 200 :initial-element #\2))
181  (*print-radix* t) (*print-base* 3))
182
183(def-print-test print.integers.radix.base.5.0 0 "#5r0" (*print-radix* t) (*print-base* 5))
184(def-print-test print.integers.radix.base.5.1 1 "#5r1" (*print-radix* t) (*print-base* 5))
185(def-print-test print.integers.radix.base.5.2 2 "#5r2" (*print-radix* t) (*print-base* 5))
186(def-print-test print.integers.radix.base.5.3 6 "#5r11" (*print-radix* t) (*print-base* 5))
187(def-print-test print.integers.radix.base.5.4 -1 "#5r-1" (*print-radix* t) (*print-base* 5))
188(def-print-test print.integers.radix.base.5.5 -2 "#5r-2" (*print-radix* t) (*print-base* 5))
189(def-print-test print.integers.radix.base.5.6 -8 "#5r-13" (*print-radix* t) (*print-base* 5))
190(def-print-test print.integers.radix.base.5.7 390625 "#5r100000000" (*print-radix* t) (*print-base* 5))
191(def-print-test print.integers.radix.base.5.8 -625 "#5r-10000" (*print-radix* t) (*print-base* 5))
192(def-print-test print.integers.radix.base.5.9 (expt 5 100)
193  (concatenate 'string "#5r1" (make-string 100 :initial-element #\0))
194  (*print-radix* t) (*print-base* 5))
195(def-print-test print.integers.radix.base.5.10 (- 1 (expt 5 200))
196  (concatenate 'string "#5r-" (make-string 200 :initial-element #\4))
197  (*print-radix* t) (*print-base* 5))
198
199(def-print-test print.integers.radix.base.8.0 0 "#o0" (*print-radix* t) (*print-base* 8))
200(def-print-test print.integers.radix.base.8.1 1 "#o1" (*print-radix* t) (*print-base* 8))
201(def-print-test print.integers.radix.base.8.2 2 "#o2" (*print-radix* t) (*print-base* 8))
202(def-print-test print.integers.radix.base.8.3 9 "#o11" (*print-radix* t) (*print-base* 8))
203(def-print-test print.integers.radix.base.8.4 -1 "#o-1" (*print-radix* t) (*print-base* 8))
204(def-print-test print.integers.radix.base.8.5 -2 "#o-2" (*print-radix* t) (*print-base* 8))
205(def-print-test print.integers.radix.base.8.6 -11 "#o-13" (*print-radix* t) (*print-base* 8))
206(def-print-test print.integers.radix.base.8.7 16777216 "#o100000000" (*print-radix* t) (*print-base* 8))
207(def-print-test print.integers.radix.base.8.8 -4096 "#o-10000" (*print-radix* t) (*print-base* 8))
208(def-print-test print.integers.radix.base.8.9 (expt 8 100)
209  (concatenate 'string "#o1" (make-string 100 :initial-element #\0))
210  (*print-radix* t) (*print-base* 8))
211(def-print-test print.integers.radix.base.8.10 (- 1 (expt 8 200))
212  (concatenate 'string "#o-" (make-string 200 :initial-element #\7))
213  (*print-radix* t) (*print-base* 8))
214
215(def-print-test print.integers.radix.base.12.0 0 "#12r0" (*print-radix* t) (*print-base* 12))
216(def-print-test print.integers.radix.base.12.1 1 "#12r1" (*print-radix* t) (*print-base* 12))
217(def-print-test print.integers.radix.base.12.2 2 "#12r2" (*print-radix* t) (*print-base* 12))
218(def-print-test print.integers.radix.base.12.3 13 "#12r11" (*print-radix* t) (*print-base* 12))
219(def-print-test print.integers.radix.base.12.4 -1 "#12r-1" (*print-radix* t) (*print-base* 12))
220(def-print-test print.integers.radix.base.12.5 -2 "#12r-2" (*print-radix* t) (*print-base* 12))
221(def-print-test print.integers.radix.base.12.6 -15 "#12r-13" (*print-radix* t) (*print-base* 12))
222(def-print-test print.integers.radix.base.12.7 (expt 12 8)
223  "#12r100000000" (*print-radix* t) (*print-base* 12))
224(def-print-test print.integers.radix.base.12.8 (- (* 12 12 12 12))
225  "#12r-10000" (*print-radix* t) (*print-base* 12))
226(def-print-test print.integers.radix.base.12.9 (expt 12 100)
227  (concatenate 'string "#12r1" (make-string 100 :initial-element #\0))
228  (*print-radix* t) (*print-base* 12))
229(def-print-test print.integers.radix.base.12.10 (- 1 (expt 12 200))
230  (concatenate 'string "#12r-" (make-string 200 :initial-element #\B))
231  (*print-radix* t) (*print-base* 12))
232
233(def-print-test print.integers.radix.base.16.0 0 "#x0" (*print-radix* t) (*print-base* 16))
234(def-print-test print.integers.radix.base.16.1 1 "#x1" (*print-radix* t) (*print-base* 16))
235(def-print-test print.integers.radix.base.16.2 2 "#x2" (*print-radix* t) (*print-base* 16))
236(def-print-test print.integers.radix.base.16.3 17 "#x11" (*print-radix* t) (*print-base* 16))
237(def-print-test print.integers.radix.base.16.4 -1 "#x-1" (*print-radix* t) (*print-base* 16))
238(def-print-test print.integers.radix.base.16.5 -2 "#x-2" (*print-radix* t) (*print-base* 16))
239(def-print-test print.integers.radix.base.16.6 -19 "#x-13" (*print-radix* t) (*print-base* 16))
240(def-print-test print.integers.radix.base.16.7 (expt 16 8)
241  "#x100000000" (*print-radix* t) (*print-base* 16))
242(def-print-test print.integers.radix.base.16.8 (- (* 16 16 16 16))
243  "#x-10000" (*print-radix* t) (*print-base* 16))
244(def-print-test print.integers.radix.base.16.9 (expt 16 100)
245  (concatenate 'string "#x1" (make-string 100 :initial-element #\0))
246  (*print-radix* t) (*print-base* 16))
247(def-print-test print.integers.radix.base.16.10 (- 1 (expt 16 200))
248  (concatenate 'string "#x-" (make-string 200 :initial-element #\F))
249  (*print-radix* t) (*print-base* 16))
250
251(def-print-test print.integers.radix.base.36.0 0 "#36r0" (*print-radix* t) (*print-base* 36))
252(def-print-test print.integers.radix.base.36.1 1 "#36r1" (*print-radix* t) (*print-base* 36))
253(def-print-test print.integers.radix.base.36.2 2 "#36r2" (*print-radix* t) (*print-base* 36))
254(def-print-test print.integers.radix.base.36.3 37 "#36r11" (*print-radix* t) (*print-base* 36))
255(def-print-test print.integers.radix.base.36.4 -1 "#36r-1" (*print-radix* t) (*print-base* 36))
256(def-print-test print.integers.radix.base.36.5 -2 "#36r-2" (*print-radix* t) (*print-base* 36))
257(def-print-test print.integers.radix.base.36.6 -39 "#36r-13" (*print-radix* t) (*print-base* 36))
258(def-print-test print.integers.radix.base.36.7 (expt 36 8)
259  "#36r100000000" (*print-radix* t) (*print-base* 36))
260(def-print-test print.integers.radix.base.36.8 (- (* 36 36 36 36))
261  "#36r-10000" (*print-radix* t) (*print-base* 36))
262(def-print-test print.integers.radix.base.36.9 (expt 36 100)
263  (concatenate 'string "#36r1" (make-string 100 :initial-element #\0))
264  (*print-radix* t) (*print-base* 36))
265(def-print-test print.integers.radix.base.36.10 (- 1 (expt 36 200))
266  (concatenate 'string "#36r-" (make-string 200 :initial-element #\Z))
267  (*print-radix* t) (*print-base* 36))
268
269(deftest print.integers.base.various.1
270  (with-standard-io-syntax
271   (loop for b from 2 to 36
272         nconc
273         (let ((*print-base* b) (*read-base* b))
274           (loop for i from 1 to 100
275                 for n = (expt b i)
276                 for str = (with-output-to-string (s) (prin1 n s))
277                 for result = (read-from-string str)
278                 unless (= n result)
279                 collect (list b i n str result)))))
280  nil)
281
282(deftest print.integers.base.various.2
283  (with-standard-io-syntax
284   (loop for b from 2 to 36
285         nconc
286         (let ((*print-base* b) (*read-base* b))
287           (loop for i from 1 to 100
288                 for n = (- (expt b i))
289                 for str = (with-output-to-string (s) (prin1 n s))
290                 for result = (read-from-string str)
291                 unless (= n result)
292                 collect (list b i n str result)))))
293  nil)
294
295(deftest print.integers.base.various.3
296  (with-standard-io-syntax
297   (loop for b from 2 to 36
298         nconc
299         (let ((*print-base* b) (*read-base* b) (*print-radix* t))
300           (loop for i from 1 to 100
301                 for n = (expt b i)
302                 for str = (with-output-to-string (s) (prin1 n s))
303                 for result = (read-from-string str)
304                 unless (= n result)
305                 collect (list b i n str result)))))
306  nil)
307
308(deftest print.integers.base.various.4
309  (with-standard-io-syntax
310   (loop for b from 2 to 36
311         nconc
312         (let ((*print-base* b) (*read-base* b) (*print-radix* t))
313           (loop for i from 1 to 100
314                 for n = (- (expt b i))
315                 for str = (with-output-to-string (s) (prin1 n s))
316                 for result = (read-from-string str)
317                 unless (= n result)
318                 collect (list b i n str result)))))
319  nil)       
320
321(deftest print.integers.random.1
322  (loop for numbits = (random 40)
323        for bound = (ash 1 numbits)
324        for r = (- (random (+ bound bound)) bound)
325        repeat 10000
326        nconc (randomly-check-readability r))
327  nil)
Note: See TracBrowser for help on using the repository browser.