Class CombinedGenerators
CombinedGenerators can be used to create custom Generators.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Generator<T[]>Create a generator of arrays with values from the content generator.static <T> Generator<T[]>Create a generator of arrays with values from the content generator.static Generator<byte[]>Create a generator of byte arrays.static Generator<byte[]>byteArrays(Generator<Byte> content, Generator<Integer> size) Create a generator of byte arrays.static Generator<byte[]>byteArrays(Generator<Integer> size) Create a generator of byte arrays.duplicates(Iterable<T> input) Create a generator that produces lists of duplicates.duplicates(T... input) Create a generator that produces lists of duplicates.static <T> StatefulGenerator<T>ensureValues(Iterable<T> ensuredValues) Create a deterministic generator which guarantees that all values from the ensuredValues collection will be returnGenerator.next()are issued (i.e.static <T> StatefulGenerator<T>ensureValues(Iterable<T> ensuredValues, int window, Generator<T> otherValues) Create a generator which guarantees that all values from the ensuredValues will be returnGenerator.next()are issued.static <T> StatefulGenerator<T>ensureValues(Iterable<T> ensuredValues, Generator<T> otherValues) Create a deterministic generator which guarantees that all values from the ensuredValues collection will be returnGenerator.next()are issued (i.e.static <T> StatefulGenerator<T>ensureValues(T... content) Create a deterministic generator which guarantees that all values from the ensuredValues array will be returnGenerator.next()are issued (i.e.static <T> Generator<T>excludeValues(Generator<T> generator, Iterable<T> excluded) Create a generator that omits a given set of values.static <T> Generator<T>excludeValues(Generator<T> generator, T... excluded) Create a generator that omits a given set of values.static <T> Generator<T>excludeValues(Iterable<T> values, Iterable<T> excluded) Create a generator that omits a given set of values.static <T> Generator<T>excludeValues(Iterable<T> values, T... excluded) Create a generator that omits a given set of values.static <T> FrequencyGenerator<T>Create a frequency generator.static Generator<int[]>Create a generator of integer arrays.static Generator<int[]>Create a generator of integer arrays.static Generator<int[]>Create a generator of integer arrays.Create a generator of iterators.Create a generator of iterators.Create a generator of lists with values from the content generator.Create a generator of lists with values from the content generator.Create a generator of lists with values from the content generator.Create a generator of lists with values from the content generator.Create a generator ofmaps.Create a generator ofmaps.Create a generator of maps from a given map.Create a generator of maps from a given map.static <T> Generator<T[]>nonEmptyArrays(Generator<? extends T> content, Class<T> type) Create a generator of arrays that are not empty.nonEmptyIterators(Generator<T> content) Create a generator of iterators.nonEmptyLists(Generator<? extends T> content) Create a generator of non-empty lists with values from the content generator.nonEmptySets(Generator<? extends T> content) Create a generator of sets that are not empty.static <T> Generator<T>Create a generator as a combination of a null value generator and generator of type T.static <T> Generator<T>Create a generator as a combination of a null value generator and generator of type T.static <T> Generator<T>nullsAnd(T... values) Create a generator return the given values.static <T> ExtendibleGenerator<T,T> OneOf is a convenience method forfrequency(Generator, int)when all generator share the same weight.Create a generator of pairs of type A for the left value and type B for the right value.Create a generator of sets with values from the content generator.Create a generator of sets with values from the content generator.Create a generator of sets with values from the content generator.Create a generator of subsets from a given set.Create a generator of subsets from a given set.sets(T... superset) static <T extends Comparable<T>>
Generator<List<T>>sortedLists(Generator<T> content) Create a generator of sorted lists with values from the content generator.static <T extends Comparable<T>>
Generator<List<T>>sortedLists(Generator<T> content, int low, int high) Create a generator of sorted lists with values from the content generator.static <T extends Comparable<T>>
Generator<List<T>>sortedLists(Generator<T> content, Generator<Integer> size) Create a generator of sorted lists with values from the content generator.static <T extends Comparable<T>>
Generator<Pair<T,T>> sortedPairs(Generator<T> content) Create a generator of pairs where first value <= second value.static <T extends Comparable<T>>
Generator<Triple<T,T, T>> sortedTriple(Generator<T> content) Create a generator of triples where first value <= second value <= third value.static <T extends Comparable<T>>
Generator<List<T>>strictlyOrdered(Generator<T> input) A generator for a lists.static <T extends Comparable<T>>
Generator<List<T>>strictlyOrdered(Generator<T> input, int low, int high) A generator for a lists.strictlyOrdered(Generator<T> input, Comparator<T> comparator) A generator for a lists.strictlyOrdered(Generator<T> input, Comparator<T> comparator, Generator<Integer> size) A generator for a lists.Create a generator of triples of the types A, B and C for first, second and third value.static <T> StatefulGenerator<T>uniqueValues(Generator<T> generator) Create a generator that ensures unique valuesstatic <T> StatefulGenerator<T>uniqueValues(Generator<T> generator, int tries) Create a generator that ensures unique values.static <T> StatefulGenerator<T>uniqueValues(Generator<T> generator, Comparator<? super T> comparator) Create a generator that ensures unique values.static <T> StatefulGenerator<T>uniqueValues(Generator<T> generator, Comparator<? super T> comparator, int tries) Create a generator that ensures unique values.Create a generator which will create vectors (here lists) of type T.
-
Field Details
-
DEFAULT_COLLECTION_MAX_SIZE
- See Also:
-
DEFAULT_MAX_TRIES
- See Also:
-
-
Constructor Details
-
CombinedGenerators
public CombinedGenerators()
-
-
Method Details
-
frequency
Create a frequency generator. The frequency of
Generatorusage depends on the generator weight.- Type Parameters:
T- type of values generated by the generators.- Parameters:
generator- pairs of generators and their weights used to created the values
-
oneOf
OneOf is a convenience method forfrequency(Generator, int)when all generator share the same weight. -
vectors
Create a generator which will create vectors (here lists) of type T.- Type Parameters:
T- Type of the list values.- Parameters:
size- Number of element in the vector.
-
pairs
Create a generator of pairs of type A for the left value and type B for the right value.- Type Parameters:
A- Type of left value.B- Type of right value.- Parameters:
first- Generator for left values.second- Generator for right values.
-
sortedPairs
Create a generator of pairs where first value <= second value.- Type Parameters:
T- Type of the pair values.- Parameters:
content- Generator for content of the pair values.
-
triples
public static <A,B, Generator<Triple<A,C> B, triplesC>> (Generator<A> first, Generator<B> second, Generator<C> third) Create a generator of triples of the types A, B and C for first, second and third value.- Type Parameters:
A- Type of first value.B- Type of second value.C- Type of third value.- Parameters:
first- Generator for first values.second- Generator for second values.third- Generator for third values.
-
nullsAnd
Create a generator return the given values.- Type Parameters:
T- Type of the values generated.
-
sortedTriple
Create a generator of triples where first value <= second value <= third value.- Type Parameters:
T- Type of the triple values.- Parameters:
content- Generator for content of the triple values.
-
nullsAnd
Create a generator as a combination of a null value generator and generator of type T.- Type Parameters:
T- Type of the values generated.
-
nullsAnd
Create a generator as a combination of a null value generator and generator of type T.- Type Parameters:
T- Type of the values generated.- Parameters:
weight- weight of the provided generator
-
sets
Create a generator of sets with values from the content generator.- Type Parameters:
T- type of set elements generated- Parameters:
content- generator providing the content of sets generated
-
sets
Create a generator of sets with values from the content generator.- Type Parameters:
T- type of set elements generated- Parameters:
content- generator providing the content of sets generatedsize- size of the sets generated
-
sets
Create a generator of sets with values from the content generator. Length is between high and low.- Type Parameters:
T- type of set elements generated- Parameters:
content- generator providing the content of sets generatedlow- minimal sizehigh- max size
-
nonEmptySets
Create a generator of sets that are not empty.- Type Parameters:
T- type of set elements generated- Parameters:
content- generator providing the content of sets generated
-
sets
-
sets
Create a generator of subsets from a given set.- Type Parameters:
T- type of set elements generated- Parameters:
superset- of the generated set
-
sets
Create a generator of subsets from a given set.- Type Parameters:
T- type of set elements generated- Parameters:
superset- of the generated setsize- of the generated set
-
duplicates
Create a generator that produces lists of duplicates.- Returns:
- a list derived from the input values. At least one input value is more than once in the resulting list.
-
duplicates
Create a generator that produces lists of duplicates.- Returns:
- a list derived from the input values. At least one input value is more than once in the resulting list.
-
iterators
Create a generator of iterators.Values of the elements will be taken from the content generator.
- Type Parameters:
T- type of iterator elements generated- Parameters:
content- generator providing the content of iterators generated
-
nonEmptyIterators
Create a generator of iterators.Values of the elements will be taken from the content generator. The generated iterator will have at least one element.
- Type Parameters:
T- type of iterator elements generated- Parameters:
content- generator providing the content of iterators generated
-
iterators
public static <T> Generator<Iterator<T>> iterators(Generator<? extends T> content, Generator<Integer> size) Create a generator of iterators.Values of the elements will be taken from the content generator. The length of the iterators will be determined with the size generator.
- Type Parameters:
T- type of iterator elements generated- Parameters:
content- generator providing the content of iterators generatedsize- used to determine the number of elements of the iterator
-
lists
Create a generator of lists with values from the content generator. Length values of lists generated will be created withDistribution.UNIFORM.- Type Parameters:
T- type of list elements generated- Parameters:
content- generator providing the content of lists generated
-
nonEmptyLists
Create a generator of non-empty lists with values from the content generator. Length values of lists generated will be created withDistribution.UNIFORM.- Type Parameters:
T- type of list elements generated- Parameters:
content- generator providing the content of lists generated
-
lists
Create a generator of lists with values from the content generator. Length values of lists generated will be created with size generator.- Type Parameters:
T- type of list elements generated- Parameters:
content- generator providing the content of lists generatedsize- integer used to determine the list size
-
lists
Create a generator of lists with values from the content generator. Length is between high and low.- Type Parameters:
T- type of list elements generated- Parameters:
content- generator providing the content of lists generatedlow- minimal sizehigh- max size
-
lists
Create a generator of lists with values from the content generator. Length is at least low.- Type Parameters:
T- type of list elements generated- Parameters:
content- generator providing the content of lists generatedlow- minimal size. If low is larger thanDEFAULT_COLLECTION_MAX_SIZEthen it is the upper size bound as well.
-
sortedLists
Create a generator of sorted lists with values from the content generator.- Type Parameters:
T- type of list elements generated- Parameters:
content- generator providing the content of lists generated
-
sortedLists
public static <T extends Comparable<T>> Generator<List<T>> sortedLists(Generator<T> content, int low, int high) Create a generator of sorted lists with values from the content generator. Length is between high and low.- Type Parameters:
T- type of list elements generated- Parameters:
content- generator providing the content of lists generatedlow- minimal sizehigh- max size
-
sortedLists
public static <T extends Comparable<T>> Generator<List<T>> sortedLists(Generator<T> content, Generator<Integer> size) Create a generator of sorted lists with values from the content generator. Length is between high and low.- Type Parameters:
T- type of list elements generated- Parameters:
content- generator providing the content of lists generatedsize- integer used to determine the list size
-
arrays
Create a generator of arrays with values from the content generator. Length values of array generated will be created withDistribution.UNIFORM.- Type Parameters:
T- type of arrays elements generated- Parameters:
content- generator providing the content of arrays generatedtype- type of arrays generated
-
nonEmptyArrays
Create a generator of arrays that are not empty.- Type Parameters:
T- type of arrays elements generated- Parameters:
content- generator providing the content of arrays generatedtype- type of arrays generated
-
arrays
public static <T> Generator<T[]> arrays(Generator<? extends T> content, Generator<Integer> size, Class<T> type) Create a generator of arrays with values from the content generator. Length values of arrays generated will be created with size generator.- Type Parameters:
T- type of arrays elements generated- Parameters:
content- generator providing the content of arrays generatedsize- integer used to determine the array sizetype- type of arrays generated
-
byteArrays
Create a generator of byte arrays. The length of arrays generated will be determined by theByteArrayGenerator.MIN_SIZEandByteArrayGenerator.MAX_SIZEconstants. -
byteArrays
Create a generator of byte arrays. Length values of arrays generated will be created with size generator.- Parameters:
size- integer used to determine the array size
-
byteArrays
Create a generator of byte arrays. Length values of arrays generated will be created with size generator.- Parameters:
size- integer used to determine the array sizecontent- generator for the byte array content
-
intArrays
Create a generator of integer arrays. -
intArrays
Create a generator of integer arrays. Length values of arrays generated will be created with size generator.- Parameters:
size- integer used to determine the array size
-
intArrays
Create a generator of integer arrays. Length values of arrays generated will be created with size generator.- Parameters:
size- integer used to determine the array sizecontent- generator for the integer array content
-
maps
Create a generator ofmaps.This is a generator for simple maps where the values are not related to the keys.
-
maps
public static <K,V> Generator<Map<K,V>> maps(Generator<K> keys, Generator<V> values, Generator<Integer> size) Create a generator ofmaps.This is a generator for simple maps where the values are not related to the keys.
-
maps
Create a generator of maps from a given map.The entry set of the generated maps are subsets of the given map's entry set.
- Parameters:
supermap- of the generated maps
-
maps
Create a generator of maps from a given map.The entry set of the generated maps are subsets of the given map's entry set.
- Parameters:
supermap- of the generated mapssizes- of the generated maps
-
ensureValues
Create a deterministic generator which guarantees that all values from the ensuredValues collection will be returnGenerator.next()are issued (i.e. ensuredValues.size() <= # of runs). The order of values is undefined.- Type Parameters:
T- type of values return
-
ensureValues
Create a deterministic generator which guarantees that all values from the ensuredValues array will be returnGenerator.next()are issued (i.e. ensuredValues.size() <= # of runs). The order of values is undefined.- Type Parameters:
T- type of values return
-
ensureValues
public static <T> StatefulGenerator<T> ensureValues(Iterable<T> ensuredValues, Generator<T> otherValues) Create a deterministic generator which guarantees that all values from the ensuredValues collection will be return
Generator.next()are issued (i.e. ensuredValues.size() <= # of runs). The order of values is undefined.If all values of ensuredValues are generated calls to
Generator.next()will return generator.- Type Parameters:
T- type of values return
-
ensureValues
public static <T> StatefulGenerator<T> ensureValues(Iterable<T> ensuredValues, int window, Generator<T> otherValues) Create a generator which guarantees that all values from the ensuredValues will be return
Generator.next()are issued.The order of values is undefined. All other values in the window and after the window are taken from the
generator otherValues.- Type Parameters:
T- type of values return- Parameters:
window- After window number of calls toGenerator.next()it is guaranteed that all ensured values were return
-
uniqueValues
Create a generator that ensures unique values.
The actual values are created with an arbitrary generator.
Note: unique generator depends on valid implementation of equals and hashCode method of the content type generated.
- Type Parameters:
T- type of values return- Parameters:
generator- used to create the raw values. This generator can create duplicate valuestries- Number of tries to create a new unique value. After this number of tries is exceeded the generation aborts with aGeneratorException.- Returns:
- unique generator instance
-
uniqueValues
public static <T> StatefulGenerator<T> uniqueValues(Generator<T> generator, Comparator<? super T> comparator, int tries) Create a generator that ensures unique values.
The actual values are created with an arbitrary generator.
Unique generator depends on the
Comparatorimplementation to decide if two instances are the same (i.e. when the comparator return forComparator.compare(Object, Object)).- Type Parameters:
T- type of values return- Parameters:
generator- used to create the raw values. This generator can create duplicate valuescomparator- that decides if two values are of the same equivalence class.tries- Number of tries to create a new unique value. After this number of tries is exceeded the generation aborts with aGeneratorException.- Returns:
- unique generator instance
-
uniqueValues
public static <T> StatefulGenerator<T> uniqueValues(Generator<T> generator, Comparator<? super T> comparator) Create a generator that ensures unique values.
The actual values are created with an arbitrary generator.
Unique generator depends on the
Comparatorimplementation to decide if two instances are the same (i.e. when the comparator return forComparator.compare(Object, Object)).- Type Parameters:
T- type of values return- Parameters:
generator- used to create the raw values. This generator can create duplicate valuescomparator- that decides if two values are of the same equivalence class.- Returns:
- unique generator instance
-
uniqueValues
Create a generator that ensures unique values
The actual values are created with an arbitrary generator.
Note: unique generator depends on valid implementation of equals and hashCode method of the content type generated.
- Type Parameters:
T- type of values return- Parameters:
generator- used to create the raw values. This generator can create duplicate values- Returns:
- unique generator instance
-
excludeValues
Create a generator that omits a given set of values.- Parameters:
generator- used to create the raw values.excluded- values. These values will not be return
-
excludeValues
Create a generator that omits a given set of values.- Parameters:
values- of generatorexcluded- values. These values will not be return
-
excludeValues
Create a generator that omits a given set of values.- Parameters:
values- of generatorexcluded- values. These values will not be return
-
excludeValues
Create a generator that omits a given set of values.- Parameters:
generator- used to create the raw values.excluded- values. These values will not be return
-
strictlyOrdered
A generator for a lists. The values in the lists are strictly increasing.For every element x in the list: x(n) < x(n+1).
- Parameters:
input- values generator
-
strictlyOrdered
public static <T extends Comparable<T>> Generator<List<T>> strictlyOrdered(Generator<T> input, int low, int high) A generator for a lists. The values in the lists are strictly increasing.For every element x in the list: x(n) < x(n+1).
- Parameters:
input- values generatorlow- minimum size of the listshigh- maximum size of the lists
-
strictlyOrdered
A generator for a lists. The values in the lists are strictly increasing.For every element x in the list: x(n) < x(n+1).
This
Generatorcan be used to generate a list of strictly decreasing values:CombinedGenerators.strictlyOrdered(ts, Collections.<T> reverseOrder());- Parameters:
input- values generatorcomparator- that orders the values
-
strictlyOrdered
public static <T> Generator<List<T>> strictlyOrdered(Generator<T> input, Comparator<T> comparator, Generator<Integer> size) A generator for a lists. The values in the lists are strictly increasing.For every element x in the list: x(n) < x(n+1).
- Parameters:
input- values generatorcomparator- that orders the valuessize- of the resulting lists
-