@API(status=STABLE,
since="1.0")
public class Arbitraries
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
Arbitraries.ArbitrariesFacade |
Modifier and Type | Method and Description |
---|---|
static BigDecimalArbitrary |
bigDecimals()
Create an arbitrary that generates values of type BigDecimal.
|
static BigIntegerArbitrary |
bigIntegers()
Create an arbitrary that generates values of type BigInteger.
|
static ByteArbitrary |
bytes()
Create an arbitrary that generates values of type Byte.
|
static CharacterArbitrary |
chars()
Create an arbitrary that generates values of type Character.
|
static <T> Arbitrary<T> |
constant(T value)
Create an arbitrary that will always generate the same value.
|
static <T> Arbitrary<T> |
create(java.util.function.Supplier<T> supplier)
Create an arbitrary that will use a supplier to generate a value.
|
static <T> Arbitrary<T> |
defaultFor(java.lang.Class<T> type,
java.lang.Class<?>... typeParameters)
Find a registered arbitrary that will be used to generate values of type T.
|
static <T> Arbitrary<T> |
defaultFor(TypeUsage typeUsage)
Find a registered arbitrary that will be used to generate values of type T.
|
static DoubleArbitrary |
doubles()
Create an arbitrary that generates values of type Double.
|
static <K,V> Arbitrary<java.util.Map.Entry<K,V>> |
entries(Arbitrary<K> keysArbitrary,
Arbitrary<V> valuesArbitrary)
Create an arbitrary to create instances of Map.Entry.
|
static FloatArbitrary |
floats()
Create an arbitrary that generates values of type Float.
|
static <T> TypeArbitrary<T> |
forType(java.lang.Class<T> targetType)
Create an arbitrary for type
T that will by default use the type's
public constructors and public factory methods. |
static <T> Arbitrary<T> |
frequency(java.util.List<Tuple.Tuple2<java.lang.Integer,T>> frequencies)
Create an arbitrary that will randomly choose between all given values of the same type T.
|
static <T> Arbitrary<T> |
frequency(Tuple.Tuple2<java.lang.Integer,T>... frequencies)
Create an arbitrary that will randomly choose between all given values of the same type T.
|
static <T> Arbitrary<T> |
frequencyOf(java.util.List<Tuple.Tuple2<java.lang.Integer,Arbitrary<T>>> frequencies)
Create an arbitrary that will randomly choose between all given arbitraries of the same type T.
|
static <T> Arbitrary<T> |
frequencyOf(Tuple.Tuple2<java.lang.Integer,Arbitrary<T>>... frequencies)
Create an arbitrary that will randomly choose between all given arbitraries of the same type T.
|
static <T> Arbitrary<T> |
fromGenerator(RandomGenerator<T> generator)
Create an arbitrary of type T from a corresponding generator of type T.
|
static IntegerArbitrary |
integers()
Create an arbitrary that generates values of type Integer.
|
static <T> Arbitrary<T> |
lazy(java.util.function.Supplier<Arbitrary<T>> arbitrarySupplier)
Create an arbitrary that will evaluate arbitrarySupplier as soon as it is used for generating values.
|
static LongArbitrary |
longs()
Create an arbitrary that generates values of type Long.
|
static <K,V> SizableArbitrary<java.util.Map<K,V>> |
maps(Arbitrary<K> keysArbitrary,
Arbitrary<V> valuesArbitrary)
Create an arbitrary to create instances of Map.
|
static Arbitrary<java.lang.Void> |
nothing()
Create an arbitrary that never creates anything.
|
static Arbitrary<java.lang.Character> |
of(char[] values)
Create an arbitrary of character values.
|
static <T extends java.lang.Enum<T>> |
of(java.lang.Class<T> enumClass)
Create an arbitrary for enum values of type T.
|
static <T> Arbitrary<T> |
of(java.util.Collection<T> values)
Create an arbitrary that will randomly choose from a given collection of values.
|
static <T> Arbitrary<T> |
of(T... values)
Create an arbitrary that will randomly choose from a given array of values.
|
static <T> Arbitrary<T> |
ofSuppliers(java.util.Collection<java.util.function.Supplier<T>> valueSuppliers)
Create an arbitrary that will randomly choose from a given collection of value suppliers
and then get the value from the supplier.
|
static <T> Arbitrary<T> |
ofSuppliers(java.util.function.Supplier<T>... valueSuppliers)
Create an arbitrary that will randomly choose from a given array of value suppliers
and then get the value from the supplier.
|
static <T> Arbitrary<T> |
oneOf(Arbitrary<? extends T> first,
Arbitrary<? extends T>... rest)
Create an arbitrary that will randomly choose between all given arbitraries of the same type T.
|
static <T> Arbitrary<T> |
oneOf(java.util.List<Arbitrary<T>> all)
Create an arbitrary that will randomly choose between all given arbitraries of the same type T.
|
static Arbitrary<java.util.Random> |
randoms()
Create an arbitrary for Random objects.
|
static <T> Arbitrary<T> |
randomValue(java.util.function.Function<java.util.Random,T> generator)
Create an arbitrary that will generate values of type T using a generator function.
|
static <T> Arbitrary<T> |
recursive(java.util.function.Supplier<Arbitrary<T>> base,
java.util.function.Function<Arbitrary<T>,Arbitrary<T>> recur,
int depth)
Create an arbitrary by deterministic recursion.
|
static <T> Arbitrary<T> |
samples(T... samples)
Deprecated.
Use
of(Object[]) or move to data-driven properties if order is important. Will be removed in version 1.4.0 |
static <M> ActionSequenceArbitrary<M> |
sequences(Arbitrary<? extends Action<M>> actionArbitrary)
Create an arbitrary to create a sequence of actions.
|
static ShortArbitrary |
shorts()
Create an arbitrary that generates values of type Short.
|
static <T> Arbitrary<java.util.List<T>> |
shuffle(java.util.List<T> values)
Create an arbitrary that will always generate a list which is a
permutation of the values handed to it.
|
static <T> Arbitrary<java.util.List<T>> |
shuffle(T... values)
Create an arbitrary that will always generate a list which is a
permutation of the values handed to it.
|
static StringArbitrary |
strings()
Create an arbitrary that generates values of type String.
|
public static <T> Arbitrary<T> fromGenerator(RandomGenerator<T> generator)
T
- The type of values to generategenerator
- The generator to be used for generating the valuespublic static <T> Arbitrary<T> randomValue(java.util.function.Function<java.util.Random,T> generator)
T
- The type of values to generategenerator
- The generator function to be used for generating the valuespublic static Arbitrary<java.util.Random> randoms()
@SafeVarargs public static <T> Arbitrary<T> of(T... values)
Use this method only for immutable values, because changing the value will change subsequent generated values as well. For mutable values use ofSuppliers(Supplier[]) instead.
T
- The type of values to generatevalues
- The array of values to choose from@API(status=MAINTAINED, since="1.3.1") public static <T> Arbitrary<T> of(java.util.Collection<T> values)
Use this method only for immutable values, because changing the value will change subsequent generated values as well. For mutable values use ofSuppliers(Collection) instead.
T
- The type of values to generatevalues
- The collection of values to choose from@API(status=MAINTAINED, since="1.3.0") @SafeVarargs public static <T> Arbitrary<T> ofSuppliers(java.util.function.Supplier<T>... valueSuppliers)
Use this method instead of of(Object[]) for mutable objects to make sure that changing a generated object will not influence other generated objects.
T
- The type of values to generatevalueSuppliers
- The array of values to choose from@API(status=MAINTAINED, since="1.3.1") public static <T> Arbitrary<T> ofSuppliers(java.util.Collection<java.util.function.Supplier<T>> valueSuppliers)
Use this method instead of of(Collection) for mutable objects to make sure that changing a generated object will not influence other generated objects.
T
- The type of values to generatevalueSuppliers
- The collection of values to choose frompublic static Arbitrary<java.lang.Character> of(char[] values)
values
- The array of characters to choose from.public static <T extends java.lang.Enum<T>> Arbitrary<T> of(java.lang.Class<T> enumClass)
T
- The type of values to generateenumClass
- The enum class.@SafeVarargs public static <T> Arbitrary<T> oneOf(Arbitrary<? extends T> first, Arbitrary<? extends T>... rest)
T
- The type of values to generatefirst
- The first arbitrary to choose formrest
- An array of arbitraries to choose frompublic static <T> Arbitrary<T> oneOf(java.util.List<Arbitrary<T>> all)
T
- The type of values to generateall
- A list of arbitraries to choose from@SafeVarargs public static <T> Arbitrary<T> frequency(Tuple.Tuple2<java.lang.Integer,T>... frequencies)
T
- The type of values to generatefrequencies
- An array of tuples of which the first parameter gives the weight and the second the value.public static <T> Arbitrary<T> frequency(java.util.List<Tuple.Tuple2<java.lang.Integer,T>> frequencies)
T
- The type of values to generatefrequencies
- A list of tuples of which the first parameter gives the weight and the second the value.@SafeVarargs public static <T> Arbitrary<T> frequencyOf(Tuple.Tuple2<java.lang.Integer,Arbitrary<T>>... frequencies)
T
- The type of values to generatefrequencies
- An array of tuples of which the first parameter gives the weight and the second the arbitrary.public static <T> Arbitrary<T> frequencyOf(java.util.List<Tuple.Tuple2<java.lang.Integer,Arbitrary<T>>> frequencies)
T
- The type of values to generatefrequencies
- A list of tuples of which the first parameter gives the weight and the second the arbitrary.public static IntegerArbitrary integers()
public static LongArbitrary longs()
public static BigIntegerArbitrary bigIntegers()
public static FloatArbitrary floats()
public static BigDecimalArbitrary bigDecimals()
public static DoubleArbitrary doubles()
public static ByteArbitrary bytes()
public static ShortArbitrary shorts()
public static StringArbitrary strings()
public static CharacterArbitrary chars()
@SafeVarargs @Deprecated @API(status=DEPRECATED, since="1.3.0") public static <T> Arbitrary<T> samples(T... samples)
of(Object[])
or move to data-driven properties if order is important. Will be removed in version 1.4.0
Attention: If you want to randomly choose between samples
you must use of(Object[])
T
- The type of values to generatesamples
- The array of sample valuespublic static <T> Arbitrary<T> constant(T value)
T
- The type of values to generatevalue
- The value to "generate"@API(status=MAINTAINED, since="1.1.1") public static <T> Arbitrary<T> create(java.util.function.Supplier<T> supplier)
For exhaustive shrinking all generated values are supposed to have identical behaviour, i.e. that means that only one value is generated per combination.
T
- The type of values to generatesupplier
- The supplier use to generate a value@SafeVarargs public static <T> Arbitrary<java.util.List<T>> shuffle(T... values)
T
- The type of values to generatevalues
- The values to permutepublic static <T> Arbitrary<java.util.List<T>> shuffle(java.util.List<T> values)
T
- The type of values to generatevalues
- The values to permutepublic static <T> Arbitrary<T> defaultFor(java.lang.Class<T> type, java.lang.Class<?>... typeParameters)
T
- The type of values to generatetype
- The type of the value to find an arbitrary fortypeParameters
- The type parameters if type is a generic typeCannotFindArbitraryException
- if there is no registered arbitrary provider to serve this type@API(status=MAINTAINED, since="1.1") public static <T> Arbitrary<T> defaultFor(TypeUsage typeUsage)
T
- The type of values to generatetypeUsage
- The type of the value to find an arbitrary forCannotFindArbitraryException
- if there is no registered arbitrary provider to serve this type@API(status=MAINTAINED, since="1.2.0") public static <T> TypeArbitrary<T> forType(java.lang.Class<T> targetType)
T
that will by default use the type's
public constructors and public factory methods.T
- The type of values to generatetargetType
- The class of the type to create an arbitrary forTypeArbitrary
public static <T> Arbitrary<T> lazy(java.util.function.Supplier<Arbitrary<T>> arbitrarySupplier)
This is useful (and necessary) when arbitrary providing functions use other arbitrary providing functions in a recursive way. Without the use of lazy() this would result in a stack overflow.
T
- The type of values to generatearbitrarySupplier
- The supplier function being used to generate an arbitraryrecursive(Supplier, Function, int)
public static <T> Arbitrary<T> recursive(java.util.function.Supplier<Arbitrary<T>> base, java.util.function.Function<Arbitrary<T>,Arbitrary<T>> recur, int depth)
Mind that the arbitrary will be created by invoking recursion at arbitrary creation time. Using lazy(Supplier) instead will recur at value generation time.
T
- The type of values to generatebase
- The supplier returning the recursion's base caserecur
- The function to extend the base casedepth
- The number of times to invoke recursionlazy(Supplier)
@API(status=MAINTAINED, since="1.0") public static <M> ActionSequenceArbitrary<M> sequences(Arbitrary<? extends Action<M>> actionArbitrary)
M
- The type of actions to generateactionArbitrary
- The arbitrary to generate individual actions.@API(status=MAINTAINED, since="1.1.6") public static <K,V> SizableArbitrary<java.util.Map<K,V>> maps(Arbitrary<K> keysArbitrary, Arbitrary<V> valuesArbitrary)
K
- type of keysV
- type of valueskeysArbitrary
- The arbitrary to generate the keysvaluesArbitrary
- The arbitrary to generate the values@API(status=MAINTAINED, since="1.2.0") public static <K,V> Arbitrary<java.util.Map.Entry<K,V>> entries(Arbitrary<K> keysArbitrary, Arbitrary<V> valuesArbitrary)
K
- type of keysV
- type of valueskeysArbitrary
- The arbitrary to generate the keysvaluesArbitrary
- The arbitrary to generate the values@API(status=MAINTAINED, since="1.3.0") public static Arbitrary<java.lang.Void> nothing()