;;;; mathh-test ;;;; Kon Lovett, May '17 ;;;; Issues ;;;; (require-extension test) ;;; (require-extension mathh) (test-begin "mathh") ;; (test-group "ISO C Functions" (test 1.0 (bessel-j0 0.0)) (test 0.0 (bessel-j1 0.0)) (test 1.0 (bessel-jn 0 0.0)) (test 0.0 (bessel-jn 1 0.0)) (test 0.088256964215677 (bessel-y0 1.0)) (test -0.781212821300289 (bessel-y1 1.0)) (test 0.088256964215677 (bessel-yn 0 1.0)) (test -0.781212821300289 (bessel-yn 1 1.0)) (test 1.0 (cosh 0.0)) (test 0.0 (sinh 0.0)) (test 0.0 (tanh 0.0)) (test 5.0 (hypot -5.0 0)) (test 1.0 (tgamma 1.0)) (test 0.0 (lgamma 1.0)) (test 2.0 (log10 100.0)) (test 3.0 (log2 8.0)) (test 0.0 (log1p 0.0)) (test 0.0 (fpmod 0.0 1.0)) (test (values 5.0 0.5) (modf 5.5)) (test 20.0 (ldexp 5.0 2)) (test 20.0 (scalbn 5.0 2)) (test (values 0.536870912 -30) (frexp 5.0e-10)) ) ;; (test-group "BSD Functions" (test-assert (signbit -1.0)) (test-assert (not (signbit 1.0))) (test-assert (signbit -0.0)) (test -1.0 (copysign 1.0 -1.0)) (test 1.0 (copysign -1.0 1.0)) (test 1.0 (nextafter 1.0 -1.0)) (test -1.0 (nextafter -1.0 1.0)) (test 2.4662 (cbrt 15.0)) ) ;; (test-group "Function fpclass" (test 'negative-infinite (fpclass -inf.0)) (test 'signaling-nan (fpclass -nan.0)) (test 'negative-zero (fpclass -0.0)) (test 'positive-normal (fpclass 0.741573033707865)) (test 'positive-normal (fpclass (fp/ 33.0 44.5))) ) ;; (test-group "Function fpclassify" (test 'infinite (fpclassify -inf.0)) (test 'nan (fpclassify -nan.0)) (test 'zero (fpclassify -0.0)) (test 'normal (fpclassify 0.741573033707865)) (test 'normal (fpclassify (fp/ 33.0 44.5))) ) ;;; ;(import (prefix mathh-consts C:)) ;(require-library mathh-consts) ;=> C:sqrt2 C:degree C:ln2 C:log2e C:e (require-extension mathh-consts) (test-group "Math Constants" ; Well, some (test sqrt2 (sqrt 2.0)) (test degree (/ pi 180.0)) (test ln2 (log 2.0)) (test log2e (log2 e)) ) ;;; (test-group "Inline failure #1340" (define (factorial x) (gamma (+ 1 x)) ) (test 362880.0 (factorial 9)) ) ;;; (require-extension fp-utils) (define-constant 5eps (fp/ 9.0 1e06)) (define-constant 4eps (fp/ 9.0 1e05)) (test-group "FP Utils" (test-assert (fpzero? 0.0)) (test-assert (not (fpzero? 1.0))) (test-assert (not (fpzero? maximum-flonum))) (test-assert (not (fpzero? minimum-flonum))) (test-assert (not (fppositive? 0.0))) (test-assert (not (fppositive? (fpneg minimum-flonum)))) (test-assert (fppositive? maximum-flonum)) (test-assert (fpcardinal? 0.0)) (test-assert (not (fpcardinal? (fpneg minimum-flonum)))) (test-assert (fpcardinal? maximum-flonum)) (test-assert (not (fpnegative? 0.0))) (test-assert (fpnegative? (fpneg minimum-flonum))) (test-assert (not (fpnegative? maximum-flonum))) (test-assert (not (fpeven? 7.0))) (test-assert (fpeven? 6.0)) (test-assert (not (fpodd? 6.0))) (test-assert (fpodd? 7.0)) (test-assert (flonum? (fprandom))) (test-assert (flonum? (fprandom 2456))) (test 4.0 (fpadd1 3.0)) (test 2.0 (fpsub1 3.0)) (test 27.0 (fpcub 3.0)) (test 1.0 (fpmodulo 5.0 2.0)) (test 0.0 (fpmodulo 0.0 1.0)) (test 2.0 (fpquotient 5.0 2.0)) (test 1.0 (fpremainder 5.0 2.0)) (test-assert (fp~= 0.123456 0.123457 5eps)) (test-assert (fp~<= 0.123456 0.123457 5eps)) (test-assert (fp~>= 0.123456 0.123457 5eps)) (test-assert (fp~<= 0.123456 0.12346 5eps)) (test-assert (fp~>= 0.123456 0.12344 5eps)) (parameterize ((current-test-epsilon 4eps)) (test 5.6568 (fpdistance 1.0 1.0 5.0 5.0)) ) (receive (mx mn) (fpmax-and-min 1.0 -1.0 -16.0 13.0 2.0 16.0 7.0 -8.0) (test "fpmax-and-min max" 16.0 mx) (test "fpmax-and-min min" -16.0 mn) ) ) ;;; (require-extension fx-utils) (test-group "FX Utils" (test-assert (fxzero? 0)) (test-assert (not (fxzero? 1))) (test-assert (not (fxzero? most-positive-fixnum))) (test-assert (not (fxzero? most-negative-fixnum))) (test-assert (not (fxpositive? 0))) (test-assert (not (fxpositive? most-negative-fixnum))) (test-assert (fxpositive? most-positive-fixnum)) (test-assert (fxcardinal? 0)) (test-assert (not (fxcardinal? most-negative-fixnum))) (test-assert (fxcardinal? most-positive-fixnum)) (test-assert (not (fxnegative? 0))) (test-assert (fxnegative? most-negative-fixnum)) (test-assert (not (fxnegative? most-positive-fixnum))) (test-assert (fixnum? (fxrandom))) (test-assert (fixnum? (fxrandom 2456))) (test 4 (fxadd1 3)) (test 2 (fxsub1 3)) (test 27 (fxcub 3)) (test -1 (fxlog2 0)) (test 0 (fxlog2 1)) (test 1 (fxlog2 2)) (test 1 (fxlog2 3)) (test 2 (fxlog2 4)) (test -1 (fxpow2log2 0)) (test 4 (fxpow2log2 3)) (test 8 (fxpow2log2 7)) (test 16 (fxpow2log2 15)) (test 16 (fxpow2log2 16)) (test 32 (fxpow2log2 17)) (test 16 (fxdistance 1 1 5 5)) (receive (mx mn) (fxmax-and-min 1 -1 -16 13 2 16 7 -8) (test "fxmax-and-min max" 16 mx) (test "fxmax-and-min min" -16 mn) ) ) ;;; (test-end "mathh") ;;; (test-exit)