falsify-0.1.1: Property-based testing with internal integrated shrinking

Test.Falsify.Range

Description

Numerical ranges

Synopsis

# Documentation

data Range a Source #

Range of values

#### Instances

Instances details
 Source # Instance detailsDefined in Test.Falsify.Internal.Range Methodsfmap :: (a -> b) -> Range a -> Range b #(<\$) :: a -> Range b -> Range a #

# Constructors

## Linear

between :: forall a. (Integral a, FiniteBits a) => (a, a) -> Range a Source #

Uniform selection between the given bounds, shrinking towards first bound

withOrigin :: (Integral a, FiniteBits a) => (a, a) -> a -> Range a Source #

Selection within the given bounds, shrinking towards the specified origin

All else being equal, prefers values in the second half of the range (in the common case of say withOrigin (-100, 100) 0, this means we prefer positive values).

## Non-linear

skewedBy :: forall a. (FiniteBits a, Integral a) => Double -> (a, a) -> Range a Source #

Introduce skew (non-uniform selection)

A skew of s == 0 means no skew: uniform selection.

A positive skew (s > 0) introduces a bias towards smaller values (this is the typical use case). As example, for a skew of s == 1:

• We will generate a value from the lower 20% of the range 60% of the time.
• We will generate a value from the upper 60% of the range 20% of the time.

A negative skew (s < 0) introduces a bias towards larger values. For a skew of s == 1:

• We will generate a value from the upper 20% of the range 60% of the time.
• We will generate a value from the lower 60% of the range 20% of the time.

The table below lists values for the percentage of the range used, given a percentage of the time (a value of 0 means a single value from the range):

   | time%
s | 50% | 90%
--------------
0 |  50 |  90
1 |  13 |  56
2 |   4 |  35
3 |   1 |  23
4 |   0 |  16
5 |   0 |  11
6 |   0 |   8
7 |   0 |   6
8 |   0 |   5
9 |   0 |   4
10 |   0 |   3

Will shrink towards x, independent of skew.

NOTE: The implementation currently uses something similar to μ-law encoding. As a consequence, the generator gets increased precision near the end of the range we skew towards, and less precision near the other end. This means that not all values in the range can be produced.

# Queries

origin :: Range a -> a Source #

Origin of the range (value we shrink towards)

# Primitive constructors

data ProperFraction where Source #

Value x such that 0 <= x < 1

Bundled Patterns

 pattern ProperFraction :: Double -> ProperFraction

#### Instances

Instances details
 Source # Instance detailsDefined in Test.Falsify.Internal.Range Methods Source # Instance detailsDefined in Test.Falsify.Internal.Range Methods Source # Show instance relies on the ProperFraction pattern synonym Instance detailsDefined in Test.Falsify.Internal.Range MethodsshowList :: [ProperFraction] -> ShowS # Source # Instance detailsDefined in Test.Falsify.Internal.Range Methods Source # Instance detailsDefined in Test.Falsify.Internal.Range Methods

newtype Precision Source #

Precision (in bits)

Constructors

 Precision Word8

#### Instances

Instances details
 Source # Instance detailsDefined in Test.Falsify.Internal.Range MethodsenumFrom :: Precision -> [Precision] # Source # Instance detailsDefined in Test.Falsify.Internal.Range Methods Source # Instance detailsDefined in Test.Falsify.Internal.Range MethodsshowList :: [Precision] -> ShowS # Source # Instance detailsDefined in Test.Falsify.Internal.Range Methods Source # Instance detailsDefined in Test.Falsify.Internal.Range Methods

constant :: a -> Range a Source #

Range that is x everywhere

fromProperFraction :: Precision -> (ProperFraction -> a) -> Range a Source #

Construct a given a fraction

Precondition: f must be monotonically increasing or decreasing; i.e.

• for all x <= y, f x <= f y, or
• for all x <= y, f y <= f x

towards :: a -> [Range a] -> Range a Source #

Generate value in any of the specified ranges, then choose the one that is closest to the specified origin

Precondition: the target must be within the bounds of all ranges.

# Evalation

eval :: forall f a. (Applicative f, Ord a, Num a) => (Precision -> f ProperFraction) -> Range a -> f a Source #

Evaluate a range, given an action to generate fractions

Most users will probably never need to call this function.