-
Notifications
You must be signed in to change notification settings - Fork 587
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
Ensure boundary cases are drawn by strategies #1847
Comments
Hi @cxong - we've thought about this one a fair bit, actually! Unfortunately the naive approach does indeed break lots of important invariants. It's possible to implement a version which works; but then you have a serious problem in how to tune the heuristic - integers are often used in ways where it doesn't make sense to just generate the endpoints more often. See #1754 for example, where we actually reduced the occurrence of large numbers! We'd also need to think about frequency in relation to the So I don't think we're up for changing this at the moment, but it's fantastic to see you're interested in this level of detail! Maybe I'll see you at PyCon AU in Sydney this year? |
Note that calling Hypothesis already has some internal heuristics that should make it pretty good at generating 0, or the boundary closest to 0. Consistently generating the opposite boundary is more difficult, unfortunately. |
The range strategies, e.g.
BoundedIntStrategy
, seem to draw examples throughout the range. E.g.The above example typically won't contain
0
or1000
, but defects tend to occur at the boundaries so a more useful strategy would try to always include the min and max values.I could work around this by using explicit
example
but this cannot be used withdata
. I could also use a hack likest.draw(st.integers().map(lambda x: max(0, min(1000, x)))
which will end up testing with the min/max values a lot. Is there a better way? Otherwise the strategy should minimise developer effort, and just try out boundary values all the time.Here's a naive implementation; I'm not familiar with hypothesis design so not sure if this will break some other things:
The text was updated successfully, but these errors were encountered: