-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A smarter QuickCheck. -- -- See the README.md: fast, small shrinking and generalization of failing -- test-cases from QuickCheck. @package smartcheck @version 0.2.4 module Test.SmartCheck.Types data SubT SubT :: a -> SubT [unSubT] :: SubT -> a subT :: (Arbitrary a, SubTypes a) => a -> SubT -- | Possible results of iterateArb. data Result a -- | Base type. Won't analyze. BaseType :: Result a -- | Couldn't satisfy the precondition of a QuickCheck property FailedPreCond :: Result a -- | Failed the property---either we expect failure and it passes or we -- expect to pass it and we fail. FailedProp :: Result a -- | Satisfied it, with the satisfying value. Result :: a -> Result a -- | This class covers algebraic datatypes that can be transformed into -- Trees. subTypes is the main method, placing values into trees. -- -- for a datatype with constructors A and C, -- --
--   subTypes (A (C 0) 1)
--   [Node {rootLabel = C 0, subForest = []}]
--   
class (Arbitrary a, Show a, Typeable a) => SubTypes a where subTypes = gst . from baseType _ = False replaceChild a forest b = fmap to $ grc (from a) forest b toConstr = gtc . from showForest = gsf . from -- | Turns algebraic data into a forest representation. subTypes :: SubTypes a => a -> Forest SubT -- | Turns algebraic data into a forest representation. subTypes :: (SubTypes a, Generic a, GST (Rep a)) => a -> Forest SubT -- | Base types (e.g., Int, Char) aren't analyzed. baseType :: SubTypes a => a -> Bool -- | Generically replace child i in m with value s. A total function: -- returns Nothing if you try to replace a child with an ill-typed child -- s. (Returns Just (the original data) if your index is out of bounds). replaceChild :: (SubTypes a, Typeable b) => a -> Forest Subst -> b -> Maybe a -- | Generically replace child i in m with value s. A total function: -- returns Nothing if you try to replace a child with an ill-typed child -- s. (Returns Just (the original data) if your index is out of bounds). replaceChild :: (SubTypes a, Generic a, GST (Rep a), Typeable b) => a -> Forest Subst -> b -> Maybe a -- | Get the string representation of the constructor. toConstr :: SubTypes a => a -> String -- | Get the string representation of the constructor. toConstr :: (SubTypes a, Generic a, GST (Rep a)) => a -> String -- | showForest generically shows a value while preserving its structure -- (in a Tree). Always returns either a singleton list containing the -- tree (a degenerate forest) or an empty list for baseTypes. An -- invariant is that the shape of the tree produced by showForest is the -- same as the one produced by subTypes. showForest :: SubTypes a => a -> Forest String -- | showForest generically shows a value while preserving its structure -- (in a Tree). Always returns either a singleton list containing the -- tree (a degenerate forest) or an empty list for baseTypes. An -- invariant is that the shape of the tree produced by showForest is the -- same as the one produced by subTypes. showForest :: (SubTypes a, Generic a, GST (Rep a)) => a -> Forest String -- | Index into a Tree/Forest, where level is the depth from the root and -- column is the distance d is the dth value on the same level. Thus, all -- left-most nodes are in column 0. This is a "matrix view" of -- tree-structured data. data Idx Idx :: Int -> Int -> Idx [level] :: Idx -> Int [column] :: Idx -> Int -- | Keep or substitue a value in the tree. data Subst Keep :: Subst Subst :: Subst -- | Nominally, a list for value generalization indexes and existential -- generalization. data Replace a Replace :: [a] -> [a] -> Replace a [unVals] :: Replace a -> [a] [unConstrs] :: Replace a -> [a] errorMsg :: String -> a gst :: GST f => f a -> Forest SubT grc :: (GST f, Typeable b) => f a -> Forest Subst -> b -> Maybe (f a) gtc :: GST f => f a -> String gsf :: GST f => f a -> Forest String instance GHC.Read.Read Test.SmartCheck.Types.Subst instance GHC.Classes.Eq Test.SmartCheck.Types.Subst instance GHC.Show.Show Test.SmartCheck.Types.Subst instance GHC.Classes.Eq Test.SmartCheck.Types.Idx instance GHC.Classes.Eq a => GHC.Classes.Eq (Test.SmartCheck.Types.Result a) instance GHC.Read.Read a => GHC.Read.Read (Test.SmartCheck.Types.Result a) instance GHC.Show.Show a => GHC.Show.Show (Test.SmartCheck.Types.Result a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Test.SmartCheck.Types.Replace a) instance GHC.Read.Read a => GHC.Read.Read (Test.SmartCheck.Types.Replace a) instance GHC.Show.Show a => GHC.Show.Show (Test.SmartCheck.Types.Replace a) instance GHC.Base.Functor Test.SmartCheck.Types.Result instance GHC.Base.Monad Test.SmartCheck.Types.Result instance GHC.Base.Applicative Test.SmartCheck.Types.Result instance GHC.Show.Show Test.SmartCheck.Types.Idx instance GHC.Classes.Ord Test.SmartCheck.Types.Idx instance GHC.Show.Show Test.SmartCheck.Types.SubT instance Test.SmartCheck.Types.GST GHC.Generics.U1 instance (Test.SmartCheck.Types.GST a, Test.SmartCheck.Types.GST b) => Test.SmartCheck.Types.GST (a GHC.Generics.:*: b) instance (Test.SmartCheck.Types.GST a, Test.SmartCheck.Types.GST b) => Test.SmartCheck.Types.GST (a GHC.Generics.:+: b) instance (GHC.Generics.Constructor c, Test.SmartCheck.Types.GST a) => Test.SmartCheck.Types.GST (GHC.Generics.M1 GHC.Generics.C c a) instance Test.SmartCheck.Types.GST a => Test.SmartCheck.Types.GST (GHC.Generics.M1 i k a) instance (GHC.Show.Show a, Test.QuickCheck.Arbitrary.Arbitrary a, Test.SmartCheck.Types.SubTypes a, Data.Typeable.Internal.Typeable a) => Test.SmartCheck.Types.GST (GHC.Generics.K1 i a) instance Test.SmartCheck.Types.SubTypes GHC.Types.Bool instance Test.SmartCheck.Types.SubTypes GHC.Types.Char instance Test.SmartCheck.Types.SubTypes GHC.Types.Double instance Test.SmartCheck.Types.SubTypes GHC.Types.Float instance Test.SmartCheck.Types.SubTypes GHC.Types.Int instance Test.SmartCheck.Types.SubTypes GHC.Integer.Type.Integer instance Test.SmartCheck.Types.SubTypes GHC.Int.Int8 instance Test.SmartCheck.Types.SubTypes GHC.Int.Int16 instance Test.SmartCheck.Types.SubTypes GHC.Int.Int32 instance Test.SmartCheck.Types.SubTypes GHC.Int.Int64 instance Test.SmartCheck.Types.SubTypes GHC.Types.Word instance Test.SmartCheck.Types.SubTypes GHC.Word.Word8 instance Test.SmartCheck.Types.SubTypes GHC.Word.Word16 instance Test.SmartCheck.Types.SubTypes GHC.Word.Word32 instance Test.SmartCheck.Types.SubTypes GHC.Word.Word64 instance Test.SmartCheck.Types.SubTypes () instance (Test.QuickCheck.Arbitrary.Arbitrary a, Test.SmartCheck.Types.SubTypes a, Data.Typeable.Internal.Typeable a) => Test.SmartCheck.Types.SubTypes [a] instance (GHC.Real.Integral a, Test.QuickCheck.Arbitrary.Arbitrary a, Test.SmartCheck.Types.SubTypes a, Data.Typeable.Internal.Typeable a) => Test.SmartCheck.Types.SubTypes (GHC.Real.Ratio a) instance (GHC.Float.RealFloat a, Test.QuickCheck.Arbitrary.Arbitrary a, Test.SmartCheck.Types.SubTypes a, Data.Typeable.Internal.Typeable a) => Test.SmartCheck.Types.SubTypes (Data.Complex.Complex a) instance (Test.QuickCheck.Arbitrary.Arbitrary a, Test.SmartCheck.Types.SubTypes a, Data.Typeable.Internal.Typeable a) => Test.SmartCheck.Types.SubTypes (GHC.Base.Maybe a) instance (Test.QuickCheck.Arbitrary.Arbitrary a, Test.SmartCheck.Types.SubTypes a, Data.Typeable.Internal.Typeable a, Test.QuickCheck.Arbitrary.Arbitrary b, Test.SmartCheck.Types.SubTypes b, Data.Typeable.Internal.Typeable b) => Test.SmartCheck.Types.SubTypes (Data.Either.Either a b) instance (Test.QuickCheck.Arbitrary.Arbitrary a, Test.SmartCheck.Types.SubTypes a, Data.Typeable.Internal.Typeable a, Test.QuickCheck.Arbitrary.Arbitrary b, Test.SmartCheck.Types.SubTypes b, Data.Typeable.Internal.Typeable b) => Test.SmartCheck.Types.SubTypes (a, b) instance (Test.QuickCheck.Arbitrary.Arbitrary a, Test.SmartCheck.Types.SubTypes a, Data.Typeable.Internal.Typeable a, Test.QuickCheck.Arbitrary.Arbitrary b, Test.SmartCheck.Types.SubTypes b, Data.Typeable.Internal.Typeable b, Test.QuickCheck.Arbitrary.Arbitrary c, Test.SmartCheck.Types.SubTypes c, Data.Typeable.Internal.Typeable c) => Test.SmartCheck.Types.SubTypes (a, b, c) instance (Test.QuickCheck.Arbitrary.Arbitrary a, Test.SmartCheck.Types.SubTypes a, Data.Typeable.Internal.Typeable a, Test.QuickCheck.Arbitrary.Arbitrary b, Test.SmartCheck.Types.SubTypes b, Data.Typeable.Internal.Typeable b, Test.QuickCheck.Arbitrary.Arbitrary c, Test.SmartCheck.Types.SubTypes c, Data.Typeable.Internal.Typeable c, Test.QuickCheck.Arbitrary.Arbitrary d, Test.SmartCheck.Types.SubTypes d, Data.Typeable.Internal.Typeable d) => Test.SmartCheck.Types.SubTypes (a, b, c, d) instance (Test.QuickCheck.Arbitrary.Arbitrary a, Test.SmartCheck.Types.SubTypes a, Data.Typeable.Internal.Typeable a, Test.QuickCheck.Arbitrary.Arbitrary b, Test.SmartCheck.Types.SubTypes b, Data.Typeable.Internal.Typeable b, Test.QuickCheck.Arbitrary.Arbitrary c, Test.SmartCheck.Types.SubTypes c, Data.Typeable.Internal.Typeable c, Test.QuickCheck.Arbitrary.Arbitrary d, Test.SmartCheck.Types.SubTypes d, Data.Typeable.Internal.Typeable d, Test.QuickCheck.Arbitrary.Arbitrary e, Test.SmartCheck.Types.SubTypes e, Data.Typeable.Internal.Typeable e) => Test.SmartCheck.Types.SubTypes (a, b, c, d, e) -- | SmartCheck's interface to QuickCheck. module Test.SmartCheck.Test -- | Our SmartCheck reimplementation of the main QuickCheck driver. We want -- to distinguish the first argument to a Testable property to be -- SmartChecked. In particular: the first argument will not be shrunk -- (even if there are default shrink instances for the type). However, -- the argument will be grown according to the the maxSize -- argument to QuickCheck, in accordance with its generator. Other -- arguments will be shrunk, if they have shrinking instances. scQuickCheckWithResult :: forall a prop. (Show a, Arbitrary a, Testable prop) => Args -> (a -> prop) -> IO (Maybe a, Result) -- | The default test arguments stdArgs :: Args module Test.SmartCheck.DataToTree forestReplaceChildren :: Forest a -> Idx -> a -> Forest a -- | Returns the value at index idx. Returns nothing if the index is out of -- bounds. getAtIdx :: SubTypes a => a -> Idx -> Maybe Int -> Maybe SubT -- | Replace a value at index idx generically in a Tree/Forest generically. replaceAtIdx :: (SubTypes a, Typeable b) => a -> Idx -> b -> Maybe a -- | Get the tree at idx in a forest. Nothing if the index is -- out-of-bounds. getIdxForest :: Forest a -> Idx -> Maybe (Tree a) -- | Return the list of values at each level in a Forest Not like levels in -- Data.Tree (but what I imagined it should have done!). breadthLevels :: Forest a -> [[a]] -- | Make a substitution Forest (all proper children). Initially we don't -- replace anything. mkSubstForest :: SubTypes a => a -> b -> Forest b -- | Get the depth of a Forest. 0-based (an empty Forest has depth 0). depth :: Forest a -> Int tooDeep :: Int -> Maybe Int -> Bool instance GHC.Classes.Eq Test.SmartCheck.DataToTree.SubStrat instance GHC.Read.Read Test.SmartCheck.DataToTree.SubStrat instance GHC.Show.Show Test.SmartCheck.DataToTree.SubStrat module Test.SmartCheck.SmartGen -- | Driver for iterateArb. iterateArbIdx :: SubTypes a => a -> (Idx, Maybe Int) -> Int -> Int -> (a -> Property) -> IO (Int, Result a) -- | Replace the hole in d indexed by idx with a bunch of random values, -- and test the new d against the property. Returns the first new d (the -- full d but with the hole replaced) that succeeds. Succeeds is -- determined by the call to resultify---if we're expecting failure, then -- we succeed by getting a value that passes the precondition but fails -- the property; otherwise we succeed by getting a value that passes the -- precondition and satisfies the property. If no value ever satisfies -- the precondition, then we return FailedPreCond. (Thus, there's an -- implied linear order on the Result type: FailedPreCond < FailedProp -- < Result a.) iterateArb :: forall a. SubTypes a => a -> SubT -> Idx -> Int -> Int -> (a -> Property) -> IO (Int, Result a) -- | Make a QuickCheck Result by applying a property function to a value -- and then get out the Result using our result type. resultify :: (a -> Property) -> a -> IO (Result a) -- | Put a value v into a another value d at a hole idx, if v is -- well-typed. Return Nothing if dynamic typing fails. replace :: SubTypes a => a -> Idx -> SubT -> Maybe a iter :: SubTypes a => a -> Test a b -> Next a b -> (a -> Property) -> Maybe Int -> Forest Bool -> Idx -> [Idx] -> IO (a, [Idx]) module Test.SmartCheck.Matches -- | True if d matches any ds. Assume all ds are unequal to each other. matchesShapes :: SubTypes a => a -> [(a, Replace Idx)] -> Bool -- | SmartCheck arguments. module Test.SmartCheck.Args data ScArgs ScArgs :: Format -> Args -> Int -> Maybe Int -> Int -> Bool -> Int -> Int -> Bool -> Int -> ScArgs -- | How to show extrapolated formula [format] :: ScArgs -> Format -- | QuickCheck arguments [qcArgs] :: ScArgs -> Args -- | Maximum size of data to generate, in terms of the size parameter of -- QuickCheck's Arbitrary instance for your data. [scMaxSize] :: ScArgs -> Int -- | How many levels into the structure of the failed value should we -- descend when reducing or generalizing? Nothing means we go down to -- base types. [scMaxDepth] :: ScArgs -> Maybe Int -- | How hard (number of rounds) to look for failure in the reduction -- stage. [scMaxReduce] :: ScArgs -> Int -- | Should we extrapolate? [runForall] :: ScArgs -> Bool -- | How hard (number of rounds) to look for failures during the -- extrapolation stage. [scMaxForall] :: ScArgs -> Int -- | Minimum number of times a property's precondition must be passed to -- generalize it. [scMinForall] :: ScArgs -> Int -- | Should we try to generalize constructors? [runExists] :: ScArgs -> Bool -- | How hard (number of rounds) to look for failing values with each -- constructor. For "wide" sum types, this value should be increased. [scMaxExists] :: ScArgs -> Int scStdArgs :: ScArgs data Format PrintTree :: Format PrintString :: Format instance GHC.Read.Read Test.SmartCheck.Args.ScArgs instance GHC.Show.Show Test.SmartCheck.Args.ScArgs instance GHC.Show.Show Test.SmartCheck.Args.Format instance GHC.Read.Read Test.SmartCheck.Args.Format instance GHC.Classes.Eq Test.SmartCheck.Args.Format -- | Rendering arbitrary data, and filling in holes in the data with -- variables. module Test.SmartCheck.Render renderWithVars :: SubTypes a => Format -> a -> Replace Idx -> IO () smartPrtLn :: String -> IO () module Test.SmartCheck.ConstructorGen -- | Entry point to generalize constructors. We pass in a list of indexes -- from value generalizations so we don't try to generalize those -- constructors (or anything below). constrsGen :: (SubTypes a, Generic a, ConNames (Rep a)) => ScArgs -> a -> (a -> Property) -> [Idx] -> IO [Idx] module Test.SmartCheck.Extrapolate -- | Test d with arbitrary values replacing its children. For anything we -- get 100% failure for, we claim we can generalize it---any term in that -- hole fails. -- -- We extrapolate if there exists at least one test that satisfies the -- precondition, and for all tests that satisfy the precondition, they -- fail. extrapolate :: SubTypes a => ScArgs -> a -> (a -> Property) -> IO ([Idx]) module Test.SmartCheck.Reduce smartRun :: SubTypes a => ScArgs -> a -> (a -> Property) -> IO a -- | Interface module. module Test.SmartCheck -- | Main interface function. smartCheck :: (SubTypes a, Generic a, ConNames (Rep a), Testable prop) => ScArgs -> (a -> prop) -> IO () smartCheckInput :: forall a prop. (SubTypes a, Generic a, ConNames (Rep a), Testable prop, Read a) => ScArgs -> (a -> prop) -> IO () -- | Run QuickCheck, to get a counterexamples for each argument, including -- the one we want to focus on for SmartCheck, which is the first -- argument. That argument is never shrunk by QuickCheck, but others may -- be shrunk by QuickCheck. Returns the value (if it exists) and a -- Property (by applying the property method to the -- Testable value). In each iteration of runQC, -- non-SmartCheck arguments are not necessarily held constant runQC :: forall a prop. (Show a, Arbitrary a, Testable prop) => Args -> (a -> prop) -> IO (Maybe a, a -> Property) -- | This class covers algebraic datatypes that can be transformed into -- Trees. subTypes is the main method, placing values into trees. -- -- for a datatype with constructors A and C, -- --
--   subTypes (A (C 0) 1)
--   [Node {rootLabel = C 0, subForest = []}]
--   
class (Arbitrary a, Show a, Typeable a) => SubTypes a where subTypes = gst . from baseType _ = False replaceChild a forest b = fmap to $ grc (from a) forest b toConstr = gtc . from showForest = gsf . from -- | Turns algebraic data into a forest representation. subTypes :: SubTypes a => a -> Forest SubT -- | Turns algebraic data into a forest representation. subTypes :: (SubTypes a, Generic a, GST (Rep a)) => a -> Forest SubT -- | Base types (e.g., Int, Char) aren't analyzed. baseType :: SubTypes a => a -> Bool -- | Generically replace child i in m with value s. A total function: -- returns Nothing if you try to replace a child with an ill-typed child -- s. (Returns Just (the original data) if your index is out of bounds). replaceChild :: (SubTypes a, Typeable b) => a -> Forest Subst -> b -> Maybe a -- | Generically replace child i in m with value s. A total function: -- returns Nothing if you try to replace a child with an ill-typed child -- s. (Returns Just (the original data) if your index is out of bounds). replaceChild :: (SubTypes a, Generic a, GST (Rep a), Typeable b) => a -> Forest Subst -> b -> Maybe a -- | Get the string representation of the constructor. toConstr :: SubTypes a => a -> String -- | Get the string representation of the constructor. toConstr :: (SubTypes a, Generic a, GST (Rep a)) => a -> String -- | showForest generically shows a value while preserving its structure -- (in a Tree). Always returns either a singleton list containing the -- tree (a degenerate forest) or an empty list for baseTypes. An -- invariant is that the shape of the tree produced by showForest is the -- same as the one produced by subTypes. showForest :: SubTypes a => a -> Forest String -- | showForest generically shows a value while preserving its structure -- (in a Tree). Always returns either a singleton list containing the -- tree (a degenerate forest) or an empty list for baseTypes. An -- invariant is that the shape of the tree produced by showForest is the -- same as the one produced by subTypes. showForest :: (SubTypes a, Generic a, GST (Rep a)) => a -> Forest String gst :: GST f => f a -> Forest SubT grc :: (GST f, Typeable b) => f a -> Forest Subst -> b -> Maybe (f a) gtc :: GST f => f a -> String gsf :: GST f => f a -> Forest String