Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

st.floats() with bounds do not shrink correctly #1704

Closed
Zac-HD opened this issue Dec 18, 2018 · 2 comments
Closed

st.floats() with bounds do not shrink correctly #1704

Zac-HD opened this issue Dec 18, 2018 · 2 comments
Labels
bug something is clearly wrong here legibility make errors helpful and Hypothesis grokable test-case-reduction about efficiently finding smaller failing examples

Comments

@Zac-HD
Copy link
Member

Zac-HD commented Dec 18, 2018

The floats() strategy has a well-defined shrinking order: the fractional part is simplified away, then it shrinks towards zero as for integers(). While this is the case for unbounded floats, floats with bounds usually do not follow this shrinking order:

def do_draw(self, data):
f = self.lower_bound + (
self.upper_bound - self.lower_bound
) * d.fractional_float(data)

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.

@Zac-HD Zac-HD added the test-case-reduction about efficiently finding smaller failing examples label Dec 18, 2018
@Zac-HD
Copy link
Member Author

Zac-HD commented Dec 28, 2018

I was imagining [...] a single wrapper strategy called say FloatShrinkingStrategy which wraps some underlying strategy and filter function (or set of float specific constraints) and automatically produces a float strategy that shrinks correctly. This would then commonize shrinking logic between all three float strategies, and potentially would allow us to (later) improve the generation of floats to boot.

@DRMacIver, in #1644 (comment)

@Zac-HD Zac-HD changed the title st.floats() with two bounds do not shrink correctly st.floats() with bounds do not shrink correctly Dec 28, 2018
@Zac-HD Zac-HD added bug something is clearly wrong here legibility make errors helpful and Hypothesis grokable labels Nov 6, 2019
@Zac-HD Zac-HD self-assigned this Nov 6, 2019
@Zac-HD Zac-HD removed their assignment Jan 7, 2020
@Zac-HD
Copy link
Member Author

Zac-HD commented Mar 15, 2021

Closing in favor of 2907.

@Zac-HD Zac-HD closed this as completed Mar 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something is clearly wrong here legibility make errors helpful and Hypothesis grokable test-case-reduction about efficiently finding smaller failing examples
Projects
None yet
Development

No branches or pull requests

1 participant