Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rng Size for Vec Arbitrary cannot be 0 #306

Open
nipunn1313 opened this issue Feb 24, 2022 · 0 comments
Open

Rng Size for Vec Arbitrary cannot be 0 #306

nipunn1313 opened this issue Feb 24, 2022 · 0 comments

Comments

@nipunn1313
Copy link

See here
https://docs.rs/quickcheck/1.0.3/src/quickcheck/arbitrary.rs.html#255

If it is set to 0, we get

thread 'tests::quickcheck_test' panicked at 'cannot sample empty range', /Users/nipunn/.cargo/registry/src/github.com-1ecc6299db9ec823/rand-0.8.5/src/rng.rs:134:9

I think it would logically make more sense to change this line to

g.gen_range(0..s+1)

Here, a size of 0 would represent a distribution that creates an empty Vec 100% of the time rather than panicking. Currently size=1 represents this, which I find confusing.

This can be helpful for custom Arbitrary implementations that intentionally reduce the size parameter in a way to ensure a bounded depth for recursive structures.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant