Search code examples
javajqwik

jqwik - How are values for tests selected?


In the first example on the jkwik site, there is a generator that potentially generates a large number of values for "divisible by 3":

@Property
boolean every_third_element_starts_with_Fizz(@ForAll("divisibleBy3") int i) {
    return fizzBuzz().get(i - 1).startsWith("Fizz");
}

@Provide
Arbitrary<Integer> divisibleBy3() {
    return Arbitraries.integers().between(1, 100).filter(i -> i % 3 == 0);
}

Will jqwik run the property test for all possible values, or does it select values from this list? If it's the secon case, how does it select?


Solution

  • In this case jqwik will generate all possible values because there are only 100 candidates to consider and 100 is smaller than the default number of generated values, which is 1000. Since there is also filtering taking place, only the 33 numbers below 100 that are divisible by 3 are being generated.

    In cases where a value's possible range cannot be fully covered, values are chosen

    1. from a set of typical edge cases like minimum (1) and maximum (100)
    2. (pseudo-)randomly from the set of all values. The random distribution of numbers is distorted to give lower numbers a higher chance of being chosen.