Skip to content

Rng Size for Vec Arbitrary cannot be 0 #306

@nipunn1313

Description

@nipunn1313

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions