Open edrdo opened 6 years ago
You can use org.quicktheories.generators.Generate.intArrays.
This accepts two Gen of Integer to supply the sizes and contents for the arrays.
This hasn't been incorporated into the DSL, not entirely sure if that was due to oversight or by design.
Thanks, I didn't pay attention to the existence of intArrays
(sorry for posting here, but I didn't find a user group link if one exists). As you say, the following works fine:
qt()
.forAll(intArrays(integers().between(1,16), integers().all()))
.check( arr -> someProp(arr) );
A minor suggestion I make is to have a more "regular" API for handling primitive type arrays in future releases, e.g. there is no equivalent shortArrays
for short[]
, longArrays
for long[]
, etc. And for byte[]
the API defines byteArrays
method but no bytes()
method / DSL, but instead the bytes(int,int,int)
method.
Best, Eduardo
Hi,
What is the most suitable way of generating primitive-type arrays, say
int[]
values (notInteger[]
) ? For instance the following will not work for obvious reasons (Integer[]
is not type-compatible withint[]
)I guess a
PrimitiveArraysDSL
should make sense as a future development (I would love to contribute it, but don't have sufficient familiarity with QuickTheories yet, I started using it this week!).As a first step towards a work-around I tried to do the following:
As you can see above the array length (
16
) is fixed. How can I "plug-in" in elegant form the equivalent to thewithLengthBetween(1,16))
constraint in the first fragment ?Thanks, Eduardo