-
Notifications
You must be signed in to change notification settings - Fork 17
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
Support Request - Generating values within a range #12
Comments
There's a section in the original SmallCheck paper covering these situations. The general method is to define a custom generator for a new "type" representing the search space based off a bijection with an existing type. In this case you want to generate integers within a finite range. We could imagine it as an algebraic data type with a large number of zero arity constructors. The generator would just iterate from one end of the range to the other. For large ranges and few tests, though, it will give just about the worst possible coverage. I think a good option is to treat the range as a large list and index into it with the signed integral generator (0 returns the low boundary, -1 returns the high) modulo the size of the range. That way you test the edge cases early but quickly spread out across the range. |
Hello John, I tried elements of your suggestion, but I didn't understand the -1 returns high end of the range. Here's what I have:
Can you recommend any improvements? |
The non-uniformity is inherent to the SmallCheck approach. SmallCheck uses a depth parameter (which is named |
Good Morning John,
I'm using autocheck, with great success, and I now want to generate values within a range.
I am testing some date functions and I want to generate years between [1970, 2015] inclusively. I tried the ac::fix() combinator, but that just sets an upper limit on the generated value.
I see how I can use discard_if() to throw away values that don't match, but that feels so wasteful. Additionally, I want to generate days, months and years so I'd throw away a lot of data before I generated a valid tuple of values.
How would you recommend generating a range, and if it doesn't exist in autocheck today, what guidance could you provide to how I should add this feature?
Thank you for your time.
Sincerely,
Jeremy Wright
The text was updated successfully, but these errors were encountered: