BurntSushi / quickcheck

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

Using a Gen besides StdGen<ThreadRng> #189

Closed CrockAgile closed 6 years ago

CrockAgile commented 6 years ago

StdGen can use any implementer of Rng, such as StdGen<IsaacRng>, StdGen<OsRng>, StdGen<XorShiftRng>, etc. However the main QuickCheck type for configuring and running tests only implements new() for StdGen<ThreadRng>. Is this an oversight in its generics? Or is there a way to configure and run tests using these other randomness sources?

Ryan1729 commented 6 years ago

You can use the gen method after calling new to use another StdGen implementation. But that still involves creating a ThreadRng instance which, over a sufficiently large number of test runs, may not be desirable. I think having another initialization method (new_with_gen?) that allowed passing in another StdGen implementation seems like a good idea. In particular using seeded RNGs seems like it could have a wide array of uses.

BurntSushi commented 6 years ago

@Ryan1729 is right, use the gen method if you want to use a different generator.

I don't understand what a hypothetical new_with_gen would buy you that the existing gen mutator doesn't.

Ryan1729 commented 6 years ago

I just had a look at the ThreadRng docs which say that the rng is lazily-initialized. In that case, then I agree a new_with_gen method wouldn't buy anyone very much.

BurntSushi commented 6 years ago

All righty, closing this. If anyone has any other thoughts please feel free to comment and we can revisit.