Class DecimalGenerator<T extends Number>
java.lang.Object
com.pholser.junit.quickcheck.generator.Generator<T>
com.pholser.junit.quickcheck.generator.DecimalGenerator<T>
- Type Parameters:
T- type of values this generator produces
- Direct Known Subclasses:
BigDecimalGenerator,DoubleGenerator,FloatGenerator
Base class for generators of decimal types, such as
double and
BigDecimal. All numbers are converted to/from BigDecimal for
processing.-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDecimalGenerator(Class<T> type) protectedDecimalGenerator(List<Class<T>> types) -
Method Summary
Modifier and TypeMethodDescriptiondecimalsFrom(Stream<BigDecimal> stream) doShrink(SourceOfRandomness random, T largestGeneric) Gives some objects that are "smaller" than a given "larger" object.inRange()protected abstract Tprotected abstract Function<BigDecimal,T> narrow()protected abstract TUsed when shrinking negative numbers to add the positive equivalent value at the top of shrinks list.protected abstract booleanshrunkenDecimals(BigDecimal largest, BigDecimal least) shrunkenIntegrals(BigDecimal largest, BigDecimal least) protected abstract Function<T,BigDecimal> widen()Methods inherited from class com.pholser.junit.quickcheck.generator.Generator
addComponentGenerators, canGenerateForParametersOfTypes, canRegisterAsType, canShrink, compatibleWithTypeParameter, configurationAnnotationsOn, configure, configure, copy, gen, gen, hasComponents, magnitude, narrow, numberOfNeededComponents, provide, shrink, types
-
Constructor Details
-
DecimalGenerator
-
DecimalGenerator
-
-
Method Details
-
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 Number>- Parameters:
random- source of randomness to use in shrinking, if desiredlargestGeneric- 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.
-
shrunkenIntegrals
-
shrunkenDecimals
-
decimalsFrom
-
widen
- Returns:
- a function converting a value of the base type into a
BigDecimal
-
narrow
- Returns:
- a function converting a
BigDecimalinto the equivalent value in the base type
-
inRange
- Returns:
- a predicate checking whether its input is in the configured range
-
leastMagnitude
- 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
- Returns:
- whether the given number is negative or not
-
negate
Used when shrinking negative numbers to add the positive equivalent value at the top of shrinks list.- Parameters:
target- always a negative number- Returns:
- the positive equivalent to target
-