BurntSushi / quickcheck

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

Expand the ranges of arbitrary integers. #221

Closed romanb closed 5 years ago

romanb commented 5 years ago

This is supposed to address both #119 and #190 by interpreting the generator's size parameter as a bias towards the induced range, instead of as a hard limit. Specifically:

In accordance with intuition, lowering the size parameter increases the probability of smaller numbers and increasing the size parameter increases the probability of larger numbers being generated.

The distribution could be further refined but I was trying to keep it simple while solving the main problem of sampling from the entire range such that the influence of the generator's size is easily described and understood. Here are some sample distributions with size=100 (the default size).

Further comments:

  1. Because I expanded the tests a little and also wanted to cover i128 / u128, I bumped the dependencies on rand and rand_core to 0.6 and 0.3, respectively, requiring a few minor modifications.

  2. Because the latest version of the transitive dependency lazy_static has a lower bound for rustc >= 1.24.1 I bumped the lower bound for quickcheck accordingly. If you are willing to go up to 1.26, the feature gate for i128 could be removed, as it stabilised in that release. Would that be desirable?

  3. The assert!s serve only to state the established invariants and could be removed or turned into comments, if desired.

BurntSushi commented 5 years ago

@romanb Would you might rebasing this? I took care of the rand/rand_core upgrade and the MSRV tweak in separate commits.

romanb commented 5 years ago

@BurntSushi Done. Since the MSRV is now 1.30, I could also remove the conditional compilation for the i128 feature as part of this PR, if desired. Nevermind, you did that already!