BurntSushi / quickcheck

Automated property based testing for Rust (with shrinking).
The Unlicense
2.4k stars 149 forks source link

Make SignedShrinker bounded for <$ty>::MIN #296

Open neithernut opened 3 years ago

neithernut commented 3 years ago

Previously, the SignedShrinker was guaranteed to yield a result if initialized with <$ty>::MIN (e.g. i32::MIN for shrinking i32 and f32). This would result in endless shrinking if a test would happen to fail for these values.

Shrinking signed values is done by halfing a second value i and subtracting it from the original x. Thus i will be equal to 0 at some point. We choose to halt the iteration in this state, i.e. not yield any new values. Yielding x - 0 would be pointless anyway, since that obviously equals the original value which was the initial witness for the test failure.


Closes #295, #301.

neithernut commented 3 years ago

Maybe it makes sense to introduce shrinking tests which assert that the shrinkers included in this crate yield at most $number values?