Class IntegralGenerator<T extends Number>
java.lang.Object
com.pholser.junit.quickcheck.generator.Generator<T>
com.pholser.junit.quickcheck.generator.IntegralGenerator<T>
- Type Parameters:
T- type of values this generator produces
- Direct Known Subclasses:
BigIntegerGenerator,ByteGenerator,IntegerGenerator,LongGenerator,ShortGenerator
Base class for generators of integral types, such as
int and
BigInteger. All numbers are converted to/from BigInteger for
processing.-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedIntegralGenerator(Class<T> type) protectedIntegralGenerator(List<Class<T>> types) -
Method Summary
Modifier and TypeMethodDescriptiondoShrink(SourceOfRandomness random, T larger) Gives some objects that are "smaller" than a given "larger" object.inRange()protected abstract Tprotected abstract Function<BigInteger,T> narrow()protected abstract TUsed when shrinking negative numbers to add the positive equivalent value at the top of shrinks list.protected abstract booleanprotected Function<T,BigInteger> 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
-
IntegralGenerator
-
IntegralGenerator
-
-
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 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.
-
widen
- Returns:
- a function converting a value of the base type into a
BigInteger
-
narrow
- Returns:
- a function converting a
BigIntegerinto 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
-