How to specify @ForAll non-zero integers?

119 Views Asked by At

How can I specify @ForAll non-zero integers (i.e. either include both positive and negative integers, or exclude 0 from the integer range)? I couldn't find anything from https://jqwik.net/docs/current/user-guide.html#integer-constraints.

1

There are 1 best solutions below

0
On BEST ANSWER

After I scrolled through the User Guide a bit more, I got @ForAll("nonZeroIntegers") int i with the following to work (but I'm open to better solutions):

@Provide
Arbitrary<Integer> nonZeroIntegers() {
    return Arbitraries.oneOf(Arbitraries.integers().greaterOrEqual(1),
                             Arbitraries.integers().lessOrEqual(-1));
}