Class CollectionGenerator<T extends Collection>
- Type Parameters:
T- the type of collection generated
- Direct Known Subclasses:
ListGenerator,SetGenerator
Base class for generators of Collections.
The generated collection has a number of elements limited by
GenerationStatus.size(), or else by the attributes of a Size
marking. The individual elements will have a type corresponding to the
collection's type argument.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidTells this generator to add elements which are distinct from each other.voidTells this generator to add elements to the generated collection a number of times within a specified minimum and/or maximum, inclusive, chosen with uniform distribution.private TdoShrink(SourceOfRandomness random, T larger) Gives some objects that are "smaller" than a given "larger" object.protected final Tempty()generate(SourceOfRandomness random, GenerationStatus status) Generates a value, possibly influenced by a source of randomness and metadata about the generation.private booleaninSizeRange(T items) Gives a hint to the shrinking process as to the magnitude of the given value.intThis is intended for use only by junit-quickcheck itself, and not by creators of custom generators.protected final voidsetDistinct(boolean distinct) private intsize(SourceOfRandomness random, GenerationStatus status) Methods inherited from class com.pholser.junit.quickcheck.generator.ComponentizedGenerator
addComponentGenerators, canGenerateForParametersOfTypes, canRegisterAsType, componentGenerators, configure, hasComponents, provideMethods inherited from class com.pholser.junit.quickcheck.generator.Generator
canShrink, compatibleWithTypeParameter, configurationAnnotationsOn, configure, copy, gen, gen, narrow, shrink, types
-
Field Details
-
sizeRange
-
distinct
private boolean distinct
-
-
Constructor Details
-
CollectionGenerator
-
-
Method Details
-
configure
Tells this generator to add elements to the generated collection a number of times within a specified minimum and/or maximum, inclusive, chosen with uniform distribution.
Note that some kinds of collections disallow duplicates, so the number of elements added may not be equal to the collection's
Collection.size().- Parameters:
size- annotation that gives the size constraints
-
configure
Tells this generator to add elements which are distinct from each other.- Parameters:
distinct- Generated elements will be distinct if this param is not null
-
setDistinct
protected final void setDistinct(boolean distinct) -
generate
Description copied from interface:GenGenerates a value, possibly influenced by a source of randomness and metadata about the generation.- Parameters:
random- source of randomness to be used when generating the valuestatus- an object that can be used to influence the generated value. For example, generating lists can use thesizemethod to generate lists with a given number of elements.- Returns:
- the generated value
-
doShrink
Description copied from class:GeneratorGives some objects that are "smaller" than a given "larger" object.
Unless overridden, a generator will produce an empty list of "smaller" values.
- Overrides:
doShrinkin classGenerator<T extends Collection>- Parameters:
random- source of randomness to use in shrinking, if desiredlarger- the larger object- Returns:
- objects that are "smaller" than the larger object. Smaller objects should be provided before bigger objects to make shrinking process faster.
-
numberOfNeededComponents
public int numberOfNeededComponents()Description copied from class:GeneratorThis is intended for use only by junit-quickcheck itself, and not by creators of custom generators.
- Overrides:
numberOfNeededComponentsin classGenerator<T extends Collection>- Returns:
- how many component generators this generator needs
- See Also:
-
magnitude
Description copied from class:GeneratorGives a hint to the shrinking process as to the magnitude of the given value. The shrinking process will prefer trying values of greater magnitude before values of lesser magnitude. If not overridden, this implementation returns "one".
Note to generator writers: Do not worry about normalizing a magnitude to a positive value; the shrinking mechanism will take care of it.
- Overrides:
magnitudein classGenerator<T extends Collection>- Parameters:
value- the value to assess- Returns:
- a measure of the given value's magnitude
- See Also:
-
empty
-
inSizeRange
-
size
-
removals
-
convert
-