| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Test.Falsify.Range
Description
Numerical ranges
Intended for qualified import.
import Test.Falsify import qualified Test.Falsify.Range as Range
Synopsis
- data Range a
- uniform :: (Integral a, FiniteBits a, Bounded a) => Range a
- inclusive :: (Integral a, FiniteBits a) => (a, a) -> Range a
- enum :: Enum a => (a, a) -> Range a
- withOrigin :: (Integral a, FiniteBits a) => (a, a) -> a -> Range a
- skewedBy :: (FiniteBits a, Integral a) => Double -> (a, a) -> Range a
- origin :: Range a -> a
- constant :: a -> Range a
- fromProperFraction :: Precision -> (ProperFraction -> a) -> Range a
- towards :: (Ord a, Num a) => a -> [Range a] -> Range a
- eval :: Applicative f => (Precision -> f WordN) -> Range a -> f a
Documentation
Range of values
Constructors
Linear
inclusive :: (Integral a, FiniteBits a) => (a, a) -> Range a Source #
Uniform selection inclusive the given bounds, shrinking towards first bound
NOTE: There is no requirement that the first bound is lower than the
second; indeed, uniform (0, -1) and uniform (-1, 0) are different
ranges: the former shrinks towards 0, the latter towards -1.
See also uniform.
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 :: (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
Primitive constructors
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 :: (Ord a, Num a) => 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.