Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Test.Falsify.Range
Description
Numerical ranges
Synopsis
- data Range a
- between :: forall a. (Integral a, FiniteBits a) => (a, a) -> Range a
- withOrigin :: (Integral a, FiniteBits a) => (a, a) -> a -> Range a
- skewedBy :: forall a. (FiniteBits a, Integral a) => Double -> (a, a) -> Range a
- origin :: Range a -> a
- data ProperFraction where
- pattern ProperFraction :: Double -> ProperFraction
- newtype Precision = Precision Word8
- constant :: a -> Range a
- fromProperFraction :: Precision -> (ProperFraction -> a) -> Range a
- towards :: a -> [Range a] -> Range a
- eval :: forall f a. (Applicative f, Ord a, Num a) => (Precision -> f ProperFraction) -> Range a -> f a
Documentation
Range of values
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
Primitive constructors
data ProperFraction where Source #
Value x
such that 0 <= x < 1
Bundled Patterns
pattern ProperFraction :: Double -> ProperFraction |
Instances
Precision (in bits)
Instances
Enum Precision Source # | |
Defined in Test.Falsify.Internal.Range Methods succ :: Precision -> Precision # pred :: Precision -> Precision # fromEnum :: Precision -> Int # enumFrom :: Precision -> [Precision] # enumFromThen :: Precision -> Precision -> [Precision] # enumFromTo :: Precision -> Precision -> [Precision] # enumFromThenTo :: Precision -> Precision -> Precision -> [Precision] # | |
Num Precision Source # | |
Defined in Test.Falsify.Internal.Range | |
Show Precision Source # | |
Eq Precision Source # | |
Ord Precision Source # | |
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.