BurntSushi / BurntSushi/quickcheck

Rng Size for Vec Arbitrary cannot be 0

Open
#306 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
2.8k
Forks
165
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.