BurntSushi / quickcheck

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

Convenience function for generation of recursive structures #286

Open neithernut opened 3 years ago

neithernut commented 3 years ago

When generating recursive structures, users will often use the size of the generator to bound the recursion depth. Dividing the size by the number of sub-structures appears to be a common practice. However, modifying the size of the generator passed to an implementation of Arbitrary::arbitrary would also affect the generation of sister structures if not restored after the generation of child nodes. Instead, users may choose to create a new generator instance with the target size.

The new function makes use of seed from the original generator rather than entropy. In addition to bounding recursive structures, this also allows to re-create those structures based on some initial seed.

This PR is based on #278 (in order to make use of from_seed).