quickcheck
quickcheck copied to clipboard
api: add Gen::set_size and Gen::from_seed
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
@BurntSushi
Some questions:
- I called the new constructor
Gen::from_seed
. Is that okay? Or maybeGen::from_seed_u64
? - You regret the current constructor
Gen::new
because it takes a size parameter. Should I add aDefault
implementation forGen
with random seed and default size? - Are you sure that you want a
Gen::set_size
?Arbitrary::arbitrary
takes a&mut Gen
and this function makes it very easy to change not only the own local size, but also the size of theArbitrary::arbitrary
caller. Maybe we should provide aGen::with_size
that returns a copy.
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
}
}
What's the status of this PR? It would be super useful to have a seedable Gen
.
^ I am also interested in this.