1

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.

Leponzo
  • 624
  • 1
  • 8
  • 20

1 Answers1

1

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));
}
Leponzo
  • 624
  • 1
  • 8
  • 20