Convenience function for generation of recursive structures#286
Open
neithernut wants to merge 3 commits intoBurntSushi:masterfrom
Open
Convenience function for generation of recursive structures#286neithernut wants to merge 3 commits intoBurntSushi:masterfrom
neithernut wants to merge 3 commits intoBurntSushi:masterfrom
Conversation
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 BurntSushi#277
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 can create a new generator instance with the target size. Historically, this would be the only option since public API for setting the size of an existing generator was only introduced recently. This change introduces a convenience function for creating such a generator. 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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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::arbitrarywould 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).