-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | generalize counter-examples of test properties -- -- Extrapolate is a tool able to provide generalized counter-examples of -- test properties where irrelevant sub-expressions are replaces with -- variables. -- -- For the incorrect property \xs -> nub xs == (xs::[Int]): -- -- @package extrapolate @version 0.2.4 -- | This module is part of Extrapolate, a library for generalization of -- counter-examples. -- -- Miscellaneous utility functions. -- -- This is not intended to be used by users of Extrapolate, only by -- modules of Extrapolate itself. Expect symbols exported here to come -- and go with every minor version. module Test.Extrapolate.Utils (+++) :: Ord a => [a] -> [a] -> [a] infixr 5 +++ nubMerge :: Ord a => [a] -> [a] -> [a] nubMergeOn :: Ord b => (a -> b) -> [a] -> [a] -> [a] nubMergeBy :: (a -> a -> Ordering) -> [a] -> [a] -> [a] foldr0 :: (a -> a -> a) -> a -> [a] -> a fromLeft :: Either a b -> a fromRight :: Either a b -> b elemBy :: (a -> a -> Bool) -> a -> [a] -> Bool listEq :: (a -> a -> Bool) -> [a] -> [a] -> Bool listOrd :: (a -> a -> Bool) -> [a] -> [a] -> Bool maybeEq :: (a -> a -> Bool) -> Maybe a -> Maybe a -> Bool maybeOrd :: (a -> a -> Bool) -> Maybe a -> Maybe a -> Bool eitherEq :: (a -> a -> Bool) -> (b -> b -> Bool) -> Either a b -> Either a b -> Bool eitherOrd :: (a -> a -> Bool) -> (b -> b -> Bool) -> Either a b -> Either a b -> Bool (.:) :: (c -> d) -> (a -> b -> c) -> (a -> b -> d) -- | This module is part of Extrapolate, a library for generalization of -- counter-examples. -- -- Some type binding operators that are useful when defining -- Generalizable instances. module Test.Extrapolate.TypeBinding argTy1of1 :: con a -> a argTy1of2 :: con a b -> a argTy2of2 :: con a b -> b argTy1of3 :: con a b c -> a argTy2of3 :: con a b c -> b argTy3of3 :: con a b c -> c argTy1of4 :: con a b c d -> a argTy2of4 :: con a b c d -> b argTy3of4 :: con a b c d -> c argTy4of4 :: con a b c d -> d argTy1of5 :: con a b c d e -> a argTy2of5 :: con a b c d e -> b argTy3of5 :: con a b c d e -> c argTy4of5 :: con a b c d e -> d argTy5of5 :: con a b c d e -> e argTy1of6 :: con a b c d e f -> a argTy2of6 :: con a b c d e f -> b argTy3of6 :: con a b c d e f -> c argTy4of6 :: con a b c d e f -> d argTy5of6 :: con a b c d e f -> e argTy6of6 :: con a b c d e f -> f -- | This module is part of Extrapolate, a library for generalization of -- counter-examples. -- -- This module re-exports some functionality from Test.Speculate.Expr, -- but instead of working on single expressions it works in lists of -- expressions (the choosen representation for counter-examples). module Test.Extrapolate.Exprs type Exprs = [Expr] canonicalizeWith :: Instances -> [Expr] -> [Expr] grounds :: Instances -> [Expr] -> [[Expr]] groundsAndBinds :: Instances -> [Expr] -> [(Binds, [Expr])] vassignments :: [Expr] -> [[Expr]] vars :: [Expr] -> [(TypeRep, String)] fold :: [Expr] -> Expr unfold :: Expr -> [Expr] isAssignmentTest :: Instances -> Int -> Expr -> Bool nameWith :: Typeable a => String -> a -> Instances -- | This module is part of Extrapolate, a library for generalization of -- counter-examples. -- -- This is the core of extrapolate. module Test.Extrapolate.Core -- | 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: -- -- class (Listable a, Typeable a, Show a) => Generalizable a where name _ = "x" background _ = [] -- | Transforms a value into an manipulable expression tree. See -- constant and :$. expr :: Generalizable a => a -> Expr -- | Common name for a variable, defaults to "x". name :: Generalizable a => a -> String -- | List of symbols allowed to appear in side-conditions. Defaults to -- []. See constant. background :: Generalizable a => a -> [Expr] -- | Computes a list of reified instances. See this. instances :: Generalizable a => a -> Instances -> Instances this :: Generalizable a => a -> (Instances -> Instances) -> Instances -> Instances backgroundWith :: Typeable a => [Expr] -> a -> Instances (+++) :: Ord a => [a] -> [a] -> [a] infixr 5 +++ backgroundOf :: Generalizable a => a -> [Expr] bgEq :: (Eq a, Generalizable a) => a -> [Expr] bgOrd :: (Ord a, Generalizable a) => a -> [Expr] bgEqWith1 :: (Generalizable a, Generalizable b) => ((b -> b -> Bool) -> a -> a -> Bool) -> [Expr] bgEqWith2 :: (Generalizable a, Generalizable b, Generalizable c) => ((b -> b -> Bool) -> (c -> c -> Bool) -> a -> a -> Bool) -> [Expr] data Option MaxTests :: Int -> Option ExtraInstances :: Instances -> Option MaxConditionSize :: Int -> Option data WithOption a With :: a -> Option -> WithOption a [property] :: WithOption a -> a [option] :: WithOption a -> Option maxTests :: Testable a => a -> Int extraInstances :: Testable a => a -> Instances maxConditionSize :: Testable a => a -> Int hasEq :: Generalizable a => a -> Bool (*==*) :: Generalizable a => a -> a -> Bool (*/=*) :: Generalizable a => a -> a -> Bool (*<=*) :: Generalizable a => a -> a -> Bool (*<*) :: Generalizable a => a -> a -> Bool counterExamples :: Testable a => Int -> a -> [[Expr]] counterExampleGen :: Testable a => Int -> a -> Maybe ([Expr], Maybe [Expr]) counterExampleGens :: Testable a => Int -> a -> Maybe ([Expr], [[Expr]]) generalizations :: Instances -> [Expr] -> [[Expr]] generalizationsCE :: Testable a => Int -> a -> [Expr] -> [[Expr]] generalizationsCEC :: Testable a => Int -> a -> [Expr] -> [(Expr, [Expr])] generalizationsCounts :: Testable a => Int -> a -> [Expr] -> [([Expr], Int)] weakestCondition :: Testable a => Int -> a -> [Expr] -> Expr candidateConditions :: Testable a => a -> [Expr] -> [Expr] conditionalGeneralization :: Testable a => Int -> a -> [Expr] -> [Expr] -> Maybe ([Expr], [Expr]) -- | 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
--   
matchList :: [Expr] -> [Expr] -> Maybe Binds newMatches :: [Expr] -> [Expr] -> Maybe Binds class Testable a where options _ = [] resultiers :: Testable a => a -> [[([Expr], Bool)]] ($-|) :: Testable a => a -> [Expr] -> Bool tinstances :: Testable a => a -> Instances options :: Testable a => a -> Options results :: Testable a => a -> [([Expr], Bool)] areInstancesOf :: [Expr] -> [Expr] -> Bool expressionsT :: [Expr] -> [[Expr]] instance GHC.Show.Show Test.Extrapolate.Core.Option instance Test.Extrapolate.Core.Generalizable () instance Test.Extrapolate.Core.Generalizable GHC.Types.Bool instance Test.Extrapolate.Core.Generalizable GHC.Types.Int instance Test.Extrapolate.Core.Generalizable GHC.Integer.Type.Integer instance Test.Extrapolate.Core.Generalizable GHC.Types.Char instance Test.Extrapolate.Core.Generalizable a => Test.Extrapolate.Core.Generalizable (GHC.Base.Maybe a) instance (Test.Extrapolate.Core.Generalizable a, Test.Extrapolate.Core.Generalizable b) => Test.Extrapolate.Core.Generalizable (Data.Either.Either a b) instance (Test.Extrapolate.Core.Generalizable a, Test.Extrapolate.Core.Generalizable b) => Test.Extrapolate.Core.Generalizable (a, b) instance (Test.Extrapolate.Core.Generalizable a, Test.Extrapolate.Core.Generalizable b, Test.Extrapolate.Core.Generalizable c) => Test.Extrapolate.Core.Generalizable (a, b, c) instance (Test.Extrapolate.Core.Generalizable a, Test.Extrapolate.Core.Generalizable b, Test.Extrapolate.Core.Generalizable c, Test.Extrapolate.Core.Generalizable d) => Test.Extrapolate.Core.Generalizable (a, b, c, d) instance Test.Extrapolate.Core.Generalizable a => Test.Extrapolate.Core.Generalizable [a] instance Test.Extrapolate.Core.Generalizable GHC.Types.Ordering instance Test.Extrapolate.Core.Testable a => Test.Extrapolate.Core.Testable (Test.Extrapolate.Core.WithOption a) instance Test.Extrapolate.Core.Testable GHC.Types.Bool instance (Test.Extrapolate.Core.Testable b, Test.Extrapolate.Core.Generalizable a, Test.LeanCheck.Core.Listable a) => Test.Extrapolate.Core.Testable (a -> b) -- | This module is part of Extrapolate, a library for generalization of -- counter-examples. -- -- This is a module for deriving Generalizable instances. -- -- Needs GHC and Template Haskell (tested on GHC 8.0). -- -- If Extrapolate does not compile under later GHCs, this module is the -- probable culprit. module Test.Extrapolate.Derive -- | Derives a Generalizable instance for a given type Name. -- -- Consider the following Stack datatype: -- --
--   data Stack a = Stack a (Stack a) | Empty
--   
-- -- Writing -- --
--   deriveGeneralizable ''Stack
--   
-- -- will automatically derive the following Generalizable instance: -- --
--   instance Generalizable a => Generalizable (Stack a) where
--     expr s@(Stack x y) = constant "Stack" (Stack ->>: s) :$ expr x :$ expr y
--     expr s@Empty       = constant "Empty" (Empty   -: s)
--     instances s = this "s" s
--                 $ let Stack x y = Stack undefined undefined `asTypeOf` s
--                   in instances x
--                    . instances y
--   
-- -- This function needs the TemplateHaskell extension. deriveGeneralizable :: Name -> DecsQ -- | Same as deriveGeneralizable but does not warn when instance -- already exists (deriveGeneralizable is preferable). deriveGeneralizableIfNeeded :: Name -> DecsQ -- | Derives a Generalizable instance for a given type Name -- cascading derivation of type arguments as well. deriveGeneralizableCascading :: Name -> DecsQ instance GHC.Show.Show Test.Extrapolate.Derive.Bla instance GHC.Classes.Ord Test.Extrapolate.Derive.Bla instance GHC.Classes.Eq Test.Extrapolate.Derive.Bla -- | This module is part of Extrapolate, a library for generalization of -- counter-examples. -- -- QuickCheck-like interface. module Test.Extrapolate.IO -- | Checks a property printing results on stdout -- --
--   > check $ \xs -> sort (sort xs) == sort (xs::[Int])
--   +++ OK, passed 360 tests.
--   
--   > check $ \xs ys -> xs `union` ys == ys `union` (xs::[Int])
--   *** Failed! Falsifiable (after 4 tests):
--   [] [0,0]
--   
--   Generalization:
--   [] (x:x:_)
--   
check :: Testable a => a -> IO () -- | Check a property printing results on stdout and returning -- True on success. -- -- There is no option to silence this function: for silence, you should -- use holds. checkResult :: Testable a => a -> IO Bool -- | Use for to configure the number of tests performed by -- check. -- --
--   > check `for` 10080 $ \xs -> sort (sort xs) == sort (xs :: [Int])
--   +++ OK, passed 10080 tests.
--   
-- -- Don't forget the dollar ($)! for :: Testable a => (WithOption a -> b) -> Int -> a -> b -- | Allows the user to customize instance information available when -- generalized. (For advanced users.) withInstances :: Testable a => (WithOption a -> b) -> Instances -> a -> b -- | Use withBackground to provide additional functions to -- appear in side-conditions. -- --
--   check `withBackground` [constant "isSpace" isSpace] $ \xs -> unwords (words xs) == xs
--   *** Failed! Falsifiable (after 4 tests):
--   " "
--   
--   Generalization:
--   ' ':_
--   
--   Conditional Generalization:
--   c:_  when  isSpace c
--   
withBackground :: Testable a => (WithOption a -> b) -> [Expr] -> a -> b -- | Use withConditionSize to configure the maximum -- condition size allowed. withConditionSize :: Testable a => (WithOption a -> b) -> Int -> a -> b instance GHC.Show.Show Test.Extrapolate.IO.Result instance GHC.Classes.Eq Test.Extrapolate.IO.Result -- | This module is otherwise unused in the code. -- -- This is a stub of a new algorithm that is smarter and generalizes from -- several initial counter-examples rather than just one. -- -- When this gets finished, it should be moved into -- Test.Extrapolate.Core. module Test.Extrapolate.New generalizedCounterExamples :: Testable a => Int -> a -> [Exprs] lgg :: Exprs -> Exprs -> Exprs -- | Computes the least general generalization of two expressions -- --
--   lgg1 (expr [0,0]) (expr [1,1])
--   
-- -- lgg1 :: Expr -> Expr -> Expr -- | This module is part of Extrapolate, a library for generalization of -- counter-examples. -- -- This provides the basic functionality of extrapolate. You will have -- better luck importing Test.Extrapolate directly. module Test.Extrapolate.Basic instance (GHC.Real.Integral a, Test.Extrapolate.Core.Generalizable a) => Test.Extrapolate.Core.Generalizable (GHC.Real.Ratio a) instance (Test.Extrapolate.Core.Generalizable a, Test.Extrapolate.Core.Generalizable b, Test.Extrapolate.Core.Generalizable c, Test.Extrapolate.Core.Generalizable d, Test.Extrapolate.Core.Generalizable e) => Test.Extrapolate.Core.Generalizable (a, b, c, d, e) instance (Test.Extrapolate.Core.Generalizable a, Test.Extrapolate.Core.Generalizable b, Test.Extrapolate.Core.Generalizable c, Test.Extrapolate.Core.Generalizable d, Test.Extrapolate.Core.Generalizable e, Test.Extrapolate.Core.Generalizable f) => Test.Extrapolate.Core.Generalizable (a, b, c, d, e, f) instance (Test.Extrapolate.Core.Generalizable a, Test.Extrapolate.Core.Generalizable b, Test.Extrapolate.Core.Generalizable c, Test.Extrapolate.Core.Generalizable d, Test.Extrapolate.Core.Generalizable e, Test.Extrapolate.Core.Generalizable f, Test.Extrapolate.Core.Generalizable g) => Test.Extrapolate.Core.Generalizable (a, b, c, d, e, f, g) instance (Test.Extrapolate.Core.Generalizable a, Test.Extrapolate.Core.Generalizable b, Test.Extrapolate.Core.Generalizable c, Test.Extrapolate.Core.Generalizable d, Test.Extrapolate.Core.Generalizable e, Test.Extrapolate.Core.Generalizable f, Test.Extrapolate.Core.Generalizable g, Test.Extrapolate.Core.Generalizable h) => Test.Extrapolate.Core.Generalizable (a, b, c, d, e, f, g, h) -- | Extrapolate is a property-based testing library capable of reporting -- generalized counter-examples. -- -- Consider the following faulty implementation of sort: -- --
--   sort :: Ord a => [a] -> [a]
--   sort []      =  []
--   sort (x:xs)  =  sort (filter (< x) xs)
--                ++ [x]
--                ++ sort (filter (> x) xs)
--   
-- -- When tests pass, Extrapolate works like a regular property-based -- testing library. See: -- --
--   > check $ \xs -> sort (sort xs :: [Int]) == sort xs
--   +++ OK, passed 360 tests.
--   
-- -- When tests fail, Extrapolate reports a fully defined counter-example -- and a generalization of failing inputs. See: -- --
--   > > check $ \xs -> length (sort xs :: [Int]) == length xs
--   *** Failed! Falsifiable (after 3 tests):
--   [0,0]
--   
--   Generalization:
--   x:x:_
--   
-- -- The property fails for any integer x and for any list -- _ at the tail. module Test.Extrapolate -- | Checks a property printing results on stdout -- --
--   > check $ \xs -> sort (sort xs) == sort (xs::[Int])
--   +++ OK, passed 360 tests.
--   
--   > check $ \xs ys -> xs `union` ys == ys `union` (xs::[Int])
--   *** Failed! Falsifiable (after 4 tests):
--   [] [0,0]
--   
--   Generalization:
--   [] (x:x:_)
--   
check :: Testable a => a -> IO () -- | Check a property printing results on stdout and returning -- True on success. -- -- There is no option to silence this function: for silence, you should -- use holds. checkResult :: Testable a => a -> IO Bool -- | Use for to configure the number of tests performed by -- check. -- --
--   > check `for` 10080 $ \xs -> sort (sort xs) == sort (xs :: [Int])
--   +++ OK, passed 10080 tests.
--   
-- -- Don't forget the dollar ($)! for :: Testable a => (WithOption a -> b) -> Int -> a -> b -- | Use withBackground to provide additional functions to -- appear in side-conditions. -- --
--   check `withBackground` [constant "isSpace" isSpace] $ \xs -> unwords (words xs) == xs
--   *** Failed! Falsifiable (after 4 tests):
--   " "
--   
--   Generalization:
--   ' ':_
--   
--   Conditional Generalization:
--   c:_  when  isSpace c
--   
withBackground :: Testable a => (WithOption a -> b) -> [Expr] -> a -> b -- | Use withConditionSize to configure the maximum -- condition size allowed. withConditionSize :: Testable a => (WithOption a -> b) -> Int -> a -> b -- | 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: -- -- class (Listable a, Typeable a, Show a) => Generalizable a where name _ = "x" background _ = [] -- | Transforms a value into an manipulable expression tree. See -- constant and :$. expr :: Generalizable a => a -> Expr -- | Common name for a variable, defaults to "x". name :: Generalizable a => a -> String -- | List of symbols allowed to appear in side-conditions. Defaults to -- []. See constant. background :: Generalizable a => a -> [Expr] -- | Computes a list of reified instances. See this. instances :: Generalizable a => a -> Instances -> Instances this :: Generalizable a => a -> (Instances -> Instances) -> Instances -> Instances data Expr :: * Constant :: String -> Dynamic -> Expr Var :: String -> TypeRep -> Expr (:$) :: Expr -> Expr -> Expr constant :: Typeable * a => String -> a -> Expr showConstant :: (Typeable * a, Show a) => a -> Expr bgEq :: (Eq a, Generalizable a) => a -> [Expr] bgOrd :: (Ord a, Generalizable a) => a -> [Expr] class Testable a where options _ = [] -- | Derives a Generalizable instance for a given type Name. -- -- Consider the following Stack datatype: -- --
--   data Stack a = Stack a (Stack a) | Empty
--   
-- -- Writing -- --
--   deriveGeneralizable ''Stack
--   
-- -- will automatically derive the following Generalizable instance: -- --
--   instance Generalizable a => Generalizable (Stack a) where
--     expr s@(Stack x y) = constant "Stack" (Stack ->>: s) :$ expr x :$ expr y
--     expr s@Empty       = constant "Empty" (Empty   -: s)
--     instances s = this "s" s
--                 $ let Stack x y = Stack undefined undefined `asTypeOf` s
--                   in instances x
--                    . instances y
--   
-- -- This function needs the TemplateHaskell extension. deriveGeneralizable :: Name -> DecsQ -- | Same as deriveGeneralizable but does not warn when instance -- already exists (deriveGeneralizable is preferable). deriveGeneralizableIfNeeded :: Name -> DecsQ -- | Derives a Generalizable instance for a given type Name -- cascading derivation of type arguments as well. deriveGeneralizableCascading :: Name -> DecsQ