BurntSushi / quickcheck

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

Improve readme on Gen combination and composition #159

Closed jockbert closed 4 years ago

jockbert commented 7 years ago

Basically, I'm new to both QuickCheck and Rust. In ScalaCheck, I'm used to do generator combination and generator composition with ease. It might be trivial to do the same in Rust and QuickCheck, but I just don't know how. I think some examples in the QuickCheck Readme would help both me and QuickCheck.

Generator Composition How do I create a generator of time from a generator of hours and a generator seconds? How do I create a generator of cars from a generator of wheels and a Generator of engines?

Generator Combination How do I combine a generator of squares and a generator of circles to get a generator of shapes?

Another example of combination, let say that the StdGen is insufficient for type f64. I want to combine a Generator (A) that gives values in the range [MIN, MAX] with another generator (B) that choose from the set of specific values _{INFINITY, NAN, NEGATIVEINFINITY, ZERO}. I might also want to specify the distribution, so that 90% of values should come from generator A and the last 10% of values from generator B. How do I do that?

BurntSushi commented 4 years ago

I'd probably look at the existing impls of Arbitrary for inspiration on this, since there is a lot of reuse. Otherwise, I kind of feel like this is more in the domain of rand?