• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: How do I create a Strategy that generates a value in a given range in proptest?

Resolved: How do I create a Strategy that generates a value in a given range in proptest?

0
By Isaac Tonny on 15/03/2023 Issue
Share
Facebook Twitter LinkedIn

In this post, we will see how to resolve How do I create a Strategy that generates a value in a given range in proptest?

Question:

I want to create a Strategy that generates u32 values less than 1000000 efficiently and uniformly. The only two ways that I know to do this are to use any::<u32>() and then do one of the following:
  • use prop_filter to filter out values greater than or equal to 1000000
  • use prop_map to convert the values greater than or equal to 1000000 to values less than 1000000 using the modulus operator (i.e. .prop_map(|x|x % 1000000)). However, this would not provide a uniform sample, and it seems a bit clunky.

Is there any better way to do this, perhaps by using proptest::prelude::Rng::gen_range() somehow?

Best Answer:

Just use a Range, as their tutorial states:

0..100i32 is a strategy to generate i32s between 0, inclusive, and 100, exclusive


so the strategy for numbers up to 1_000_000 is 0u32..1_000_000

If you have better answer, please add a comment about this, thank you!

Source: Stackoverflow.com

property-based-testing proptest rust
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: PyCharm cannot see my newly compiled .pyc see on import

27/03/2023

Resolved: I am facing ERR_HTTP2_PROTOCOL_ERROR on my website

27/03/2023

Resolved: TypeScript does not recognize properties when instantiating interface array

27/03/2023

Comments are closed.

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.