-
-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Arbitraries and generators are fundamental concepts; so is transforming them into other arbitraries.
Jqwik 1 already has a well-working API for that, so I suggest keeping the API similar where appropriate
and making it simpler where possible.
Arbitrary and Generator
Let's start with the two fundamental interfaces:
public interface Arbitrary<T> {
Generator<T> generator();
}
public interface Generator<T> {
T generate(GenSource source);
}
Differences to Jqwik 1
-
Arbitrary.generator()
no longer takes agenSize
: This parameter turned out to be of little use in most cases and made caching of generators much more difficult. -
Generator
- used to be calledRandomGenerator
- can now directly generate values throughgenerate(GenSource source)
method. The detour over aShrinkable
type is no longer necessary. -
The concept of
GenSource
, which is new, will be discussed in other issues.
Standard Transformations
Mapping, filtering, flat-mapping etc. should work as before. The same is true for creating lists, sets etc.
Thus, there'll be a couple of default methods in Arbitrary
:
public interface Arbitrary<T> {
Generator<T> generator();
default <R> Arbitrary<R> map(Function<T, R> mapper) { ... }
default <T> Arbitrary<T> filter(Predicate<T> filter) { ... }
default <R> Arbitrary<R> flatMap(Function<T, Arbitrary<R>> mapper) { ... }
default ListArbitrary<T> list() { ... }
default SetArbitrary<T> set() { ... }
}
Filter or Include / Exclude?
Since the term filter is somewhat ambiguous, a few libraries have switched to provide include
, exclude
, filterIn
, filterOut
or similar clarifying terms. Is this a clarification or does it go against expectations?