elm-explorations / test

Write unit and fuzz tests for Elm code.
https://package.elm-lang.org/packages/elm-explorations/test/latest
BSD 3-Clause "New" or "Revised" License
236 stars 40 forks source link

Shrink floats towards human readable #168

Closed gampleman closed 2 years ago

gampleman commented 3 years ago

Right now shrinkers for floats shrink towards zero. However, if the test doesn't fail at zero, you are likely to get wonderful values like -9.99999e-7 and 0.000001.

The problem is that floating point arithmetic can also produce small errors. This makes it hard to tell if the comparison is wrong or the algorithm is wrong.

I think it would be nicer to shrink towards integers. For me it is easier to work with -3 and 12 rather than -9.99999e-7 and 0.000001.

Janiczek commented 3 years ago

Random remark: Hypothesis, to do this, has had to do their own bit remapping of the IEEE 754 float format. But that might be more related to their "automatic shrinking" machinery that goes with "smaller bit representation == simpler value" assumption. I have some code doing that in Elm in my WIP PR in this repo.

Perhaps there is an easy-enough way to do this with current elm-explorations/test implementation and a custom shrinker though.

Janiczek commented 2 years ago

This is now implemented on master and will be published in 2.0.0! :tada: I think we can close this issue 🙂