hedgehog-1.5: Release with confidence.

Safe Haskell | None
Language | Haskell2010

Hedgehog.Range

Contents

- Size
- Range
- Constant
- Linear
- Exponential

Synopsis

- newtype Size = Size {
  - unSize :: Int
  }
- data Range a
- origin :: Range a -> a
- bounds :: Size -> Range a -> (a, a)
- lowerBound :: Ord a => Size -> Range a -> a
- upperBound :: Ord a => Size -> Range a -> a
- singleton :: a -> Range a
- constant :: a -> a -> Range a
- constantFrom :: a -> a -> a -> Range a
- constantBounded :: (Bounded a, Num a) => Range a
- linear :: Integral a => a -> a -> Range a
- linearFrom :: Integral a => a -> a -> a -> Range a
- linearFrac :: (Fractional a, Ord a) => a -> a -> Range a
- linearFracFrom :: (Fractional a, Ord a) => a -> a -> a -> Range a
- linearBounded :: (Bounded a, Integral a) => Range a
- exponential :: Integral a => a -> a -> Range a
- exponentialFrom :: Integral a => a -> a -> a -> Range a
- exponentialBounded :: (Bounded a, Integral a) => Range a
- exponentialFloat :: (Floating a, Ord a) => a -> a -> Range a
- exponentialFloatFrom :: (Floating a, Ord a) => a -> a -> a -> Range a

# Size

newtype Size Source #

Tests are parameterized by the size of the randomly-generated data. The meaning of a `Size` value depends on the particular generator used, but it must always be a number between 0 and 99 inclusive.

Constructors

Size |

Fields

- unSize :: Int

#### Instances

Instances details

Enum Size Source # |
Instance details Defined in Hedgehog.Internal.Range Methods succ :: Size -> Size Source # pred :: Size -> Size Source # toEnum :: Int -> Size Source # fromEnum :: Size -> Int Source # enumFrom :: Size -> [Size] Source # enumFromThen :: Size -> Size -> [Size] Source # enumFromTo :: Size -> Size -> [Size] Source # enumFromThenTo :: Size -> Size -> Size -> [Size] Source #
Num Size Source # |
Instance details Defined in Hedgehog.Internal.Range Methods (+) :: Size -> Size -> Size Source # (-) :: Size -> Size -> Size Source # (*) :: Size -> Size -> Size Source # negate :: Size -> Size Source # abs :: Size -> Size Source # signum :: Size -> Size Source # fromInteger :: Integer -> Size Source #
Read Size Source # |
Instance details Defined in Hedgehog.Internal.Range Methods readsPrec :: Int -> ReadS Size Source # readList :: ReadS [Size] Source # readPrec :: ReadPrec Size Source # readListPrec :: ReadPrec [Size] Source #
Integral Size Source # |
Instance details Defined in Hedgehog.Internal.Range Methods quot :: Size -> Size -> Size Source # rem :: Size -> Size -> Size Source # div :: Size -> Size -> Size Source # mod :: Size -> Size -> Size Source # quotRem :: Size -> Size -> (Size, Size) Source # divMod :: Size -> Size -> (Size, Size) Source # toInteger :: Size -> Integer Source #
Real Size Source # |
Instance details Defined in Hedgehog.Internal.Range Methods toRational :: Size -> Rational Source #
Show Size Source # |
Instance details Defined in Hedgehog.Internal.Range Methods showsPrec :: Int -> Size -> ShowS Source # show :: Size -> String Source # showList :: [Size] -> ShowS Source #
Eq Size Source # |
Instance details Defined in Hedgehog.Internal.Range Methods (==) :: Size -> Size -> Bool Source # (/=) :: Size -> Size -> Bool Source #
Ord Size Source # |
Instance details Defined in Hedgehog.Internal.Range Methods compare :: Size -> Size -> Ordering Source # (<) :: Size -> Size -> Bool Source # (<=) :: Size -> Size -> Bool Source # (>) :: Size -> Size -> Bool Source # (>=) :: Size -> Size -> Bool Source # max :: Size -> Size -> Size Source # min :: Size -> Size -> Size Source #

# Range

data Range a Source #

A range describes the bounds of a number to generate, which may or may not be dependent on a `Size`.

The constructor takes an origin between the lower and upper bound, and a function from `Size` to bounds. As the size goes towards `0`, the values go towards the origin.

#### Instances

Instances details

Functor Range Source # |
Instance details Defined in Hedgehog.Internal.Range Methods fmap :: (a -> b) -> Range a -> Range b Source # (<$) :: a -> Range b -> Range a Source #

origin :: Range a -> a Source #

Get the origin of a range. This might be the mid-point or the lower bound, depending on what the range represents.

The `bounds` of a range are scaled around this value when using the `linear` family of combinators.

When using a `Range` to generate numbers, the shrinking function will shrink towards the origin.

bounds :: Size -> Range a -> (a, a) Source #

Get the extents of a range, for a given size.

lowerBound :: Ord a => Size -> Range a -> a Source #

Get the lower bound of a range for the given size.

upperBound :: Ord a => Size -> Range a -> a Source #

Get the upper bound of a range for the given size.

# Constant

singleton :: a -> Range a Source #

Construct a range which represents a constant single value.

    >>> bounds x $ singleton 5
    (5,5)

    >>> origin $ singleton 5
    5

constant :: a -> a -> Range a Source #

Construct a range which is unaffected by the size parameter.

A range from `0` to `10`, with the origin at `0`:

    >>> bounds x $ constant 0 10
    (0,10)

    >>> origin $ constant 0 10
    0

constantFrom Source #

Arguments

:: a | Origin (the value produced when the size parameter is 0).
-> a | Lower bound (the bottom of the range when the size parameter is 99).
-> a | Upper bound (the top of the range when the size parameter is 99).
-> Range a |

Construct a range which is unaffected by the size parameter with a origin point which may differ from the bounds.

A range from `-10` to `10`, with the origin at `0`:

    >>> bounds x $ constantFrom 0 (-10) 10
    (-10,10)

    >>> origin $ constantFrom 0 (-10) 10
    0

A range from `1970` to `2100`, with the origin at `2000`:

    >>> bounds x $ constantFrom 2000 1970 2100
    (1970,2100)

    >>> origin $ constantFrom 2000 1970 2100
    2000

constantBounded :: (Bounded a, Num a) => Range a Source #

Construct a range which is unaffected by the size parameter using the full range of a data type.

A range from `-128` to `127`, with the origin at `0`:

    >>> bounds x (constantBounded :: Range Int8)
    (-128,127)

    >>> origin (constantBounded :: Range Int8)
    0

# Linear

linear :: Integral a => a -> a -> Range a Source #

Construct a range which scales the second bound relative to the size parameter.

    >>> bounds 0 $ linear 0 10
    (0,0)

    >>> bounds 50 $ linear 0 10
    (0,5)

    >>> bounds 99 $ linear 0 10
    (0,10)

linearFrom Source #

Arguments

:: Integral a |
=> a | Origin (the value produced when the size parameter is 0).
-> a | Lower bound (the bottom of the range when the size parameter is 99).
-> a | Upper bound (the top of the range when the size parameter is 99).
-> Range a |

Construct a range which scales the bounds relative to the size parameter.

    >>> bounds 0 $ linearFrom 0 (-10) 10
    (0,0)

    >>> bounds 50 $ linearFrom 0 (-10) 20
    (-5,10)

    >>> bounds 99 $ linearFrom 0 (-10) 20
    (-10,20)

linearFrac :: (Fractional a, Ord a) => a -> a -> Range a Source #

Construct a range which scales the second bound relative to the size parameter.

This works the same as `linear`, but for fractional values.

linearFracFrom :: (Fractional a, Ord a) => a -> a -> a -> Range a Source #

Construct a range which scales the bounds relative to the size parameter.

This works the same as `linearFrom`, but for fractional values.

linearBounded :: (Bounded a, Integral a) => Range a Source #

Construct a range which is scaled relative to the size parameter and uses the full range of a data type.

    >>> bounds 0 (linearBounded :: Range Int8)
    (0,0)

    >>> bounds 50 (linearBounded :: Range Int8)
    (-64,64)

    >>> bounds 99 (linearBounded :: Range Int8)
    (-128,127)

# Exponential

exponential :: Integral a => a -> a -> Range a Source #

Construct a range which scales the second bound exponentially relative to the size parameter.

    >>> bounds 0 $ exponential 1 512
    (1,1)

    >>> bounds 11 $ exponential 1 512
    (1,2)

    >>> bounds 22 $ exponential 1 512
    (1,4)

    >>> bounds 77 $ exponential 1 512
    (1,128)

    >>> bounds 88 $ exponential 1 512
    (1,256)

    >>> bounds 99 $ exponential 1 512
    (1,512)

exponentialFrom Source #

Arguments

:: Integral a |
=> a | Origin (the value produced when the size parameter is 0).
-> a | Lower bound (the bottom of the range when the size parameter is 99).
-> a | Upper bound (the top of the range when the size parameter is 99).
-> Range a |

Construct a range which scales the bounds exponentially relative to the size parameter.

    >>> bounds 0 $ exponentialFrom 0 (-128) 512
    (0,0)

    >>> bounds 25 $ exponentialFrom 0 (-128) 512
    (-2,4)

    >>> bounds 50 $ exponentialFrom 0 (-128) 512
    (-11,22)

    >>> bounds 75 $ exponentialFrom 0 (-128) 512
    (-39,112)

    >>> bounds 99 $ exponentialFrom x (-128) 512
    (-128,512)

exponentialBounded :: (Bounded a, Integral a) => Range a Source #

Construct a range which is scaled exponentially relative to the size parameter and uses the full range of a data type.

    >>> bounds 0 (exponentialBounded :: Range Int8)
    (0,0)

    >>> bounds 50 (exponentialBounded :: Range Int8)
    (-11,11)

    >>> bounds 99 (exponentialBounded :: Range Int8)
    (-128,127)

exponentialFloat :: (Floating a, Ord a) => a -> a -> Range a Source #

Construct a range which scales the second bound exponentially relative to the size parameter.

This works the same as `exponential`, but for floating-point values.

    >>> bounds 0 $ exponentialFloat 0 10
    (0.0,0.0)

    >>> bounds 50 $ exponentialFloat 0 10
    (0.0,2.357035250656098)

    >>> bounds 99 $ exponentialFloat 0 10
    (0.0,10.0)

exponentialFloatFrom :: (Floating a, Ord a) => a -> a -> a -> Range a Source #

Construct a range which scales the bounds exponentially relative to the size parameter.

This works the same as `exponentialFrom`, but for floating-point values.

    >>> bounds 0 $ exponentialFloatFrom 0 (-10) 20
    (0.0,0.0)

    >>> bounds 50 $ exponentialFloatFrom 0 (-10) 20
    (-2.357035250656098,3.6535836249197002)

    >>> bounds 99 $ exponentialFloatFrom x (-10) 20
    (-10.0,20.0)