Open russel opened 8 years ago
As you say, filtering using suchThat
is potentially expensive and should only be used when you don't have to discard too many test cases.
For integers, you can use the inRange
generator: https://github.com/emil-e/rapidcheck/blob/master/doc/generators_ref.md#gent-inranget-min-t-max
For strings with a subset of Unicode codepoints, there is support for that if we're only talking byte sized characters by using gen::container
with std::string
and some generator that only generates the characters you want. However, support for Unicode generation is currently lacking but is on my to do list as soon as I can actually find the time.
OK, that sounds good. I'll investigate further. (I just thought I'd ask to try and avoid reading the code :-)
I am probably being to hasty/rushed, but the documentation on generators tells how to create them, but seemingly not how to use them in an rc:check. I guess I just need pointing at the right place…
You can read about it here: https://github.com/emil-e/rapidcheck/blob/master/doc/generators.md
The user guide has links to pretty much everything: https://github.com/emil-e/rapidcheck/blob/master/doc/user_guide.md
Indeed, but, and I may just be missing it, I see no examples of usage of generators in an rc::check so it is difficult to know what is idiomatic use of the generators.
Sorry about the late reply, vacation and stuff. Maybe this was unclear but to explicitly use a generator, "dereference" it using operator*
.
Data generation of ints seems to work fine. However filtering in the check lambda is a fairly bad idea since it reduces, potentially, drastically the number of cases. Furthermore it is not clear how many real cases and how many rejected cases there were. Although ranges are possibly in C++17 (or maybe later), having the ability to create a range [0, 900] is very, very useful.
Also for strings it can be very important to create strings using only a subset of the Unicode codepoint set, is this possible?