Class DoubleGenerator

All Implemented Interfaces:
Gen<Double>, Shrink<Double>

public class DoubleGenerator extends DecimalGenerator<Double>
Produces values for property parameters of type double or Double.
  • Field Details

    • min

      private double min
    • max

      private double max
  • Constructor Details

    • DoubleGenerator

      public DoubleGenerator()
  • Method Details

    • configure

      public void configure(InRange range)
      Tells this generator to produce values within a specified minimum (inclusive) and/or maximum (exclusive) with uniform distribution. InRange.min() and InRange.max() take precedence over InRange.minDouble() and InRange.maxDouble(), if non-empty.
      Parameters:
      range - annotation that gives the range's constraints
    • generate

      public Double generate(SourceOfRandomness random, GenerationStatus status)
      Description copied from interface: Gen
      Generates 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 value
      status - an object that can be used to influence the generated value. For example, generating lists can use the size method to generate lists with a given number of elements.
      Returns:
      the generated value
    • widen

      protected Function<Double,BigDecimal> widen()
      Specified by:
      widen in class DecimalGenerator<Double>
      Returns:
      a function converting a value of the base type into a BigDecimal
    • narrow

      protected Function<BigDecimal,Double> narrow()
      Specified by:
      narrow in class DecimalGenerator<Double>
      Returns:
      a function converting a BigDecimal into the equivalent value in the base type
    • inRange

      protected Predicate<Double> inRange()
      Specified by:
      inRange in class DecimalGenerator<Double>
      Returns:
      a predicate checking whether its input is in the configured range
    • leastMagnitude

      protected Double leastMagnitude()
      Specified by:
      leastMagnitude in class DecimalGenerator<Double>
      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 boolean negative(Double target)
      Specified by:
      negative in class DecimalGenerator<Double>
      Returns:
      whether the given number is negative or not
    • negate

      protected Double negate(Double target)
      Description copied from class: DecimalGenerator
      Used when shrinking negative numbers to add the positive equivalent value at the top of shrinks list.
      Specified by:
      negate in class DecimalGenerator<Double>
      Parameters:
      target - always a negative number
      Returns:
      the positive equivalent to target
    • magnitude

      public BigDecimal magnitude(Object value)
      Description copied from class: Generator

      Gives 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:
      magnitude in class Generator<Double>
      Parameters:
      value - the value to assess
      Returns:
      a measure of the given value's magnitude
      See Also: