extrapolate-0.3.0: generalize counter-examples of test properties

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

Test.Extrapolate.Core

Description

This module is part of Extrapolate, a library for generalization of counter-examples.

This is the core of extrapolate.

Synopsis

Documentation

class (Listable a, Typeable a, Show a) => Generalizable a where Source #

Extrapolate can generalize counter-examples of any types that are Generalizable.

The core (and only required functions) of the generalizable typeclass are the expr and instances functions.

The following example shows a datatype and its instance:

data Stack a = Stack a (Stack a) | Empty
instance Generalizable a => Generalizable (Stack a) where
name _ = "s"
expr s@(Stack x y) = constant "Stack" (Stack ->>: s) :$ expr x :$ expr y
expr s@Empty       = constant "Empty" (Empty   -: s)
instances s = this s $ instances (argTy1of1 s)

To declare instances and expr it may be useful to use:

Minimal complete definition

expr, instances

Methods

expr :: a -> Expr Source #

Transforms a value into an manipulable expression tree. See constant and :$.

name :: a -> String Source #

Common name for a variable, defaults to "x".

background :: a -> [Expr] Source #

List of symbols allowed to appear in side-conditions. Defaults to []. See constant.

instances :: a -> Instances -> Instances Source #

Computes a list of reified instances. See this.

Instances

Generalizable Bool Source # 
Generalizable Char Source # 
Generalizable Int Source # 
Generalizable Integer Source # 
Generalizable Ordering Source # 
Generalizable () Source # 

Methods

expr :: () -> Expr Source #

name :: () -> String Source #

background :: () -> [Expr] Source #

instances :: () -> Instances -> Instances Source #

Generalizable a => Generalizable [a] Source # 

Methods

expr :: [a] -> Expr Source #

name :: [a] -> String Source #

background :: [a] -> [Expr] Source #

instances :: [a] -> Instances -> Instances Source #

Generalizable a => Generalizable (Maybe a) Source # 
(Generalizable a, Generalizable b) => Generalizable (Either a b) Source # 
(Generalizable a, Generalizable b) => Generalizable (a, b) Source # 

Methods

expr :: (a, b) -> Expr Source #

name :: (a, b) -> String Source #

background :: (a, b) -> [Expr] Source #

instances :: (a, b) -> Instances -> Instances Source #

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

Methods

expr :: (a, b, c) -> Expr Source #

name :: (a, b, c) -> String Source #

background :: (a, b, c) -> [Expr] Source #

instances :: (a, b, c) -> Instances -> Instances Source #

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

Methods

expr :: (a, b, c, d) -> Expr Source #

name :: (a, b, c, d) -> String Source #

background :: (a, b, c, d) -> [Expr] Source #

instances :: (a, b, c, d) -> Instances -> Instances Source #

(+++) :: Ord a => [a] -> [a] -> [a] infixr 5 Source #

bgEq :: (Eq a, Generalizable a) => a -> [Expr] Source #

bgOrd :: (Ord a, Generalizable a) => a -> [Expr] Source #

bgEqWith1 :: (Generalizable a, Generalizable b) => ((b -> b -> Bool) -> a -> a -> Bool) -> [Expr] Source #

bgEqWith2 :: (Generalizable a, Generalizable b, Generalizable c) => ((b -> b -> Bool) -> (c -> c -> Bool) -> a -> a -> Bool) -> [Expr] Source #

data WithOption a Source #

Constructors

With 

Fields

(*==*) :: Generalizable a => a -> a -> Bool Source #

(*/=*) :: Generalizable a => a -> a -> Bool Source #

(*<=*) :: Generalizable a => a -> a -> Bool Source #

(*<*) :: Generalizable a => a -> a -> Bool Source #

counterExamples :: Testable a => Int -> a -> [[Expr]] Source #

generalizationsCE :: Testable a => Int -> a -> [Expr] -> [[Expr]] Source #

generalizationsCEC :: Testable a => a -> [Expr] -> [(Expr, [Expr])] Source #

generalizationsCounts :: Testable a => Int -> a -> [Expr] -> [([Expr], Int)] Source #

atoms :: Testable a => a -> [[Expr]] Source #

candidateConditions :: Testable a => (Thy, [Expr]) -> a -> [Expr] -> [Expr] Source #

validConditions :: Testable a => (Thy, [Expr]) -> a -> [Expr] -> [(Expr, Int)] Source #

weakestCondition :: Testable a => (Thy, [Expr]) -> a -> [Expr] -> Expr Source #

matchList :: [Expr] -> [Expr] -> Maybe Binds Source #

List matches of lists of expressions if possible

[0,1]   `matchList` [x,y]   = Just [x=0, y=1]
[0,1+2] `matchList` [x,y+y] = Nothing

class Testable a where Source #

Minimal complete definition

resultiers, ($-|), tinstances

Methods

resultiers :: a -> [[([Expr], Bool)]] Source #

($-|) :: a -> [Expr] -> Bool Source #

tinstances :: a -> Instances Source #

options :: a -> Options Source #

Instances

Testable Bool Source # 

Methods

resultiers :: Bool -> [[([Expr], Bool)]] Source #

($-|) :: Bool -> [Expr] -> Bool Source #

tinstances :: Bool -> Instances Source #

options :: Bool -> Options Source #

Testable a => Testable (WithOption a) Source # 
(Testable b, Generalizable a, Listable a) => Testable (a -> b) Source # 

Methods

resultiers :: (a -> b) -> [[([Expr], Bool)]] Source #

($-|) :: (a -> b) -> [Expr] -> Bool Source #

tinstances :: (a -> b) -> Instances Source #

options :: (a -> b) -> Options Source #

results :: Testable a => a -> [([Expr], Bool)] Source #