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
All Implemented Interfaces:
Gen<T>, Shrink<T>
Direct Known Subclasses:
BigDecimalGenerator, DoubleGenerator, FloatGenerator

public abstract class DecimalGenerator<T extends Number> extends Generator<T>
Base class for generators of decimal types, such as double and BigDecimal. All numbers are converted to/from BigDecimal for processing.
  • Constructor Details

    • DecimalGenerator

      protected DecimalGenerator(Class<T> type)
    • DecimalGenerator

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

    • doShrink

      public List<T> doShrink(SourceOfRandomness random, T largestGeneric)
      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
      largestGeneric - 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

      private List<T> shrunkenIntegrals(BigDecimal largest, BigDecimal least)
    • shrunkenDecimals

      private List<T> shrunkenDecimals(BigDecimal largest, BigDecimal least)
    • decimalsFrom

      private List<T> decimalsFrom(Stream<BigDecimal> stream)
    • widen

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

      protected abstract Function<BigDecimal,T> narrow()
      Returns:
      a function converting a BigDecimal 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