BurntSushi / quickcheck

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

api: add Gen::set_size and Gen::from_seed #278

Open jakoschiko opened 3 years ago

jakoschiko commented 3 years ago

The seed still can't be set by QuickCheck users, but the new Gen constructor is useful for other crates that use QuickCheck only for its Arbitrary trait.

Closes #277

jakoschiko commented 3 years ago

@BurntSushi

Some questions:

audunska commented 3 years ago

Just my thoughts here, but Gen::with_size seems reasonable here. Maybe even one that takes a closure? I.e., to generate arbitrary vec's with a size parameter of 10: gen.with_size(10, Vec::arbitrary)

It would be implemented something like

impl Gen {
  pub fn with_size<T>(&mut self, size: usize, f: impl FnOnce(&mut Gen) -> T) -> T {
    let old_size = self.size;
    self.size = size;
    let res = f(self);
    self.size = old_size;
    res
  }
}
aakoshh commented 1 year ago

What's the status of this PR? It would be super useful to have a seedable Gen.

JarredAllen commented 1 year ago

^ I am also interested in this.