leancheck-0.9.0: Enumerative property-based testing

Copyright(c) 2015-2018 Rudy Matela
License3-Clause BSD (see the file LICENSE)
MaintainerRudy Matela <rudy@matela.com.br>
Safe HaskellNone
LanguageHaskell2010

Test.LeanCheck.Derive

Description

This module is part of LeanCheck, a simple enumerative property-based testing library.

Needs GHC and Template Haskell (tested on GHC 7.4, 7.6, 7.8, 7.10, 8.0, 8.2 and 8.4).

If LeanCheck does not compile under later GHCs, this module is probably the culprit.

If you rather do this through GHC Generics, please see: Test.LeanCheck.Generic (experimental).

Synopsis

Documentation

deriveListable :: Name -> DecsQ Source #

Derives a Listable instance for a given type Name.

Consider the following Stack datatype:

data Stack a = Stack a (Stack a) | Empty

Writing

deriveListable ''Stack

will automatically derive the following Listable instance:

instance Listable a => Listable (Stack a) where
  tiers = cons2 Stack \/ cons0 Empty

Warning: if the values in your type need to follow a data invariant, the derived instance won't respect it. Use this only on "free" datatypes.

Needs the TemplateHaskell extension.

deriveListableIfNeeded :: Name -> DecsQ Source #

Same as deriveListable but does not warn when the requested instance already exists. The function deriveListable is preferable in most situations.

deriveListableCascading :: Name -> DecsQ Source #

Derives a Listable instance for a given type Name cascading derivation of type arguments as well.

Consider the following series of datatypes:

data Position = CEO | Manager | Programmer

data Person = Person
            { name :: String
            , age :: Int
            , position :: Position
            }

data Company = Company
             { name :: String
             , employees :: [Person]
             }

Writing

deriveListableCascading ''Company

will automatically derive the following three Listable instances:

instance Listable Position where
  tiers = cons0 CEO \/ cons0 Manager \/ cons0 Programmer

instance Listable Person where
  tiers = cons3 Person

instance Listable Company where
  tiers = cons2 Company

deriveTiers :: Name -> ExpQ Source #

Given a type Name, derives an expression to be placed as the result of tiers:

consN C1 \/ consN C2 \/ ... \/ consN CN

This function can be used in the definition of Listable instances:

instance Listable MyType where
  tiers = $(deriveTiers)

deriveList :: Name -> ExpQ Source #

Given a type Name, derives an expression to be placed as the result of list:

concat $ consN C1 \/ consN C2 \/ ... \/ consN CN