-- 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]): -- --
-- 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: -- --
-- [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 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: -- --
-- 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