0

According to the jqwik documentation here: https://jqwik.net/docs/current/user-guide.html#integer-constraints it states the integer constraint annotations as:

@Positive: Numbers larger than 0. For all integral types.

@Negative: Numbers lower than 0. For all integral types.

etc.

Are there any convenience annotations for auto generating something like @NegativeOrZero / @PositiveOrZero?

I'm currently using the following code:

    @Provide
    Arbitrary<Integer> negativeOrZero() {
        return Arbitraries.integers().between(Integer.MIN_VALUE, 0);
    }

The shorthand annotations would definitely come in handy if available by default.

vab2048
  • 1,065
  • 8
  • 21

1 Answers1

3

You're right, jqwik does not come with those annotations by default. You have a couple of options, though:

  1. Use @IntRange(min = 0)

  2. Create your more or less trivial custom annotation:

    @Target({ElementType.PARAMETER, ElementType.TYPE_USE})
    @Retention(RetentionPolicy.RUNTIME)
    @IntRange(min = 0) 
    @interface PositiveOrZero {}
    
  3. Open a feature request on https://github.com/jlink/jqwik/issues if you think it would be a worthwhile out-of-the-box feature.

johanneslink
  • 4,877
  • 1
  • 20
  • 37
  • if I were to make a pull request adding these annotations to jqwik are you likely to accept them? I think the situation is common enough that it warrants being in the standard lib.. – vab2048 Jan 06 '21 at 14:03
  • If they come with tests and doc, sure. – johanneslink Jan 06 '21 at 16:34