st.floats() with bounds do not shrink correctly #1704
Labels
bug
something is clearly wrong here
legibility
make errors helpful and Hypothesis grokable
test-case-reduction
about efficiently finding smaller failing examples
The
floats()
strategy has a well-defined shrinking order: the fractional part is simplified away, then it shrinks towards zero as forintegers()
. While this is the case for unbounded floats, floats with bounds usually do not follow this shrinking order:hypothesis/hypothesis-python/src/hypothesis/searchstrategy/numbers.py
Lines 185 to 188 in 7d1cf43
Instead, they shrink by simplifying the fraction of the allowed interval, with the lower bound as the minimal value. This technique is also lossy for large ranges, as it can generate at most 2^52 distinct values. The way that floats with one bound shrink as an offset to that bound is a relatively minor problem.
To fix this in the general case we will probably have to use the "shrink open" trick explained here and demonstrated here (from #1621), to split generation from shrinking.
The text was updated successfully, but these errors were encountered: