Add a few tests to contrib/10.roundtrip
This commit is contained in:
parent
30f220316c
commit
db36d7040f
|
@ -2,3 +2,8 @@ CONTRIB_DEFS += -DPIC_CSTRING_TO_DOUBLE=emyg_atod -DPIC_DOUBLE_TO_CSTRING=emyg_d
|
|||
|
||||
CONTRIB_SRCS += contrib/10.roundtrip/emyg_dtoa.c \
|
||||
contrib/10.roundtrip/emyg_atod.c
|
||||
|
||||
CONTRIB_TESTS += test-roundtrip
|
||||
|
||||
test-roundtrip: bin/picrin
|
||||
$(TEST_RUNNER) contrib/10.roundtrip/t/roundtrip.scm
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
(import (scheme base)
|
||||
(srfi 27)
|
||||
(scheme inexact)
|
||||
(picrin test))
|
||||
|
||||
(test-begin)
|
||||
|
||||
(define (rountrip-ok number)
|
||||
(let ((radix 10))
|
||||
(eqv? number (string->number (number->string number radix) radix))))
|
||||
|
||||
(test #t (rountrip-ok -nan.0))
|
||||
|
||||
(test #t (rountrip-ok +nan.0))
|
||||
|
||||
(test #t (rountrip-ok -inf.0))
|
||||
|
||||
(test #t (rountrip-ok +inf.0))
|
||||
|
||||
(test -inf.0 (string->number "-inf.0"))
|
||||
|
||||
(test +inf.0 (string->number "+inf.0"))
|
||||
|
||||
(test #t (nan? (string->number "-nan.0")))
|
||||
|
||||
(test #t (nan? (string->number "+nan.0")))
|
||||
|
||||
(define (random-roundtrip)
|
||||
(let ((r (random-real)))
|
||||
(if (rountrip-ok r)
|
||||
#t
|
||||
r)))
|
||||
|
||||
(test #t (random-roundtrip))
|
||||
(test #t (random-roundtrip))
|
||||
(test #t (random-roundtrip))
|
||||
(test #t (random-roundtrip))
|
||||
(test #t (random-roundtrip))
|
||||
(test #t (random-roundtrip))
|
||||
(test #t (random-roundtrip))
|
||||
(test #t (random-roundtrip))
|
||||
(test #t (random-roundtrip))
|
||||
(test #t (random-roundtrip))
|
||||
(test #t (random-roundtrip))
|
||||
(test #t (random-roundtrip))
|
||||
(test #t (random-roundtrip))
|
||||
|
||||
(test-end)
|
Loading…
Reference in New Issue