T - type of generated objects@FunctionalInterface public interface Gen<T>
To ease the creation of Arbitraries, Gen is a FunctionalInterface which extends Function<Random, T>.
Gen objects are obtained via one of the methods choose, fail, frequency, of and
oneOf.
Given Gen objects may be transformed using one of the methods filter, map and flatMap.
A simple way to obtain an Arbitrary of a Gen is to call arbitrary(). This will ignore the size hint of Arbitrary.
Arbitrary| Modifier and Type | Method and Description |
|---|---|
T |
apply(Random random)
Functional interface of this generator.
|
default Arbitrary<T> |
arbitrary()
Converts this Gen to an Arbitrary
|
static Gen<Character> |
choose(char... characters)
Chooses a char from all chars in the array
|
static Gen<Character> |
choose(char min,
char max)
Chooses a char between min and max, bounds inclusive and chars distributed according to the underlying random
number generator.
|
static <T extends Enum<T>> |
choose(Class<T> clazz)
Chooses an enum value from all the enum constants defined in the enumerated type.
|
static Gen<Double> |
choose(double min,
double max)
Chooses a double between min and max, bounds inclusive and numbers distributed according to the distribution
of the underlying random number generator.
|
static Gen<Integer> |
choose(int min,
int max)
Chooses an int between min and max, bounds inclusive and numbers distributed according to the distribution of
the underlying random number generator.
|
static <T> Gen<T> |
choose(Iterable<T> values)
Chooses a value from all values in the iterable
|
static Gen<Long> |
choose(long min,
long max)
Chooses a long between min and max, bounds inclusive and numbers distributed according to the distribution of
the underlying random number generator.
|
static <T> Gen<T> |
choose(T... values)
Chooses a value from all values in the array.
|
static <T> Gen<T> |
fail()
A failing generator which throws a RuntimeException("failed").
|
static <T> Gen<T> |
fail(String message)
A failing generator which throws a RuntimeException.
|
default Gen<T> |
filter(Predicate<? super T> predicate)
Returns a generator based on this generator which produces values that fulfill the given predicate.
|
default <U> Gen<U> |
flatMap(Function<? super T,? extends Gen<? extends U>> mapper)
Maps generated Ts to Us.
|
static <T> Gen<T> |
frequency(Iterable<Tuple2<Integer,Gen<T>>> generators)
Chooses one of the given generators according to their frequency.
|
static <T> Gen<T> |
frequency(Tuple2<Integer,Gen<T>>... generators)
Chooses one of the given generators according to their frequency.
|
default Gen<T> |
intersperse(Gen<T> other)
Intersperse values from this generator instance with those of another.
|
default <U> Gen<U> |
map(Function<? super T,? extends U> mapper)
Maps generated Ts to Us.
|
static <T> Gen<T> |
of(T t)
A generator which constantly returns t.
|
static <T> Gen<T> |
of(T seed,
Function<? super T,? extends T> next) |
static <T> Gen<T> |
oneOf(Gen<T>... generators)
Randomly chooses one of the given generators.
|
static <T> Gen<T> |
oneOf(Iterable<Gen<T>> generators)
Randomly chooses one of the given generators.
|
default Gen<T> |
peek(Consumer<? super T> action) |
default <U> U |
transform(Function<? super Gen<T>,? extends U> f)
Transforms this
Gen. |
T apply(Random random)
random - a random number generatorstatic <T> Gen<T> of(T t)
T - Type of t.t - A value.static Gen<Integer> choose(int min, int max)
Note: min and max are internally swapped if min > max.
min - lower boundmax - upper boundstatic Gen<Long> choose(long min, long max)
Note: min and max are internally swapped if min > max.
min - lower boundmax - upper boundstatic Gen<Double> choose(double min, double max)
Note: min and max are internally swapped if min > max.
min - lower boundmax - upper boundIllegalArgumentException - if min or max is infinite, min or max is not a number (NaN)static Gen<Character> choose(char min, char max)
Note: min and max are internally swapped if min > max.
min - lower boundmax - upper boundstatic Gen<Character> choose(char... characters)
characters - array with the characters to choose fromstatic <T extends Enum<T>> Gen<T> choose(Class<T> clazz)
T - type of enum constantsclazz - Enum class@SafeVarargs static <T> Gen<T> choose(T... values)
T - value typevalues - array with the values to choose fromstatic <T> Gen<T> choose(Iterable<T> values)
T - value typevalues - iterable with the values to choose from.static <T> Gen<T> fail()
T - Type of values theoretically generated.static <T> Gen<T> fail(String message)
T - Type of values theoretically generated.message - Message thrown.@SafeVarargs static <T> Gen<T> frequency(Tuple2<Integer,Gen<T>>... generators)
T - Type to be generatedgenerators - A non-empty array of Tuples (frequency, generator)NullPointerException - if generators is nullIllegalArgumentException - if generators doesn't contain any generator with positive frequencystatic <T> Gen<T> frequency(Iterable<Tuple2<Integer,Gen<T>>> generators)
T - Type to be generatedgenerators - A non-empty traversable of Tuples (frequency, generator)NullPointerException - if generators is nullIllegalArgumentException - if generators doesn't contain any generator with positive frequencydefault Gen<T> intersperse(Gen<T> other)
other - another T generator to accept values from.@SafeVarargs static <T> Gen<T> oneOf(Gen<T>... generators)
T - Type to be generatedgenerators - A non-empty array of generatorsNullPointerException - if generators is nullIllegalArgumentException - if generators is emptystatic <T> Gen<T> oneOf(Iterable<Gen<T>> generators)
T - Type to be generatedgenerators - A non-empty Iterable of generatorsNullPointerException - if generators is nullIllegalArgumentException - if generators is emptydefault Arbitrary<T> arbitrary()
default Gen<T> filter(Predicate<? super T> predicate)
predicate - A predicatedefault <U> Gen<U> flatMap(Function<? super T,? extends Gen<? extends U>> mapper)
U - Type of generated objects of the new generatormapper - A function that maps a generated T to a new generator which generates objects of type U.default <U> Gen<U> map(Function<? super T,? extends U> mapper)
U - Type of the mapped objectmapper - A function that maps a generated T to an object of type U.default <U> U transform(Function<? super Gen<T>,? extends U> f)
Gen.U - Type of transformation resultf - A transformationUNullPointerException - if f is nullCopyright © 2021. All Rights Reserved.