-- 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]): -- --
-- typesIn (typeOf (undefined :: (Int -> Int) -> Int -> Bool)) -- == [Bool,Int] --typesIn :: TypeRep -> [TypeRep] argumentTy :: TypeRep -> TypeRep resultTy :: TypeRep -> TypeRep discard :: (a -> Bool) -> [a] -> [a] compareIndex :: Eq a => [a] -> a -> a -> Ordering (.:) :: (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: -- --
-- [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 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 -- | Use minFailures to configure the minimum number of -- failures for a conditional generalization in function of the maximum -- number of tests. -- -- To set that conditional generalizations should fail for 10% of cases: -- > check minFailures (div 10) $ prop -- -- To set that conditional generalizations should fail for 5% of cases: -- > check minFailures (div 20) $ prop minFailures :: Testable a => (WithOption a -> b) -> Ratio Int -> a -> b maxSpeculateSize :: Testable a => (WithOption a -> b) -> Maybe Int -> a -> b conditionBound :: Testable a => (WithOption a -> b) -> Maybe Int -> a -> b -- | Configures a bound on the number of constants allowed in expressions -- that are considered when testing for equality in Speculate. -- -- Defaults to 2. constantBound :: Testable a => (WithOption a -> b) -> Maybe Int -> a -> b -- | Configures a bound on the depth of expressions that are considered -- when testing for equality in Speculate. -- -- Default to 3. depthBound :: Testable a => (WithOption a -> b) -> Maybe 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]) ---- --
-- 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 -- | Use minFailures to configure the minimum number of -- failures for a conditional generalization in function of the maximum -- number of tests. -- -- To set that conditional generalizations should fail for 10% of cases: -- > check minFailures (div 10) $ prop -- -- To set that conditional generalizations should fail for 5% of cases: -- > check minFailures (div 20) $ prop minFailures :: Testable a => (WithOption a -> b) -> Ratio 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: -- --
-- constant "0" 0 -- constant "'a'" 'a' -- constant "True" True -- constant "id" (id :: Int -> Int) -- constant "(+)" ((+) :: Int -> Int -> Int) -- constant "sort" (sort :: [Bool] -> [Bool]) --constant :: Typeable * a => String -> a -> Expr -- | A shorthand for constant to be used on values that are -- Show instances. Examples: -- --
-- showConstant 0 = constant "0" 0 -- showConstant 'a' = constant "'a'" 'a' -- showConstant True = constant "True" True --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