falsify-0.4.0: Property-based testing with internal integrated shrinking
Safe HaskellNone
LanguageHaskell2010

Test.Falsify.SampleTree

Description

Sample tree

Intended for qualified import.

import Test.Falsify.SampleTree (SampleTree(..), pattern Inf, Sample(..))
import qualified Test.Falsify.SampleTree as SampleTree
Synopsis

Definition

data SampleTree Source #

Sample tree

A sample tree is a (conceptually and sometimes actually) infinite tree representing drawing values from and splitting a PRNG.

Constructors

SampleTree Sample SampleTree SampleTree

Default constructor

The type of ST is really

ST :: Word64 & (SampleTree * SampleTree) -> SampleTree

where (&) is the additive conjunction from linear logic. In other words, the intention is that either the Word64 is used, or the pair of subtrees; put another way, we either draw a value from the PRNG, or split it into two new PRNGs.

Minimal

Minimal tree (0 everywhere)

This constructor allows us to represent an infinite tree in a finite way and, importantly, recognize a tree that is minimal everywhere. This is necessary when shrinking in the context of generators that generate infinitely large values.

Instances

Instances details
Show SampleTree Source # 
Instance details

Defined in Test.Falsify.SampleTree

data Sample Source #

Sample

The samples in the SampleTree record if they were the originally produced sample, or whether they have been shrunk.

Constructors

NotShrunk Word64 
Shrunk Word64 

Instances

Instances details
Show Sample Source # 
Instance details

Defined in Test.Falsify.SampleTree

Eq Sample Source # 
Instance details

Defined in Test.Falsify.SampleTree

Methods

(==) :: Sample -> Sample -> Bool #

(/=) :: Sample -> Sample -> Bool #

Ord Sample Source # 
Instance details

Defined in Test.Falsify.SampleTree

pattern Inf :: Sample -> SampleTree -> SampleTree -> SampleTree Source #

Pattern synonym for treating the sample tree as infinite

sampleValue :: Sample -> Word64 Source #

Value of the sample

Samples differentiate between NotShrunk and Shrunk, but for most use cases this distinction does not matter.

Construction

fromPRNG :: SMGen -> SampleTree Source #

Construct SampleTree from splittable PRNG

fromSeed :: Word64 -> SampleTree Source #

Consruct SampleTree from initial seed

The seed will be used to initialize an SMGen

minimal :: SampleTree Source #

Minimal sample tree

Generators should produce the "simplest" value when given this tree, for some suitable application-specific definition of "simple".

constant :: Word64 -> SampleTree Source #

Sample tree that is the given value everywhere

This is primarily useful for debugging.

Combinators

map :: (Word64 -> Word64) -> SampleTree -> SampleTree Source #

Map function over all random samples in the tree

Precondition: the function must preserve zeros:

f 0 == 0

This means that we have

map f M == M

This is primarily useful for debugging.

mod :: Word64 -> SampleTree -> SampleTree Source #

Apply mod m at every sample in the tree

This is primarily useful for debugging.