testing-feat-0.4.0.3: Functional Enumeration of Algebraic Types

Safe HaskellNone
LanguageHaskell98

Test.Feat

Contents

Description

This module contains a (hopefully) manageable subset of the functionality of Feat. The rest resides only in the Test.Feat.* modules.

Synopsis

Documentation

data Enumerate a #

A functional enumeration of type t is a partition of t into finite numbered sets called Parts. Each parts contains values of a certain cost (typically the size of the value).

Instances

Functor Enumerate #

Only use fmap with bijective functions (e.g. data constructors)

Methods

fmap :: (a -> b) -> Enumerate a -> Enumerate b #

(<$) :: a -> Enumerate b -> Enumerate a #

Applicative Enumerate #

Pure is singleton and <*> corresponds to cartesian product (as with lists)

Methods

pure :: a -> Enumerate a #

(<*>) :: Enumerate (a -> b) -> Enumerate a -> Enumerate b #

(*>) :: Enumerate a -> Enumerate b -> Enumerate b #

(<*) :: Enumerate a -> Enumerate b -> Enumerate a #

Monoid (Enumerate a) #

The mappend is (disjoint) union

The type class

class Typeable a => Enumerable a where #

A class of functionally enumerable types

Minimal complete definition

enumerate

Methods

enumerate :: Enumerate a #

This is the interface for defining an instance. When combining enumerations use shared instead and when accessing the data of enumerations use optimal.

Instances

Enumerable Bool # 
Enumerable Char #

Contains only ASCII characters

Enumerable Double #

Not injective

Enumerable Float #

Not injective

Enumerable Int # 
Enumerable Int8 # 
Enumerable Int16 # 
Enumerable Int32 # 
Enumerable Int64 # 
Enumerable Integer # 
Enumerable Ordering # 
Enumerable Word # 
Enumerable Word8 # 
Enumerable Word16 # 
Enumerable Word32 # 
Enumerable Word64 # 
Enumerable () # 

Methods

enumerate :: Enumerate () #

Enumerable Printable # 
Enumerable Unicode # 
Enumerable a_12 => Enumerable [a_12] # 

Methods

enumerate :: Enumerate [a_12] #

Enumerable a_a1aW => Enumerable (Maybe a_a1aW) # 

Methods

enumerate :: Enumerate (Maybe a_a1aW) #

(Infinite a, Enumerable a) => Enumerable (Ratio a) #

Not injective

Methods

enumerate :: Enumerate (Ratio a) #

(Infinite a, Enumerable a) => Enumerable (NonZero a) # 
Infinite a => Enumerable (Nat a) # 

Methods

enumerate :: Enumerate (Nat a) #

Enumerable a => Enumerable (NonEmpty a) # 
(Enumerable a_acKx, Enumerable b_acKy) => Enumerable (Either a_acKx b_acKy) # 

Methods

enumerate :: Enumerate (Either a_acKx b_acKy) #

(Enumerable a_12, Enumerable b_13) => Enumerable (a_12, b_13) # 

Methods

enumerate :: Enumerate (a_12, b_13) #

(Enumerable a, Enumerable b) => Enumerable (FreePair a b) # 

Methods

enumerate :: Enumerate (FreePair a b) #

(Enumerable a_12, Enumerable b_13, Enumerable c_14) => Enumerable (a_12, b_13, c_14) # 

Methods

enumerate :: Enumerate (a_12, b_13, c_14) #

(Enumerable a_12, Enumerable b_13, Enumerable c_14, Enumerable d_15) => Enumerable (a_12, b_13, c_14, d_15) # 

Methods

enumerate :: Enumerate (a_12, b_13, c_14, d_15) #

(Enumerable a_12, Enumerable b_13, Enumerable c_14, Enumerable d_15, Enumerable e_16) => Enumerable (a_12, b_13, c_14, d_15, e_16) # 

Methods

enumerate :: Enumerate (a_12, b_13, c_14, d_15, e_16) #

(Enumerable a_12, Enumerable b_13, Enumerable c_14, Enumerable d_15, Enumerable e_16, Enumerable f_17) => Enumerable (a_12, b_13, c_14, d_15, e_16, f_17) # 

Methods

enumerate :: Enumerate (a_12, b_13, c_14, d_15, e_16, f_17) #

(Enumerable a_12, Enumerable b_13, Enumerable c_14, Enumerable d_15, Enumerable e_16, Enumerable f_17, Enumerable g_18) => Enumerable (a_12, b_13, c_14, d_15, e_16, f_17, g_18) # 

Methods

enumerate :: Enumerate (a_12, b_13, c_14, d_15, e_16, f_17, g_18) #

shared :: Enumerable a => Enumerate a #

Version of enumerate that ensures that the enumeration is shared between all accesses. Should always be used when combining enumerations.

nullary :: a -> Constructor a #

For nullary constructors such as True and [].

unary :: Enumerable a => (a -> b) -> Constructor b #

For any non-nullary constructor. Apply funcurry until the type of the result is unary (i.e. n-1 times where n is the number of fields of the constructor).

newtype FreePair a b #

A free pair constructor. The cost of constructing a free pair is equal to the sum of the costs of its components.

Constructors

Free 

Fields

Instances

(Show b, Show a) => Show (FreePair a b) # 

Methods

showsPrec :: Int -> FreePair a b -> ShowS #

show :: FreePair a b -> String #

showList :: [FreePair a b] -> ShowS #

(Enumerable a, Enumerable b) => Enumerable (FreePair a b) # 

Methods

enumerate :: Enumerate (FreePair a b) #

funcurry :: (a -> b -> c) -> FreePair a b -> c #

Uncurry a function (typically a constructor) to a function on free pairs.

consts :: [Constructor a] -> Enumerate a #

Produces the enumeration of a type given the enumerators for each of its constructors. The result of unary should typically not be used directly in an instance even if it only has one constructor. So you should apply consts even in that case.

Automatic derivation

deriveEnumerable :: Name -> Q [Dec] #

Derive an instance of Enumberable with Template Haskell. To derive an instance for Enumerable A, just put this as a top level declaration in your module (with the TemplateHaskell extension enabled):

  deriveEnumerable ''A

Accessing data

optimal :: Enumerable a => Enumerate a #

An optimal version of enumerate. Used by all library functions that access enumerated values (but not by combining functions). Library functions should ensure that optimal is not reevaluated.

index :: Enumerable a => Integer -> a #

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 -> a #

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])] #

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

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

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.

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

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

Testing drivers

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

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

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

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 () #

Defined as ioAll p = ioFeat (take p values)

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

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

type Report a = a -> IO () #

Functions that test a property and reports the result.

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

Reports counterexamples to the given predicate by printing them