testing-feat-0.4.0.2: Functional Enumeration of Algebraic Types

Test.Feat.Access

Description

Functions for accessing the values of enumerations including compatibility with the property based testing frameworks QuickCheck and SmallCheck.

Synopsis

## Accessing functions

index :: Enumerable a => Integer -> aSource

Mainly as a proof of concept we define a function to index into an enumeration. (If this is repeated multiple times it might be very inefficient, depending on whether the dictionary for the Enumerable is shared or not.)

select :: Enumerable a => Int -> Index -> aSource

A more fine grained version of index that takes a size and an index into the values of that size. `select p i` is only defined for `i`

values :: Enumerable a => [(Integer, [a])]Source

All values of the enumeration by increasing cost (which is the number of constructors for most types). Also contains the cardinality of each list.

striped :: Enumerable a => Index -> Integer -> [(Integer, [a])]Source

A generalisation of `values` that enumerates every nth value of the enumeration from a given starting point. As a special case `values = striped 0 1`.

Useful for running enumerations in parallel since e.g. `striped 0 2` is disjoint from `striped 0 1 2` and the union of the two cover all values.

bounded :: Enumerable a => Integer -> [(Integer, [a])]Source

A version of values with a limited number of values in each inner list. If the list corresponds to a Part which is larger than the bound it evenly distributes the values across the enumeration of the Part.

## A simple property tester

featCheck :: (Enumerable a, Show a) => Int -> (a -> Bool) -> IO ()Source

Check a property for all values up to a given size. ` featCheck p prop = ioAll p (inputRep prop) `

ioFeat :: [(Integer, [a])] -> Report a -> IO ()Source

A rather simple but general property testing driver. The property is an (funcurried) IO function that both tests and reports the error. The driver goes on forever or until the list is exhausted, reporting its progress and the number of tests before each new part.

ioAll :: Enumerable a => Int -> Report a -> IO ()Source

Defined as `ioAll p = ioFeat (take p values) `

ioBounded :: Enumerable a => Integer -> Int -> Report a -> IO ()Source

Defined as `ioBounded n p = ioFeat (take p \$ bounded n)`

type Report a = a -> IO ()Source

Functions that test a property and reports the result.

inputRep :: Show a => (a -> Bool) -> Report aSource

Reports counterexamples to the given predicate by printing them

prePostRep :: (Show a, Show b) => (a -> b) -> (a -> b -> Bool) -> Report aSource

Takes a function and a predicate on its input/output pairs. Reports counterexamples by printing the failing input/output pair.

## Compatibility

### QuickCheck

uniform :: Enumerable a => Int -> Gen aSource

Compatibility with QuickCheck. Distribution is uniform generator over values bounded by the given size. Typical use: `sized uniform`.

### SmallCheck

toSeries :: Enumerable a => Int -> [a]Source

Compatibility with SmallCheck.

## Non-class versions of the access functions

indexWith :: Enumerate a -> Integer -> aSource

Non class version of `index`.

selectWith :: Enumerate a -> Int -> Index -> aSource

Non class version of `select`

valuesWith :: Enumerate a -> [(Integer, [a])]Source

Non class version of `values`.

stripedWith :: Enumerate a -> Index -> Integer -> [(Integer, [a])]Source

Non class version of `striped`.

boundedWith :: Enumerate a -> Integer -> [(Integer, [a])]Source

Non class version of `bounded`.

uniformWith :: Enumerate a -> Int -> Gen aSource

Non class version of `uniform`.

toSeriesWith :: Enumerate a -> Int -> [a]Source

Non class version of `toSeries`.