fake-0.1.1: Randomly generated fake data

Safe HaskellSafe
LanguageHaskell2010

Fake.Cover

Description

Generate fake values with full constructor coverage

The idea behind Fake.Cover is that although exhaustive testing is highly exponential, you can cover a large portion of the likely problem cases by exercising all the constructors of a data type and associated fields. This approach only requires a sub-exponential number of cases--far fewer than what you need for the exhaustive approach. The number of test cases needed to ensure that you have full coverage of all the constructors is given by the following relations for product and sum types:

numCases (a, b) = max (numCases a) (numCases b)

numCases (Either a b) = numCases a + numCases b

See the test suite for examples of how many values are generated for different data types.

Synopsis

Documentation

gcover :: (Generic a, GCover ga, ga ~ Rep a) => Coverage a Source #

A generic function that gives you full constructor coverage for a data type. Using this function as the Cover instance for a data type avoids the need to explicitly enumerate values that include coverage of all constructors.

newtype Coverage a Source #

Coverage is a list of values, implemented here with a newtype around a list of fake value generators. It's [FGen a] instead of FGen [a] because we don't want to have to evaluate the FGen monad to work with coverage lists.

Constructors

Coverage 

Fields

Instances

Functor Coverage Source # 

Methods

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

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

Applicative Coverage Source # 

Methods

pure :: a -> Coverage a #

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

liftA2 :: (a -> b -> c) -> Coverage a -> Coverage b -> Coverage c #

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

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

Alternative Coverage Source # 

Methods

empty :: Coverage a #

(<|>) :: Coverage a -> Coverage a -> Coverage a #

some :: Coverage a -> Coverage [a] #

many :: Coverage a -> Coverage [a] #

class Cover a where Source #

A type class that generates a list of values giving full construcor coverage for data types. You can write your own instances by hand or you can use the default instance which calls gcover provided your data type has a Generic instance.

Methods

cover :: Coverage a Source #

cover :: (Generic a, GCover ga, ga ~ Rep a) => Coverage a Source #

Instances

Cover () Source # 

Methods

cover :: Coverage () Source #

Cover a => Cover (Maybe a) Source # 

Methods

cover :: Coverage (Maybe a) Source #

(Cover a, Cover b) => Cover (Either a b) Source # 

Methods

cover :: Coverage (Either a b) Source #

(Cover a, Cover b) => Cover (a, b) Source # 

Methods

cover :: Coverage (a, b) Source #

(Cover a, Cover b, Cover c) => Cover (a, b, c) Source # 

Methods

cover :: Coverage (a, b, c) Source #

(Cover a, Cover b, Cover c, Cover d) => Cover (a, b, c, d) Source # 

Methods

cover :: Coverage (a, b, c, d) Source #

(Cover a, Cover b, Cover c, Cover d, Cover e) => Cover (a, b, c, d, e) Source # 

Methods

cover :: Coverage (a, b, c, d, e) Source #

(Cover a, Cover b, Cover c, Cover d, Cover e, Cover f) => Cover (a, b, c, d, e, f) Source # 

Methods

cover :: Coverage (a, b, c, d, e, f) Source #

(Cover a, Cover b, Cover c, Cover d, Cover e, Cover f, Cover g) => Cover (a, b, c, d, e, f, g) Source # 

Methods

cover :: Coverage (a, b, c, d, e, f, g) Source #