parse-double test does not test out-of range values

Description

The test file `test/clojure/test_clojure/parse.clj` includes this block in `test-parse-double` (lines 57-60):

This has several problems:

  • The function being called is `parse-long`, not `parse-double`

  • Parsing a number larger than the maximum double will return `Double/POSITIVE_INFINITY`, not `nil`

  • Parsing a number smaller than the minimum double will be rounded to the `Double/MIN_VALUE` or `0.0`, whichever is closer.

  • The smallest double is `4.9e-324`. The value being tested is about twice that, so it would parse correctly anyway (it gets rounded to `1.0E-323`)

All of this is hidden because the wrong function was being called, which returns `nil` for invalid input.

Proposal:

  • Test that numbers too large are rounded to Infinity.

  • Test that numbers too small are rounded up to `Double/MIN_VALUE` or down to `0.0`.

  • Test that strings that do not form valid doubles will return `nil` when parsed.

Screened: Alex Miller

Environment

None

Attachments

1

Activity

Show:

Alex MillerFebruary 16, 2022 at 5:24 PM

Added in 1.11.0-rc1

Paula GearonFebruary 5, 2022 at 8:19 PM

The function works just fine. This just addresses the test

Fixed

Details

Assignee

Reporter

Approval

Ok

Patch

Code and Test

Priority

Affects versions

Fix versions

Created February 5, 2022 at 8:12 PM
Updated February 16, 2022 at 5:24 PM
Resolved February 16, 2022 at 5:24 PM