format-f.lsp 18.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sun Aug  1 07:14:17 2004
;;;; Contains: Tests of the ~f format directive

(in-package :cl-test)

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

;;; Equivalent to PRIN1 for 0 or (abs x) in range [10^-3,10^7).

(deftest format.f.1
pfdietz's avatar
pfdietz committed
13
  (let ((*print-readably* nil)
sds's avatar
sds committed
14
        (fn (formatter "~F")))
pfdietz's avatar
pfdietz committed
15 16
    (loop
     for type in '(short-float single-float double-float long-float
sds's avatar
sds committed
17
                   short-float single-float double-float long-float)
pfdietz's avatar
pfdietz committed
18
     for x in '(0.0s0 0.0f0 0.0d0 0.0l0
sds's avatar
sds committed
19
                      -0.0s0 -0.0f0 -0.0d0 -0.0l0)
20 21
     for s1 = (let ((*read-default-float-format* type)) (format nil "~f" x))
     for s2 = (let ((*read-default-float-format* type)) (prin1-to-string x))
pfdietz's avatar
pfdietz committed
22
     for s3 = (let ((*read-default-float-format* type))
sds's avatar
sds committed
23
                (formatter-call-to-string fn x))
pfdietz's avatar
pfdietz committed
24 25
     unless (and (string= s1 s2) (string= s1 s3))
     collect (list x type s1 s2 s3)))
26 27 28
  nil)

(deftest format.f.2
pfdietz's avatar
pfdietz committed
29
  (let ((*print-readably* nil)
sds's avatar
sds committed
30
        (fn (formatter "~f")))
31
    (loop
32 33 34
     for i = (random 4)
     for type = (elt #(short-float single-float double-float long-float) i)
     for x = (expt (coerce 10 type)
sds's avatar
sds committed
35
                   (- (random 10.0s0) 3))
36
     for s1 = (let ((*read-default-float-format* type)) (format nil "~f" x))
37
     for s2 = (let ((*read-default-float-format* type)) (prin1-to-string x))
pfdietz's avatar
pfdietz committed
38
     for s3 = (let ((*read-default-float-format* type))
sds's avatar
sds committed
39
                (formatter-call-to-string fn x))
40 41
     repeat 1000
     when (and (<= 1/1000 x)
sds's avatar
sds committed
42 43 44
               (< x 10000000)
               (or (not (string= s1 s2))
                   (not (string= s1 s3))))
pfdietz's avatar
pfdietz committed
45
     collect (list x s1 s2 s3)))
46 47 48
  nil)

(deftest format.f.3
pfdietz's avatar
pfdietz committed
49
  (let ((*print-readably* nil)
sds's avatar
sds committed
50
        (fn (formatter "~F")))
51
    (loop
52 53 54
     for i = (random 4)
     for type = (elt #(short-float single-float double-float long-float) i)
     for x = (- (expt (coerce 10 type)
sds's avatar
sds committed
55
                      (- (random 10.0s0) 3)))
56
     for s1 = (let ((*read-default-float-format* type)) (format nil "~f" x))
57
     for s2 = (let ((*read-default-float-format* type)) (prin1-to-string x))
pfdietz's avatar
pfdietz committed
58
     for s3 = (let ((*read-default-float-format* type))
sds's avatar
sds committed
59
                (formatter-call-to-string fn x))
60 61
     repeat 1000
     when (and (>= -1/1000 x)
sds's avatar
sds committed
62 63
               (> x -10000000)
               (not (and (string= s1 s2) (string= s1 s3))))
pfdietz's avatar
pfdietz committed
64
     collect (list x s1 s2 s3)))
65 66 67
  nil)

(deftest format.f.4
pfdietz's avatar
pfdietz committed
68 69
  (let ((fn (formatter "~3f")))
    (loop for x in (remove-duplicates '(1 1.0s0 1.0f0 1.0d0 1.0l0))
sds's avatar
sds committed
70 71 72 73
          for s = (format nil "~3f" x)
          for s2 = (formatter-call-to-string fn x)
          unless (and (string= s "1.0") (string= s s2))
          collect (list x s s2)))
74 75 76
  nil)

(deftest format.f.5
pfdietz's avatar
pfdietz committed
77 78
  (let ((fn (formatter "~2f")))
    (loop for x in (remove-duplicates '(1 1.0s0 1.0f0 1.0d0 1.0l0))
sds's avatar
sds committed
79 80 81 82
          for s = (format nil "~2f" x)
          for s2 = (formatter-call-to-string fn x)
          unless (and (string= s "1.") (string= s s2))
          collect (list x s s2)))
83 84 85
  nil)

(deftest format.f.6
pfdietz's avatar
pfdietz committed
86 87
  (let ((fn (formatter "~4F")))
    (loop for x in (remove-duplicates '(1 1.0s0 1.0f0 1.0d0 1.0l0))
sds's avatar
sds committed
88 89 90 91
          for s = (format nil "~4F" x)
          for s2 = (formatter-call-to-string fn x)
          unless (and (string= s " 1.0") (string= s s2))
          collect (list x s s2)))
92 93 94
  nil)

(deftest format.f.7
pfdietz's avatar
pfdietz committed
95 96
  (let ((fn (formatter "~4@F")))
    (loop for x in (remove-duplicates '(1 1.0s0 1.0f0 1.0d0 1.0l0))
sds's avatar
sds committed
97 98 99 100
          for s = (format nil "~4@f" x)
          for s2 = (formatter-call-to-string fn x)
          unless (and (string= s "+1.0") (string= s s2))
          collect (list x s s2)))
101 102 103
  nil)

(deftest format.f.8
pfdietz's avatar
pfdietz committed
104 105
  (let ((fn (formatter "~3@F")))
    (loop for x in (remove-duplicates '(1 1.0s0 1.0f0 1.0d0 1.0l0))
sds's avatar
sds committed
106 107 108 109
          for s = (format nil "~3@F" x)
          for s2 = (formatter-call-to-string fn x)
          unless (and (string= s "+1.") (string= s s2))
          collect (list x s s2)))
110 111 112
  nil)

(deftest format.f.9
pfdietz's avatar
pfdietz committed
113 114
  (let ((fn (formatter "~4f")))
    (loop for x in (remove-duplicates '(1 1.0s0 1.0f0 1.0d0 1.0l0))
sds's avatar
sds committed
115 116 117 118
          for s = (format nil "~4f" (- x))
          for s2 = (formatter-call-to-string fn (- x))
          unless (and (string= s "-1.0") (string= s s2))
          collect (list (- x) s s2)))
119 120 121
  nil)

(deftest format.f.10
pfdietz's avatar
pfdietz committed
122 123
  (let ((fn (formatter "~3F")))
    (loop for x in (remove-duplicates '(1/2 0.5s0 0.5f0 0.5d0 0.5l0))
sds's avatar
sds committed
124 125 126 127
          for s = (format nil "~3f" x)
          for s2 = (formatter-call-to-string fn x)
          unless (and (string= s "0.5") (string= s s2))
          collect (list x s s2)))
128 129 130
  nil)

(deftest format.f.11
pfdietz's avatar
pfdietz committed
131 132
  (let ((fn (formatter "~4f")))
    (loop for x in (remove-duplicates '(1/2 0.5s0 0.5f0 0.5d0 0.5l0))
sds's avatar
sds committed
133 134 135 136
          for s = (format nil "~4f" x)
          for s2 = (formatter-call-to-string fn x)
          unless (and (string= s " 0.5") (string= s s2))
          collect (list x s s2)))
137 138 139
  nil)

(deftest format.f.12
pfdietz's avatar
pfdietz committed
140 141
  (let ((fn (formatter "~4,2F")))
    (loop for x in (remove-duplicates '(1/2 0.5s0 0.5f0 0.5d0 0.5l0))
sds's avatar
sds committed
142 143 144 145
          for s = (format nil "~4,2f" x)
          for s2 = (formatter-call-to-string fn x)
          unless (and (string= s "0.50") (string= s s2))
          collect (list x s s2)))
146 147 148
  nil)

(deftest format.f.13
pfdietz's avatar
pfdietz committed
149 150
  (let ((fn (formatter "~3,2F")))
    (loop for x in (remove-duplicates '(1/2 0.5s0 0.5f0 0.5d0 0.5l0))
sds's avatar
sds committed
151 152 153 154
          for s = (format nil "~3,2f" x)
          for s2 = (formatter-call-to-string fn x)
          unless (and (string= s ".50") (string= s s2))
          collect (list x s s2)))
155 156 157
  nil)

(deftest format.f.14
pfdietz's avatar
pfdietz committed
158 159
  (let ((fn (formatter "~2,1F")))
    (loop for x in (remove-duplicates '(1/2 0.5s0 0.5f0 0.5d0 0.5l0))
sds's avatar
sds committed
160 161 162 163
          for s = (format nil "~2,1f" x)
          for s2 = (formatter-call-to-string fn x)
          unless (and (string= s ".5") (string= s s2))
          collect (list x s s2)))
164 165 166
  nil)

(deftest format.f.15
pfdietz's avatar
pfdietz committed
167 168
  (let ((fn (formatter "~4,2@F")))
    (loop for x in (remove-duplicates '(1/2 0.5s0 0.5f0 0.5d0 0.5l0))
sds's avatar
sds committed
169 170 171 172
          for s = (format nil "~4,2@f" x)
          for s2 = (formatter-call-to-string fn x)
          unless (and (string= s "+.50") (string= s s2))
          collect (list x s s2)))
173 174 175
  nil)

(deftest format.f.16
pfdietz's avatar
pfdietz committed
176 177
  (let ((fn (formatter "~2,2F")))
    (loop for x in (remove-duplicates '(1/2 0.5s0 0.5f0 0.5d0 0.5l0))
sds's avatar
sds committed
178 179 180 181
          for s = (format nil "~2,2f" x)
          for s2 = (formatter-call-to-string fn x)
          unless (and (string= s ".50") (string= s s2))
          collect (list x s s2)))
182 183 184
  nil)

(deftest format.f.17
pfdietz's avatar
pfdietz committed
185 186
  (let ((fn (formatter "~,2F")))
    (loop for x in (remove-duplicates '(1/2 0.5s0 0.5f0 0.5d0 0.5l0))
sds's avatar
sds committed
187 188 189 190
          for s = (format nil "~,2f" x)
          for s2 = (formatter-call-to-string fn x)
          unless (and (string= s "0.50") (string= s s2))
          collect (list x s s2)))
191 192 193
  nil)

(deftest format.f.18
pfdietz's avatar
pfdietz committed
194 195
  (let ((fn (formatter "~,2F")))
    (loop for xn in (remove-duplicates '(1/2 0.5s0 0.5f0 0.5d0 0.5l0))
sds's avatar
sds committed
196 197 198 199 200
          for x = (- xn)
          for s = (format nil "~,2f" x)
          for s2 = (formatter-call-to-string fn x)
          unless (and (string= s "-0.50") (string= s s2))
          collect (list x s s2)))
201 202 203
  nil)

(deftest format.f.19
pfdietz's avatar
pfdietz committed
204 205
  (let ((fn (formatter "~4,2,-1F")))
    (loop for x in (remove-duplicates '(5 5.0s0 5.0f0 5.0d0 5.0l0))
sds's avatar
sds committed
206 207 208 209
          for s = (format nil "~4,2,-1f" x)
          for s2 = (formatter-call-to-string fn x)
          unless (and (string= s "0.50") (string= s s2))
          collect (list x s s2)))
210 211 212
  nil)

(deftest format.f.20
pfdietz's avatar
pfdietz committed
213 214
  (let ((fn (formatter "~4,2,0F")))
    (loop for x in (remove-duplicates '(1/2 0.5s0 0.5f0 0.5d0 0.5l0))
sds's avatar
sds committed
215 216 217 218
          for s = (format nil "~4,2,0f" x)
          for s2 = (formatter-call-to-string fn x)
          unless (and (string= s "0.50") (string= s s2))
          collect (list x s s2)))
219 220 221
  nil)

(deftest format.f.21
pfdietz's avatar
pfdietz committed
222 223
  (let ((fn (formatter "~4,2,1f")))
    (loop for x in (remove-duplicates '(1/20 0.05s0 0.05f0 0.05d0 0.05l0))
sds's avatar
sds committed
224 225 226 227
          for s = (format nil "~4,2,1f" x)
          for s2 = (formatter-call-to-string fn x)
          unless (and (string= s "0.50") (string= s s2))
          collect (list x s s2)))
228 229 230 231 232
  nil)

;;; overflow

(deftest format.f.22
pfdietz's avatar
pfdietz committed
233 234
  (let ((fn (formatter "~5,1,,'*F")))
    (loop for x in (remove-duplicates
sds's avatar
sds committed
235 236 237 238 239
                    '(1000 1000.0s0 1000.0f0 1000.0d0 1000.0l0))
          for s = (format nil "~5,1,,'*f" x)
          for s2 = (formatter-call-to-string fn x)
          unless (and (string= s "*****") (string= s s2))
          collect (list x s s2)))
240 241 242
  nil)

(deftest format.f.23
pfdietz's avatar
pfdietz committed
243 244
  (let ((fn (formatter "~5,1,,'*f")))
    (loop for x in (remove-duplicates
sds's avatar
sds committed
245 246 247 248 249
                    '(100 100.0s0 100.0f0 100.0d0 100.0l0))
          for s = (format nil "~5,1,,'*f" x)
          for s2 = (formatter-call-to-string fn x)
          unless (and (string= s "100.0") (string= s s2))
          collect (list x s s2)))
250 251 252
  nil)

(deftest format.f.24
pfdietz's avatar
pfdietz committed
253 254
  (let ((fn (formatter "~4,0,,'*F")))
    (loop for x in (remove-duplicates
sds's avatar
sds committed
255 256 257 258 259
                    '(100 100.0s0 100.0f0 100.0d0 100.0l0))
          for s = (format nil "~4,0,,'*f" x)
          for s2 = (formatter-call-to-string fn x)
          unless (and (string= s "100.") (string= s s2))
          collect (list x s s2)))
260 261 262
  nil)

(deftest format.f.25
pfdietz's avatar
pfdietz committed
263 264
  (let ((fn (formatter "~1,1,,f")))
    (loop for x in (remove-duplicates
sds's avatar
sds committed
265 266 267 268 269
                    '(100 100.0s0 100.0f0 100.0d0 100.0l0))
          for s = (format nil "~1,1,,f" x)
          for s2 = (formatter-call-to-string fn x)
          unless (and (string= s "100.0") (string= s s2))
          collect (list x s s2)))
270 271 272 273 274
  nil)

;;; padchar

(deftest format.f.26
pfdietz's avatar
pfdietz committed
275 276
  (let ((fn (formatter "~10,1,,f")))
    (loop for x in (remove-duplicates
sds's avatar
sds committed
277 278 279 280 281
                    '(100 100.0s0 100.0f0 100.0d0 100.0l0))
          for s = (format nil "~10,1,,f" x)
          for s2 = (formatter-call-to-string fn x)
          unless (and (string= s "     100.0") (string= s s2))
          collect (list x s s2)))
282 283 284
  nil)

(deftest format.f.27
pfdietz's avatar
pfdietz committed
285 286
  (let ((fn (formatter "~10,1,,,'*F")))
    (loop for x in (remove-duplicates
sds's avatar
sds committed
287 288 289 290 291
                    '(100 100.0s0 100.0f0 100.0d0 100.0l0))
          for s = (format nil "~10,1,,,'*f" x)
          for s2 = (formatter-call-to-string fn x)
          unless (and (string= s "*****100.0") (string= s s2))
          collect (list x s s2)))
292 293 294 295 296
  nil)

;;; v parameters

(deftest format.f.28
pfdietz's avatar
pfdietz committed
297 298
  (let ((fn (formatter "~VF")))
    (loop for x = (random 100.0)
sds's avatar
sds committed
299 300 301 302 303 304
          for s1 = (format nil "~f" x)
          for s2 = (format nil "~vf" nil x)
          for s3 = (formatter-call-to-string fn nil x)
          repeat 100
          unless (and (string= s1 s2) (string= s2 s3))
          collect (list x s1 s2 s3)))
305 306 307
  nil)

(deftest format.f.29
pfdietz's avatar
pfdietz committed
308 309
  (let ((fn (formatter "~,vf")))
    (loop for x = (random 100.0)
sds's avatar
sds committed
310 311 312 313 314 315
          for s1 = (format nil "~f" x)
          for s2 = (format nil "~,vf" nil x)
          for s3 = (formatter-call-to-string fn nil x)
          repeat 100
          unless (and (string= s1 s2) (string= s2 s3))
          collect (list x s1 s2 s3)))
316 317 318
  nil)

(deftest format.f.30
pfdietz's avatar
pfdietz committed
319 320
  (let ((fn (formatter "~,,Vf")))
    (loop for x = (random 100.0)
sds's avatar
sds committed
321 322 323 324 325 326
          for s1 = (format nil "~f" x)
          for s2 = (format nil "~,,vf" nil x)
          for s3 = (formatter-call-to-string fn nil x)
          repeat 100
          unless (and (string= s1 s2) (string= s2 s3))
          collect (list x s1 s2 s3)))
327 328 329
  nil)

(deftest format.f.31
pfdietz's avatar
pfdietz committed
330 331
  (let ((fn (formatter "~,,,vF")))
    (loop for x = (random 100.0)
sds's avatar
sds committed
332 333 334 335 336 337
          for s1 = (format nil "~f" x)
          for s2 = (format nil "~,,,vf" nil x)
          for s3 = (formatter-call-to-string fn nil x)
          repeat 100
          unless (and (string= s1 s2) (string= s2 s3))
          collect (list x s1 s2 s3)))
338 339 340
  nil)

(deftest format.f.32
pfdietz's avatar
pfdietz committed
341 342
  (let ((fn (formatter "~,,,,VF")))
    (loop for x = (random 100.0)
sds's avatar
sds committed
343 344 345 346 347 348
          for s1 = (format nil "~f" x)
          for s2 = (format nil "~,,,,vf" nil x)
          for s3 = (formatter-call-to-string fn nil x)
          repeat 100
          unless (and (string= s1 s2) (string= s2 s3))
          collect (list x s1 s2 s3)))
349 350 351 352 353 354 355
  nil)

;;; Randomized tests

#|
(deftest format.f.33
  (let ((bound (if (> 10000000 most-positive-short-float)
sds's avatar
sds committed
356 357
                   most-positive-short-float
                 (coerce 10000000 'short-float))))
358
    (loop for d = (random 10)
sds's avatar
sds committed
359 360 361 362 363 364 365 366 367 368 369 370 371
          for w = (+ 1 d (random 10))
          for x = (random bound)
          for xr = (rational x)
          for s = (format nil "~v,vf" w d x)
          for sr = (decode-fixed-decimal-string s)
          for eps = (expt 1/10 d)
          for abs-xr-sr = (abs (- xr sr))
          for abs-xr-sr-hi = (abs (- xr (+ sr eps)))
          for abs-xr-sr-lo = (abs (- xr (- sr eps)))
          repeat 100
          unless (and (<= abs-xr-sr abs-xr-sr-hi)
                      (<= abs-xr-sr abs-xr-sr-lo))
          collect (list d w x xr s sr eps abs-xr-sr abs-xr-sr-hi abs-xr-sr-lo)))
372 373 374 375 376 377 378
  nil)
|#

(deftest format.f.34
  (with-standard-io-syntax
   (let ((*read-default-float-format* 'short-float))
     (loop for i from (- 1 (ash 1 13)) below (ash 1 13)
sds's avatar
sds committed
379 380 381 382 383
           for sf = (coerce i 'short-float)
           for s = (format nil "~f" sf)
           for i2 = (floor (read-from-string s))
           unless (or (zerop i) (eql i i2))
           collect (list i sf s i2))))
384 385 386 387 388 389
  nil)

(deftest format.f.35
  (with-standard-io-syntax
   (let ((*read-default-float-format* 'single-float))
     (loop for i = (- (random (1- (ash 1 25))) -1 (ash 1 24))
sds's avatar
sds committed
390 391 392 393 394 395
           for sf = (coerce i 'single-float)
           for s = (format nil "~f" sf)
           for i2 = (floor (read-from-string s))
           repeat 2000
           unless (or (zerop i) (eql i i2))
           collect (list i sf s i2))))
396 397 398 399 400 401
  nil)

(deftest format.f.36
  (with-standard-io-syntax
   (let ((*read-default-float-format* 'double-float))
     (loop for i = (- (random (1- (ash 1 51))) -1 (ash 1 50))
sds's avatar
sds committed
402 403 404 405 406 407
           for sf = (coerce i 'double-float)
           for s = (format nil "~f" sf)
           for i2 = (floor (read-from-string s))
           repeat 2000
           unless (or (zerop i) (eql i i2))
           collect (list i sf s i2))))
408 409 410 411 412 413
  nil)

(deftest format.f.37
  (with-standard-io-syntax
   (let ((*read-default-float-format* 'long-float))
     (loop for i = (- (random (1- (ash 1 51))) -1 (ash 1 50))
sds's avatar
sds committed
414 415 416 417 418 419
           for sf = (coerce i 'long-float)
           for s = (format nil "~f" sf)
           for i2 = (floor (read-from-string s))
           repeat 2000
           unless (or (zerop i) (eql i i2))
           collect (list i sf s i2))))
420 421 422 423 424 425 426 427
  nil)

(deftest format.f.38
  (funcall
   (compile
    nil
    '(lambda ()
       (with-standard-io-syntax
sds's avatar
sds committed
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445
        (let ((*read-default-float-format* 'short-float)
              (total 0)
              (len 0))
          (loop for i from (- 1 (ash 1 13)) below (ash 1 13)
                unless (zerop i)
                nconc
                (loop for sf = (coerce i 'short-float)
                      for w = (random 8)
                      for d = (random 4)
                      for s = (format nil "~v,vf" w d sf)
                      for i2 = (ignore-errors (floor (read-from-string s)))
                      repeat 5
                      ; do (print (list w d s i i2))
                      unless (eql i i2)
                      do (incf total)
                      and collect (list i sf w d s i2))
                when (> total 100) collect "count limit exceeded"
                and do (loop-finish)))))))
446 447 448 449 450 451
  nil)

(deftest format.f.39
  (with-standard-io-syntax
   (let ((*read-default-float-format* 'single-float))
     (loop for i = (- (random (1- (ash 1 25))) -1 (ash 1 24))
sds's avatar
sds committed
452 453 454 455 456 457 458 459
           for sf = (coerce i 'single-float)
           for w = (and (coin) (random 16))
           for d = (random 4)
           for s = (format nil "~v,vf" w d sf)
           for i2 = (floor (read-from-string s))
           repeat 2000
           unless (or (zerop i) (eql i i2))
           collect (list i sf w d s i2))))
460 461 462 463 464 465
  nil)

(deftest format.f.40
  (with-standard-io-syntax
   (let ((*read-default-float-format* 'double-float))
     (loop for i = (- (random (1- (ash 1 51))) -1 (ash 1 50))
sds's avatar
sds committed
466 467 468 469 470 471 472 473
           for sf = (coerce i 'double-float)
           for w = (and (coin) (random 30))
           for d = (random 6)
           for s = (format nil "~v,vf" w d sf)
           for i2 = (floor (read-from-string s))
           repeat 2000
           unless (or (zerop i) (eql i i2))
           collect (list i sf w d s i2))))
474 475 476 477 478 479
  nil)

(deftest format.f.41
  (with-standard-io-syntax
   (let ((*read-default-float-format* 'long-float))
     (loop for i = (- (random (1- (ash 1 51))) -1 (ash 1 50))
sds's avatar
sds committed
480 481 482 483 484 485 486 487
           for sf = (coerce i 'long-float)
           for w = (and (coin) (random 30))
           for d = (random 6)
           for s = (format nil "~v,vf" w d sf)
           for i2 = (floor (read-from-string s))
           repeat 2000
           unless (or (zerop i) (eql i i2))
           collect (list i sf w d s i2))))
488 489 490 491 492 493 494
  nil)

(deftest format.f.42
  (let ((chars +standard-chars+))
    (loop
     for k = (and (coin) (random 6))
     for x = (random (/ (random-from-seq #(#.(coerce (* 32 (1- (ash 1 13))) 'short-float)
sds's avatar
sds committed
495 496 497 498
                                             #.(coerce (* 256 (1- (ash 1 24))) 'single-float)
                                             #.(coerce (* 256 (1- (ash 1 50))) 'double-float)
                                             #.(coerce (* 256 (1- (ash 1 50))) 'long-float)))
                        (if k (expt 10 k) 1)))
499 500 501 502 503
     for w = (and (coin) (random 30))
     for d = (and (coin) (random 10))
     for overflowchar = (and (coin) (random-from-seq chars))
     for padchar = (and (coin) (random-from-seq chars))
     for f1 = (concatenate 'string
sds's avatar
sds committed
504 505 506 507 508 509 510 511 512 513 514
                           "~"
                           (if w (format nil "~d" w) "")
                           ","
                           (if d (format nil "~d" d) "")
                           ","
                           (if k (format nil "~d" k) "")
                           ","
                           (if overflowchar (format nil "'~c" overflowchar) "")
                           ","
                           (if padchar (format nil "'~c" padchar) "")
                           (string (random-from-seq "fF")))
515 516 517 518 519 520 521 522
     for s1 = (format nil f1 x)
     for s2 = (format nil "~v,v,v,v,vf" w d k overflowchar padchar x)
     repeat 2000
     unless (string= s1 s2)
     collect (list x w d k overflowchar padchar f1 s1 s2)))
  nil)

;;; This failed in sbcl 0.8.12.25
523 524 525

(def-format-test format.f.43
  "~,,,,',f" (0.0) "0.0")
526 527 528

(deftest format.f.44
  (loop for i from 0 below (min #x10000 char-code-limit)
sds's avatar
sds committed
529 530 531 532 533 534 535
        for x = 2312.9817
        for c = (code-char i)
        for f1 = (and c (format nil "~~,,,,'~cf" c))
        for s1 = (and c (ignore-errors (format nil f1 x)))
        for s2 = (and c (format nil "~,,,,vf" c x))
        unless (equal s1 s2)
        collect (list i c f1 s1 s2))
536
  nil)