mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-07-07 05:06:37 +02:00
Patch for better error reporting in numeric tests from Per Bothner.
This commit is contained in:
parent
75cf2d7331
commit
c381c2cf41
1 changed files with 124 additions and 134 deletions
|
@ -1758,152 +1758,142 @@
|
||||||
(test expect (values z))
|
(test expect (values z))
|
||||||
(test #t (and (member z-str '(str strs ...)) #t))))))
|
(test #t (and (member z-str '(str strs ...)) #t))))))
|
||||||
|
|
||||||
(define-syntax test-numeric-syntaxes
|
|
||||||
(syntax-rules ()
|
|
||||||
((test-numeric-syntaxes (x ...))
|
|
||||||
(test-numeric-syntax x ...))
|
|
||||||
((test-numeric-syntaxes (x ...) . rest)
|
|
||||||
(begin (test-numeric-syntax x ...)
|
|
||||||
(test-numeric-syntaxes . rest)))))
|
|
||||||
|
|
||||||
;; Each test is of the form:
|
;; Each test is of the form:
|
||||||
;;
|
;;
|
||||||
;; (input-str expected-value expected-write-values ...)
|
;; (test-numeric-syntax input-str expected-value expected-write-values ...)
|
||||||
;;
|
;;
|
||||||
;; where the input should be eqv? to the expected-value, and the
|
;; where the input should be eqv? to the expected-value, and the
|
||||||
;; written output the same as any of the expected-write-values. The
|
;; written output the same as any of the expected-write-values. The
|
||||||
;; form
|
;; form
|
||||||
;;
|
;;
|
||||||
;; (input-str expected-value)
|
;; (test-numeric-syntax input-str expected-value)
|
||||||
;;
|
;;
|
||||||
;; is a shorthand for
|
;; is a shorthand for
|
||||||
;;
|
;;
|
||||||
;; (input-str expected-value (input-str))
|
;; (test-numeric-syntax input-str expected-value (input-str))
|
||||||
|
|
||||||
(test-numeric-syntaxes
|
;; Simple
|
||||||
;; Simple
|
(test-numeric-syntax "1" 1)
|
||||||
("1" 1)
|
(test-numeric-syntax "+1" 1 "1")
|
||||||
("+1" 1 "1")
|
(test-numeric-syntax "-1" -1)
|
||||||
("-1" -1)
|
(test-numeric-syntax "#i1" 1.0 "1.0" "1.")
|
||||||
("#i1" 1.0 "1.0" "1.")
|
(test-numeric-syntax "#I1" 1.0 "1.0" "1.")
|
||||||
("#I1" 1.0 "1.0" "1.")
|
(test-numeric-syntax "#i-1" -1.0 "-1.0" "-1.")
|
||||||
("#i-1" -1.0 "-1.0" "-1.")
|
;; Decimal
|
||||||
;; Decimal
|
(test-numeric-syntax "1.0" 1.0 "1.0" "1.")
|
||||||
("1.0" 1.0 "1.0" "1.")
|
(test-numeric-syntax "1." 1.0 "1.0" "1.")
|
||||||
("1." 1.0 "1.0" "1.")
|
(test-numeric-syntax ".1" 0.1 "0.1" "100.0e-3")
|
||||||
(".1" 0.1 "0.1" "100.0e-3")
|
(test-numeric-syntax "-.1" -0.1 "-0.1" "-100.0e-3")
|
||||||
("-.1" -0.1 "-0.1" "-100.0e-3")
|
;; Some Schemes don't allow negative zero. This is okay with the standard
|
||||||
;; Some Schemes don't allow negative zero. This is okay with the standard
|
(test-numeric-syntax "-.0" -0.0 "-0." "-0.0" "0.0" "0." ".0")
|
||||||
("-.0" -0.0 "-0." "-0.0" "0.0" "0." ".0")
|
(test-numeric-syntax "-0." -0.0 "-.0" "-0.0" "0.0" "0." ".0")
|
||||||
("-0." -0.0 "-.0" "-0.0" "0.0" "0." ".0")
|
(test-numeric-syntax "#i1.0" 1.0 "1.0" "1.")
|
||||||
("#i1.0" 1.0 "1.0" "1.")
|
(test-numeric-syntax "#e1.0" 1 "1")
|
||||||
("#e1.0" 1 "1")
|
(test-numeric-syntax "#e-.0" 0 "0")
|
||||||
("#e-.0" 0 "0")
|
(test-numeric-syntax "#e-0." 0 "0")
|
||||||
("#e-0." 0 "0")
|
;; Decimal notation with suffix
|
||||||
;; Decimal notation with suffix
|
(test-numeric-syntax "1e2" 100.0 "100.0" "100.")
|
||||||
("1e2" 100.0 "100.0" "100.")
|
(test-numeric-syntax "1E2" 100.0 "100.0" "100.")
|
||||||
("1E2" 100.0 "100.0" "100.")
|
(test-numeric-syntax "1s2" 100.0 "100.0" "100.")
|
||||||
("1s2" 100.0 "100.0" "100.")
|
(test-numeric-syntax "1S2" 100.0 "100.0" "100.")
|
||||||
("1S2" 100.0 "100.0" "100.")
|
(test-numeric-syntax "1f2" 100.0 "100.0" "100.")
|
||||||
("1f2" 100.0 "100.0" "100.")
|
(test-numeric-syntax "1F2" 100.0 "100.0" "100.")
|
||||||
("1F2" 100.0 "100.0" "100.")
|
(test-numeric-syntax "1d2" 100.0 "100.0" "100.")
|
||||||
("1d2" 100.0 "100.0" "100.")
|
(test-numeric-syntax "1D2" 100.0 "100.0" "100.")
|
||||||
("1D2" 100.0 "100.0" "100.")
|
(test-numeric-syntax "1l2" 100.0 "100.0" "100.")
|
||||||
("1l2" 100.0 "100.0" "100.")
|
(test-numeric-syntax "1L2" 100.0 "100.0" "100.")
|
||||||
("1L2" 100.0 "100.0" "100.")
|
;; NaN, Inf
|
||||||
;; NaN, Inf
|
(test-numeric-syntax "+nan.0" +nan.0 "+nan.0" "+NaN.0")
|
||||||
("+nan.0" +nan.0 "+nan.0" "+NaN.0")
|
(test-numeric-syntax "+NAN.0" +nan.0 "+nan.0" "+NaN.0")
|
||||||
("+NAN.0" +nan.0 "+nan.0" "+NaN.0")
|
(test-numeric-syntax "+inf.0" +inf.0 "+inf.0" "+Inf.0")
|
||||||
("+inf.0" +inf.0 "+inf.0" "+Inf.0")
|
(test-numeric-syntax "+InF.0" +inf.0 "+inf.0" "+Inf.0")
|
||||||
("+InF.0" +inf.0 "+inf.0" "+Inf.0")
|
(test-numeric-syntax "-inf.0" -inf.0 "-inf.0" "-Inf.0")
|
||||||
("-inf.0" -inf.0 "-inf.0" "-Inf.0")
|
(test-numeric-syntax "-iNF.0" -inf.0 "-inf.0" "-Inf.0")
|
||||||
("-iNF.0" -inf.0 "-inf.0" "-Inf.0")
|
(test-numeric-syntax "#i+nan.0" +nan.0 "+nan.0" "+NaN.0")
|
||||||
("#i+nan.0" +nan.0 "+nan.0" "+NaN.0")
|
(test-numeric-syntax "#i+inf.0" +inf.0 "+inf.0" "+Inf.0")
|
||||||
("#i+inf.0" +inf.0 "+inf.0" "+Inf.0")
|
(test-numeric-syntax "#i-inf.0" -inf.0 "-inf.0" "-Inf.0")
|
||||||
("#i-inf.0" -inf.0 "-inf.0" "-Inf.0")
|
;; Exact ratios
|
||||||
;; Exact ratios
|
(test-numeric-syntax "1/2" (/ 1 2))
|
||||||
("1/2" (/ 1 2))
|
(test-numeric-syntax "#e1/2" (/ 1 2) "1/2")
|
||||||
("#e1/2" (/ 1 2) "1/2")
|
(test-numeric-syntax "10/2" 5 "5")
|
||||||
("10/2" 5 "5")
|
(test-numeric-syntax "-1/2" (- (/ 1 2)))
|
||||||
("-1/2" (- (/ 1 2)))
|
(test-numeric-syntax "0/10" 0 "0")
|
||||||
("0/10" 0 "0")
|
(test-numeric-syntax "#e0/10" 0 "0")
|
||||||
("#e0/10" 0 "0")
|
(test-numeric-syntax "#i3/2" (/ 3.0 2.0) "1.5")
|
||||||
("#i3/2" (/ 3.0 2.0) "1.5")
|
;; Exact complex
|
||||||
;; Exact complex
|
(test-numeric-syntax "1+2i" (make-rectangular 1 2))
|
||||||
("1+2i" (make-rectangular 1 2))
|
(test-numeric-syntax "1+2I" (make-rectangular 1 2) "1+2i")
|
||||||
("1+2I" (make-rectangular 1 2) "1+2i")
|
(test-numeric-syntax "1-2i" (make-rectangular 1 -2))
|
||||||
("1-2i" (make-rectangular 1 -2))
|
(test-numeric-syntax "-1+2i" (make-rectangular -1 2))
|
||||||
("-1+2i" (make-rectangular -1 2))
|
(test-numeric-syntax "-1-2i" (make-rectangular -1 -2))
|
||||||
("-1-2i" (make-rectangular -1 -2))
|
(test-numeric-syntax "+i" (make-rectangular 0 1) "+i" "+1i" "0+i" "0+1i")
|
||||||
("+i" (make-rectangular 0 1) "+i" "+1i" "0+i" "0+1i")
|
(test-numeric-syntax "0+i" (make-rectangular 0 1) "+i" "+1i" "0+i" "0+1i")
|
||||||
("0+i" (make-rectangular 0 1) "+i" "+1i" "0+i" "0+1i")
|
(test-numeric-syntax "0+1i" (make-rectangular 0 1) "+i" "+1i" "0+i" "0+1i")
|
||||||
("0+1i" (make-rectangular 0 1) "+i" "+1i" "0+i" "0+1i")
|
(test-numeric-syntax "-i" (make-rectangular 0 -1) "-i" "-1i" "0-i" "0-1i")
|
||||||
("-i" (make-rectangular 0 -1) "-i" "-1i" "0-i" "0-1i")
|
(test-numeric-syntax "0-i" (make-rectangular 0 -1) "-i" "-1i" "0-i" "0-1i")
|
||||||
("0-i" (make-rectangular 0 -1) "-i" "-1i" "0-i" "0-1i")
|
(test-numeric-syntax "0-1i" (make-rectangular 0 -1) "-i" "-1i" "0-i" "0-1i")
|
||||||
("0-1i" (make-rectangular 0 -1) "-i" "-1i" "0-i" "0-1i")
|
(test-numeric-syntax "+2i" (make-rectangular 0 2) "2i" "+2i" "0+2i")
|
||||||
("+2i" (make-rectangular 0 2) "2i" "+2i" "0+2i")
|
(test-numeric-syntax "-2i" (make-rectangular 0 -2) "-2i" "0-2i")
|
||||||
("-2i" (make-rectangular 0 -2) "-2i" "0-2i")
|
;; Decimal-notation complex numbers (rectangular notation)
|
||||||
;; Decimal-notation complex numbers (rectangular notation)
|
(test-numeric-syntax "1.0+2i" (make-rectangular 1.0 2) "1.0+2.0i" "1.0+2i" "1.+2i" "1.+2.i")
|
||||||
("1.0+2i" (make-rectangular 1.0 2) "1.0+2.0i" "1.0+2i" "1.+2i" "1.+2.i")
|
(test-numeric-syntax "1+2.0i" (make-rectangular 1 2.0) "1.0+2.0i" "1+2.0i" "1.+2.i" "1+2.i")
|
||||||
("1+2.0i" (make-rectangular 1 2.0) "1.0+2.0i" "1+2.0i" "1.+2.i" "1+2.i")
|
(test-numeric-syntax "1e2+1.0i" (make-rectangular 100.0 1.0) "100.0+1.0i" "100.+1.i")
|
||||||
("1e2+1.0i" (make-rectangular 100.0 1.0) "100.0+1.0i" "100.+1.i")
|
(test-numeric-syntax "1s2+1.0i" (make-rectangular 100.0 1.0) "100.0+1.0i" "100.+1.i")
|
||||||
("1s2+1.0i" (make-rectangular 100.0 1.0) "100.0+1.0i" "100.+1.i")
|
(test-numeric-syntax "1.0+1e2i" (make-rectangular 1.0 100.0) "1.0+100.0i" "1.+100.i")
|
||||||
("1.0+1e2i" (make-rectangular 1.0 100.0) "1.0+100.0i" "1.+100.i")
|
(test-numeric-syntax "1.0+1s2i" (make-rectangular 1.0 100.0) "1.0+100.0i" "1.+100.i")
|
||||||
("1.0+1s2i" (make-rectangular 1.0 100.0) "1.0+100.0i" "1.+100.i")
|
;; Fractional complex numbers (rectangular notation)
|
||||||
;; Fractional complex numbers (rectangular notation)
|
(test-numeric-syntax "1/2+3/4i" (make-rectangular (/ 1 2) (/ 3 4)))
|
||||||
("1/2+3/4i" (make-rectangular (/ 1 2) (/ 3 4)))
|
;; Mixed fractional/decimal notation complex numbers (rectangular notation)
|
||||||
;; Mixed fractional/decimal notation complex numbers (rectangular notation)
|
(test-numeric-syntax "0.5+3/4i" (make-rectangular 0.5 (/ 3 4))
|
||||||
("0.5+3/4i" (make-rectangular 0.5 (/ 3 4))
|
|
||||||
"0.5+0.75i" ".5+.75i" "0.5+3/4i" ".5+3/4i" "500.0e-3+750.0e-3i")
|
"0.5+0.75i" ".5+.75i" "0.5+3/4i" ".5+3/4i" "500.0e-3+750.0e-3i")
|
||||||
;; Complex NaN, Inf (rectangular notation)
|
;; Complex NaN, Inf (rectangular notation)
|
||||||
;; ("+nan.0+nan.0i" (make-rectangular the-nan the-nan) "+NaN.0+NaN.0i")
|
;;(test-numeric-syntax "+nan.0+nan.0i" (make-rectangular the-nan the-nan) "+NaN.0+NaN.0i")
|
||||||
("+inf.0+inf.0i" (make-rectangular +inf.0 +inf.0) "+Inf.0+Inf.0i")
|
(test-numeric-syntax "+inf.0+inf.0i" (make-rectangular +inf.0 +inf.0) "+Inf.0+Inf.0i")
|
||||||
("-inf.0+inf.0i" (make-rectangular -inf.0 +inf.0) "-Inf.0+Inf.0i")
|
(test-numeric-syntax "-inf.0+inf.0i" (make-rectangular -inf.0 +inf.0) "-Inf.0+Inf.0i")
|
||||||
("-inf.0-inf.0i" (make-rectangular -inf.0 -inf.0) "-Inf.0-Inf.0i")
|
(test-numeric-syntax "-inf.0-inf.0i" (make-rectangular -inf.0 -inf.0) "-Inf.0-Inf.0i")
|
||||||
("+inf.0-inf.0i" (make-rectangular +inf.0 -inf.0) "+Inf.0-Inf.0i")
|
(test-numeric-syntax "+inf.0-inf.0i" (make-rectangular +inf.0 -inf.0) "+Inf.0-Inf.0i")
|
||||||
;; Complex numbers (polar notation)
|
;; Complex numbers (polar notation)
|
||||||
;; Need to account for imprecision in write output.
|
;; Need to account for imprecision in write output.
|
||||||
;; ("1@2" -0.416146836547142+0.909297426825682i "-0.416146836547142+0.909297426825682i")
|
;;(test-numeric-syntax "1@2" -0.416146836547142+0.909297426825682i "-0.416146836547142+0.909297426825682i")
|
||||||
;; Base prefixes
|
;; Base prefixes
|
||||||
("#x11" 17 "17")
|
(test-numeric-syntax "#x11" 17 "17")
|
||||||
("#X11" 17 "17")
|
(test-numeric-syntax "#X11" 17 "17")
|
||||||
("#d11" 11 "11")
|
(test-numeric-syntax "#d11" 11 "11")
|
||||||
("#D11" 11 "11")
|
(test-numeric-syntax "#D11" 11 "11")
|
||||||
("#o11" 9 "9")
|
(test-numeric-syntax "#o11" 9 "9")
|
||||||
("#O11" 9 "9")
|
(test-numeric-syntax "#O11" 9 "9")
|
||||||
("#b11" 3 "3")
|
(test-numeric-syntax "#b11" 3 "3")
|
||||||
("#B11" 3 "3")
|
(test-numeric-syntax "#B11" 3 "3")
|
||||||
("#o7" 7 "7")
|
(test-numeric-syntax "#o7" 7 "7")
|
||||||
("#xa" 10 "10")
|
(test-numeric-syntax "#xa" 10 "10")
|
||||||
("#xA" 10 "10")
|
(test-numeric-syntax "#xA" 10 "10")
|
||||||
("#xf" 15 "15")
|
(test-numeric-syntax "#xf" 15 "15")
|
||||||
("#x-10" -16 "-16")
|
(test-numeric-syntax "#x-10" -16 "-16")
|
||||||
("#d-10" -10 "-10")
|
(test-numeric-syntax "#d-10" -10 "-10")
|
||||||
("#o-10" -8 "-8")
|
(test-numeric-syntax "#o-10" -8 "-8")
|
||||||
("#b-10" -2 "-2")
|
(test-numeric-syntax "#b-10" -2 "-2")
|
||||||
;; Combination of prefixes
|
;; Combination of prefixes
|
||||||
("#e#x10" 16 "16")
|
(test-numeric-syntax "#e#x10" 16 "16")
|
||||||
("#i#x10" 16.0 "16.0" "16.")
|
(test-numeric-syntax "#i#x10" 16.0 "16.0" "16.")
|
||||||
;; (Attempted) decimal notation with base prefixes
|
;; (Attempted) decimal notation with base prefixes
|
||||||
("#d1." 1.0 "1.0" "1.")
|
(test-numeric-syntax "#d1." 1.0 "1.0" "1.")
|
||||||
("#d.1" 0.1 "0.1" ".1" "100.0e-3")
|
(test-numeric-syntax "#d.1" 0.1 "0.1" ".1" "100.0e-3")
|
||||||
("#x1e2" 482 "482")
|
(test-numeric-syntax "#x1e2" 482 "482")
|
||||||
("#d1e2" 100.0 "100.0" "100.")
|
(test-numeric-syntax "#d1e2" 100.0 "100.0" "100.")
|
||||||
;; Fractions with prefixes
|
;; Fractions with prefixes
|
||||||
("#x10/2" 8 "8")
|
(test-numeric-syntax "#x10/2" 8 "8")
|
||||||
("#x11/2" (/ 17 2) "17/2")
|
(test-numeric-syntax "#x11/2" (/ 17 2) "17/2")
|
||||||
("#d11/2" (/ 11 2) "11/2")
|
(test-numeric-syntax "#d11/2" (/ 11 2) "11/2")
|
||||||
("#o11/2" (/ 9 2) "9/2")
|
(test-numeric-syntax "#o11/2" (/ 9 2) "9/2")
|
||||||
("#b11/10" (/ 3 2) "3/2")
|
(test-numeric-syntax "#b11/10" (/ 3 2) "3/2")
|
||||||
;; Complex numbers with prefixes
|
;; Complex numbers with prefixes
|
||||||
;;("#x10+11i" (make-rectangular 16 17) "16+17i")
|
;;(test-numeric-syntax "#x10+11i" (make-rectangular 16 17) "16+17i")
|
||||||
("#d1.0+1.0i" (make-rectangular 1.0 1.0) "1.0+1.0i" "1.+1.i")
|
(test-numeric-syntax "#d1.0+1.0i" (make-rectangular 1.0 1.0) "1.0+1.0i" "1.+1.i")
|
||||||
("#d10+11i" (make-rectangular 10 11) "10+11i")
|
(test-numeric-syntax "#d10+11i" (make-rectangular 10 11) "10+11i")
|
||||||
;;("#o10+11i" (make-rectangular 8 9) "8+9i")
|
;;(test-numeric-syntax "#o10+11i" (make-rectangular 8 9) "8+9i")
|
||||||
;;("#b10+11i" (make-rectangular 2 3) "2+3i")
|
;;(test-numeric-syntax "#b10+11i" (make-rectangular 2 3) "2+3i")
|
||||||
;;("#e1.0+1.0i" (make-rectangular 1 1) "1+1i" "1+i")
|
;;(test-numeric-syntax "#e1.0+1.0i" (make-rectangular 1 1) "1+1i" "1+i")
|
||||||
;;("#i1.0+1.0i" (make-rectangular 1.0 1.0) "1.0+1.0i" "1.+1.i")
|
;;(test-numeric-syntax "#i1.0+1.0i" (make-rectangular 1.0 1.0) "1.0+1.0i" "1.+1.i")
|
||||||
)
|
|
||||||
|
|
||||||
(test-end)
|
(test-end)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue