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
All Implemented Interfaces:
Gen<T>, Shrink<T>
Direct Known Subclasses:
BigIntegerGenerator, ByteGenerator, IntegerGenerator, LongGenerator, ShortGenerator

public abstract class IntegralGenerator<T extends Number> extends Generator<T>
Base class for generators of integral types, such as int and BigInteger. All numbers are converted to/from BigInteger for processing.
  • Constructor Details

    • IntegralGenerator

      protected IntegralGenerator(Class<T> type)
    • IntegralGenerator

      protected IntegralGenerator(List<Class<T>> types)
  • Method Details

    • doShrink

      public List<T> doShrink(SourceOfRandomness random, T larger)
      Description copied from class: Generator

      Gives some objects that are "smaller" than a given "larger" object.

      Unless overridden, a generator will produce an empty list of "smaller" values.

      Overrides:
      doShrink in class Generator<T extends Number>
      Parameters:
      random - source of randomness to use in shrinking, if desired
      larger - 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

      protected Function<T,BigInteger> widen()
      Returns:
      a function converting a value of the base type into a BigInteger
    • narrow

      protected abstract Function<BigInteger,T> narrow()
      Returns:
      a function converting a BigInteger into the equivalent value in the base type
    • inRange

      protected abstract Predicate<T> inRange()
      Returns:
      a predicate checking whether its input is in the configured range
    • leastMagnitude

      protected abstract T 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

      protected abstract boolean negative(T target)
      Returns:
      whether the given number is negative or not
    • negate

      protected abstract T negate(T target)
      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