From db36d7040fd09e79a2338c4b31811e64e09cab1f Mon Sep 17 00:00:00 2001 From: Doug Currie Date: Sun, 10 Jan 2016 10:06:09 -0500 Subject: [PATCH] Add a few tests to contrib/10.roundtrip --- contrib/10.roundtrip/nitro.mk | 5 +++ contrib/10.roundtrip/t/roundtrip.scm | 48 ++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 contrib/10.roundtrip/t/roundtrip.scm diff --git a/contrib/10.roundtrip/nitro.mk b/contrib/10.roundtrip/nitro.mk index e28f3ffb..8238a1ff 100644 --- a/contrib/10.roundtrip/nitro.mk +++ b/contrib/10.roundtrip/nitro.mk @@ -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 diff --git a/contrib/10.roundtrip/t/roundtrip.scm b/contrib/10.roundtrip/t/roundtrip.scm new file mode 100644 index 00000000..ecbde357 --- /dev/null +++ b/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)