Add a few tests to contrib/10.roundtrip

This commit is contained in:
Doug Currie 2016-01-10 10:06:09 -05:00
parent 30f220316c
commit db36d7040f
2 changed files with 53 additions and 0 deletions

View File

@ -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

View File

@ -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)