From d376f78ffdb19e8130b2522bf24188581adf4ad9 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Fri, 30 Nov 2018 01:03:30 +0000 Subject: [PATCH] Test exceptions in sqrt too. --- tests/runtime/test-arith.scm | 43 +++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/tests/runtime/test-arith.scm b/tests/runtime/test-arith.scm index 0903e396e..c0a263799 100644 --- a/tests/runtime/test-arith.scm +++ b/tests/runtime/test-arith.scm @@ -81,6 +81,12 @@ USA. (flo:with-trapped-exceptions 0 f) (f))) +(define (yes-traps f) + (if (flo:have-trap-enable/disable?) + ;; XXX Should enable all traps. + (flo:with-trapped-exceptions (flo:exception:invalid-operation) f) + (f))) + (define (define-enumerated-test prefix cases procedure) (for-each (lambda (arguments) (define-test (symbol prefix '/ arguments) @@ -682,18 +688,43 @@ USA. (-inf.0 +inf.0i) (+inf.0 +inf.0) (-inf.0+1.i +inf.0i ,expect-failure) - (+inf.0+1.i +inf.0 ,expect-failure) + (+inf.0+1.i +inf.0 ,expect-error) (-inf.0-1.i +inf.0i ,expect-failure) - (+inf.0-1.i +inf.0 ,expect-failure) + (+inf.0-1.i +inf.0 ,expect-error) (-inf.0i -inf.0+inf.0i ,expect-failure) (+inf.0i +inf.0+inf.0i) (1.-inf.0i -inf.0+inf.0i ,expect-failure) (1.+inf.0i +inf.0+inf.0i) (-1.-inf.0i -inf.0+inf.0i ,expect-failure) - (-1.+inf.0i +inf.0+inf.0i) - ;; NaN should be preserved. - (,(flo:qnan 1234) ,(flo:qnan 1234))) + (-1.+inf.0i +inf.0+inf.0i)) (lambda (z r #!optional xfail) (with-expected-failure xfail (lambda () - (assert-eqv-nan (no-traps (lambda () (sqrt z))) r))))) \ No newline at end of file + (assert-eqv (yes-traps (lambda () (sqrt z))) r))))) + +(define-test 'sqrt-qnan + (lambda () + (let ((x (identity-procedure (flo:qnan 1234)))) + (assert-eqv-nan (yes-traps (lambda () (sqrt x))) x) + (assert-eqv + (flo:preserving-environment + (lambda () + (flo:clear-exceptions! (flo:supported-exceptions)) + (sqrt x) + (flo:test-exceptions (flo:supported-exceptions)))) + 0)))) + +(define-test 'sqrt-snan + (lambda () + (let ((x (identity-procedure (flo:snan 4321)))) + (assert-eqv-nan (no-traps (lambda () (sqrt x))) (flo:qnan 4321)) + (assert-error (lambda () (yes-traps (lambda () (sqrt x))))) + (assert-eqv + (flo:preserving-environment + (lambda () + (flo:clear-exceptions! (flo:supported-exceptions)) + (no-traps + (lambda () + (sqrt x) + (flo:test-exceptions (flo:supported-exceptions)))))) + (flo:exception:invalid-operation))))) \ No newline at end of file -- 2.25.1