-
Notifications
You must be signed in to change notification settings - Fork 21
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
Maybe improve shrinking algorithm? #15
Comments
@waterlink Great ideas here. Thanks for taking the time to explain in pseudo code. 👍 for your binary search approach to shrinking |
About the Lets assume, we are writing a sorting algorithm of some kind, it is still incomplete and incorrect, but returns some valid array, not necessary ordered. And the next property we want to write is the one, that would check the order: property_of do
# get random array here
end.check do |array|
expect(ordered?(array)).to eq(true)
end Lets assume, that generated array looked like Lets assume, that our incorrect algorithm has returned everything sorted properly, except pair of Current shrinking algorithm will remove only 2 last elements, and shrink Proposed algorithm will try to run property without each element one by one. If removing element Only when all elements, that being removed do not turn property into successful one, are removed, then algorithm will proceed and try to shrink individual elements. In this case it will try to shrink every element that has survived removal. This algorithm (depending on our incorrect sort implementation) can remove everything except key elements that cause problem: |
Shrink guessing order will look like that:
|
Updated last comment with actual values. |
For integer/float values it is possible to do shrinking not by
1
, but using kind of binary search:For arrays, currently last element is removed if it is shrinked to its "zero" value (0, "", etc.). This is not the most useful strategy, since usually properties on arrays verify relationship between different elements. That means that if some relation is failing between only 3 items, potentially all but these 3 items can be safely removed, so the algorithm for this is:
This algorithm works really well, it is very fast and still allows for individual shrinking for each element after it is done.
@abargnesi So what do you think? I could implement these (or one of these) over this weekend.
The text was updated successfully, but these errors were encountered: