Class BigDecimalGenerator
- All Implemented Interfaces:
Gen<BigDecimal>,Shrink<BigDecimal>
Produces values of type BigDecimal.
With no additional configuration, the generated values are chosen from
a range with a magnitude decided by
GenerationStatus.size().
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidTells this generator to produce values that have a specified scale.private intgenerate(SourceOfRandomness random, GenerationStatus status) Generates a value, possibly influenced by a source of randomness and metadata about the generation.protected Predicate<BigDecimal>inRange()protected BigDecimalGives a hint to the shrinking process as to the magnitude of the given value.protected Function<BigDecimal,BigDecimal> narrow()protected BigDecimalnegate(BigDecimal target) Used when shrinking negative numbers to add the positive equivalent value at the top of shrinks list.protected booleannegative(BigDecimal target) protected Function<BigDecimal,BigDecimal> widen()Methods inherited from class com.pholser.junit.quickcheck.generator.DecimalGenerator
doShrinkMethods inherited from class com.pholser.junit.quickcheck.generator.Generator
addComponentGenerators, canGenerateForParametersOfTypes, canRegisterAsType, canShrink, compatibleWithTypeParameter, configurationAnnotationsOn, configure, configure, copy, gen, gen, hasComponents, narrow, numberOfNeededComponents, provide, shrink, types
-
Field Details
-
min
-
max
-
precision
-
-
Constructor Details
-
BigDecimalGenerator
public BigDecimalGenerator()
-
-
Method Details
-
configure
Tells this generator to produce values within a specified minimum (inclusive) and/or maximum (exclusive), with uniform distribution.
If an endpoint of the range is not specified, its value takes on a magnitude influenced by
GenerationStatus.size().- Parameters:
range- annotation that gives the range's constraints
-
configure
Tells this generator to produce values that have a specified scale.
With no precision constraint and no min/max constraint, the scale of the generated values is unspecified.
Otherwise, the scale of the generated values is set as
max(0, precision.scale, range.min.scale, range.max.scale).- Parameters:
configuration- annotation that gives the desired scale of the generated values
-
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
-
decideScale
private int decideScale() -
widen
- Specified by:
widenin classDecimalGenerator<BigDecimal>- Returns:
- a function converting a value of the base type into a
BigDecimal
-
narrow
- Specified by:
narrowin classDecimalGenerator<BigDecimal>- Returns:
- a function converting a
BigDecimalinto the equivalent value in the base type
-
inRange
- Specified by:
inRangein classDecimalGenerator<BigDecimal>- Returns:
- a predicate checking whether its input is in the configured range
-
leastMagnitude
- Specified by:
leastMagnitudein classDecimalGenerator<BigDecimal>- Returns:
- the lowest magnitude number, respecting the configured range. The ideal shrink value is always this value (i.e. this value cannot be shrunk any further).
-
negative
- Specified by:
negativein classDecimalGenerator<BigDecimal>- Returns:
- whether the given number is negative or not
-
negate
Description copied from class:DecimalGeneratorUsed when shrinking negative numbers to add the positive equivalent value at the top of shrinks list.- Specified by:
negatein classDecimalGenerator<BigDecimal>- Parameters:
target- always a negative number- Returns:
- the positive equivalent to target
-
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<BigDecimal>- Parameters:
value- the value to assess- Returns:
- a measure of the given value's magnitude
- See Also:
-