leancheck-0.3.0: Cholesterol-free property-based testing

Safe HaskellSafe
LanguageHaskell2010

Test.Check.Utils

Contents

Description

Utilities functions for manipulating tiers (sized lists of lists)

Synopsis

Additional tiers constructors

consFromList :: Listable a => ([a] -> b) -> [[b]] Source

Given a constructor for a type that takes a list, return tiers for that type.

consFromAscendingList :: Listable a => ([a] -> b) -> [[b]] Source

consFromStrictlyAscendingList :: Listable a => ([a] -> b) -> [[b]] Source

Given a constructor for a type that takes a list with strictly ascending elements, return tiers of that type (e.g.: a Set type).

consFromSet :: Listable a => ([a] -> b) -> [[b]] Source

Given a constructor for a type that takes a set of elements (as a list) return tiers of that type (e.g.: a Set type).

consFromNoDupList :: Listable a => ([a] -> b) -> [[b]] Source

Given a constructor for a type that takes a list with no duplicate elements, return tiers of that type.

Products of tiers

product3With :: (a -> b -> c -> d) -> [[a]] -> [[b]] -> [[c]] -> [[d]] Source

Like product, but over 3 lists of tiers.

productMaybeWith :: (a -> b -> Maybe c) -> [[a]] -> [[b]] -> [[c]] Source

Take the product of lists of tiers by a function returning a maybe value.

Tiers of lists

listsOf :: [[a]] -> [[[a]]] Source

Given tiers of values, returns tiers of lists of those values

listsOf [[]] == [[[]]]
listsOf [[x]] == [ [[]]
                 , [[x]]
                 , [[x,x]]
                 , [[x,x,x]]
                 , ...
                 ]
listsOf [[x],[y]] == [ [[]]
                     , [[x]]
                     , [[x,x],[y]]
                     , [[x,x,x],[x,y],[y,x]]
                     , ...
                     ]

ascendingListsOf :: [[a]] -> [[[a]]] Source

Given tiers of values, returns tiers of lists of elements in ascending order (from tiered enumeration).

strictlyAscendingListsOf :: [[a]] -> [[[a]]] Source

Given tiers of values, returns tiers of lists of elements in strictly ascending order (from tiered enumeration). If you only care about whether elements are in returned lists, this returns the tiers of all sets of values.

strictlyAscendingListsOf [[0],[1],[2],...] ==
  [ [[]]
  , [[0]]
  , [[1]]
  , [[0,1],[2]]
  , [[0,2],[3]]
  , [[0,3],[1,2],[4]]
  , [[0,1,2],[0,4],[1,3],[5]]
  , ...
  ]

setsOf :: [[a]] -> [[[a]]] Source

Returns tiers of sets represented as lists of values (no repeated sets). Shorthand for strictlyAscendingListsOf.

noDupListsOf :: [[a]] -> [[[a]]] Source

Given tiers of values, returns tiers of lists with no repeated elements.

noDupListsOf [[0],[1],[2],...] ==
  [ [[]]
  , [[0]]
  , [[1]]
  , [[0,1],[1,0],[2]]
  , [[0,2],[2,0],[3]]
  , ...
  ]

products :: [[[a]]] -> [[[a]]] Source

Generates several lists of the same size.

products [ xss, yss, zss ] ==

Tiers of all lists combining elements of tiers: xss, yss and zss

listsOfLength :: Int -> [[a]] -> [[[a]]] Source

Given tiers, returns tiers of lists of a given length.

deleteT :: Eq a => a -> [[a]] -> [[a]] Source

Delete the first occurence of an element in a tier, for tiers without repetitions:

deleteT x === normalizeT . (`suchThat` (/= x))

normalizeT :: [[a]] -> [[a]] Source

Tiers of choices

choices :: [[a]] -> [[(a, [[a]])]] Source

Lists tiers of all choices of values from tiers. Choices are pairs of values and tiers excluding that value.

choices [[False,True]] == [[(False,[[True]]),(True,[[False]])]]
choices [[1],[2],[3]]
  == [ [(1,[[],[2],[3]])]
     , [(2,[[1],[],[3]])]
     , [(3,[[1],[2],[]])] ]

Each choice is sized by the extracted element.

ascendingChoices :: [[a]] -> [[(a, [[a]])]] Source

strictlyAscendingChoices :: [[a]] -> [[(a, [[a]])]] Source

Like choices, but paired tiers are always strictly ascending (in terms of enumeration).

strictlyAscendingChoices [[False,True]] == [[(False,[[True]]),(True,[[]])]]
strictlyAscendingChoices [[1],[2],[3]]
  == [ [(1,[[],[2],[3]])]
     , [(2,[[],[],[3]])]
     , [(3,[[],[],[]])]
     ]