-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Functional Enumeration of Algebraic Types -- -- Feat (Functional Enumeration of Algebraic Types) provides enumerations -- as functions from natural numbers to values (similar to -- toEnum but for any algebraic data type). This can be used for -- SmallCheck-style systematic testing, QuickCheck style random testing, -- and hybrids of the two. -- -- The enumerators are defined in a very boilerplate manner and there is -- a Template Haskell script for deriving the class instance for most -- types. Test.Feat contain a subset of the other modules that -- should be sufficient for most test usage. There are some small and -- large example in the tar ball. -- -- The generators are provided by the size-based package. This means -- other libraries that implement the Sized class can use the same -- generator definitions. One such is the lazy-search package, -- that uses laziness to search for values and test properties. This is -- typically a lot faster than Feat for properties that have -- preconditions (logical implication), but can not be used for random -- selection of values. @package testing-feat @version 1.0.1.0 -- | Deprecated: Use Control.Enumerable instead module Test.Feat.Class class Typeable * a => Enumerable a enumerate :: (Enumerable a, Typeable (* -> *) f, Sized f) => Shared f a nullary :: Sized f => a -> Shareable f a unary :: (Typeable (* -> *) f, Sized f, Enumerable a) => (a -> x) -> Shareable f x funcurry :: () => (a -> b -> c) -> (a, b) -> c shared :: (Sized f, Enumerable a, Typeable f) => Shareable f a consts :: (Typeable * a, Typeable (* -> *) f, Sized f) => [Shareable f a] -> Shared f a deriveEnumerable :: Name -> Q [Dec] -- | A datatype of finite sequences module Test.Feat.Finite data Finite a Finite :: Index -> (Index -> a) -> Finite a [fCard] :: Finite a -> Index [fIndex] :: Finite a -> Index -> a type Index = Integer fromFinite :: Finite a -> (Index, [a]) finFin :: Integer -> Finite Integer instance GHC.Base.Functor Test.Feat.Finite.Finite instance GHC.Base.Applicative Test.Feat.Finite.Finite instance GHC.Base.Alternative Test.Feat.Finite.Finite instance Data.Semigroup.Semigroup (Test.Feat.Finite.Finite a) instance GHC.Base.Monoid (Test.Feat.Finite.Finite a) instance GHC.Show.Show a => GHC.Show.Show (Test.Feat.Finite.Finite a) -- | Basic combinators for building enumerations most users will want to -- use the type class based combinators in Test.Feat.Class -- instead. module Test.Feat.Enumerate type Index = Integer -- | A functional enumeration of type t is a partition of -- t into finite numbered sets called Parts. Each parts contains -- values of a certain cost (typically the size of the value). data Enumerate a Enumerate :: RevList (Finite a) -> Enumerate a [revParts] :: Enumerate a -> RevList (Finite a) parts :: Enumerate a -> [Finite a] fromParts :: [Finite a] -> Enumerate a -- | A data structure that contains a list and the reversals of all initial -- segments of the list. Intuitively -- --
-- reversals xs !! n = reverse (take (n+1) (fromRev xs)) ---- -- Any operation on a RevList typically discards the reversals -- and constructs new reversals on demand. data RevList a RevList :: [a] -> [[a]] -> RevList a [fromRev] :: RevList a -> [a] [reversals] :: RevList a -> [[a]] -- | Constructs a "Reverse list" variant of a given list. In a sensible -- Haskell implementation evaluating any inital segment of -- reversals (toRev xs) uses linear memory in the size of -- the segment. toRev :: [a] -> RevList a data Finite a Finite :: Index -> (Index -> a) -> Finite a [fCard] :: Finite a -> Index [fIndex] :: Finite a -> Index -> a fromFinite :: Finite a -> (Index, [a]) union :: Enumerate a -> Enumerate a -> Enumerate a cartesian :: () => Enumerate a -> Enumerate b -> Enumerate (a, b) -- | The definition of pure for the applicative instance. singleton :: a -> Enumerate a -- | Increases the cost/size of all values in the given set. pay :: Sized f => forall a. () => f a -> f a instance GHC.Show.Show a => GHC.Show.Show (Test.Feat.Enumerate.RevList a) instance GHC.Base.Functor Test.Feat.Enumerate.Enumerate instance GHC.Base.Applicative Test.Feat.Enumerate.Enumerate instance GHC.Base.Alternative Test.Feat.Enumerate.Enumerate instance Control.Sized.Sized Test.Feat.Enumerate.Enumerate instance Data.Semigroup.Semigroup (Test.Feat.Enumerate.Enumerate a) instance GHC.Base.Monoid (Test.Feat.Enumerate.Enumerate a) instance GHC.Base.Functor Test.Feat.Enumerate.RevList instance Data.Semigroup.Semigroup a => Data.Semigroup.Semigroup (Test.Feat.Enumerate.RevList a) instance (GHC.Base.Monoid a, Data.Semigroup.Semigroup a) => GHC.Base.Monoid (Test.Feat.Enumerate.RevList a) -- | Functions for accessing the values of enumerations including -- compatibility with the property based testing framework QuickCheck module Test.Feat.Access -- | Memoised enumeration. Note that all cardinalities are kept in memory -- until your program terminates. optimal :: Enumerable a => Enumerate a -- | Index into an enumeration. Mainly used for party tricks (give it a -- really large number), since usually you want to distinguish values by -- size. index :: Enumerable a => Integer -> a -- | A more fine grained version of index that takes a size and an index -- into the values of that size. select p i is only defined for -- i within bounds (meaning i < fst (values !! p)). select :: Enumerable a => Int -> Index -> a -- | All values of the enumeration by increasing cost (which is the number -- of constructors for most types). Also contains the length of each -- list. values :: Enumerable a => [(Integer, [a])] -- | Compatibility with QuickCheck. Distribution is uniform generator over -- values bounded by the given size. Typical use: sized uniform. uniform :: Enumerable a => Int -> Gen a -- | Enumerates every nth value of the enumeration from a given starting -- index. As a special case striped 0 1 gives all values (starts -- at index 0 and takes steps of 1). -- -- Useful for running enumerations in parallel since e.g. striped 0 -- 2 is disjoint from striped 1 2 and the union of the two -- cover all values. skipping :: Enumerate a -> Index -> Integer -> Enumerate a -- | A version of values with a limited number of values in each inner -- list. If the list corresponds to a Part which is larger than the bound -- it evenly distributes the values across the enumeration of the Part. bounded :: Enumerate a -> Integer -> Enumerate a -- | Remove all sizes exept those in the given inclusive (low,high) range sizeRange :: Enumerate a -> (Int, Int) -> Enumerate a -- | Non class version of index. indexWith :: Enumerate a -> Integer -> a -- | Non class version of select selectWith :: Enumerate a -> Int -> Index -> a -- | Non class version of values. valuesWith :: Enumerate a -> [(Integer, [a])] -- | Non class version of uniform. uniformWith :: Enumerate a -> Int -> Gen a -- | A simple testing driver for testing properties using FEAT. Contains -- three drivers with different levels of flexibility of configuration. -- -- Ironically, this code is mostly untested at the moment. module Test.Feat.Driver -- | Test with default options (defOptions). test :: Enumerable a => (a -> Bool) -> IO (Result a) data Result a counterexamples :: Result a -> [a] -- | Test with basic options. testOptions :: Enumerable a => Options -> (a -> Bool) -> IO (Result a) -- | Basic options for executing a test. Unlike FlexibleOptions this -- type has Show/Read instances. data Options Options :: Maybe Int -> Maybe (Int, Int) -> Maybe Int -> Bool -> Maybe (Index, Integer) -> Maybe Integer -> Options [oTimeoutSec] :: Options -> Maybe Int -- | (first size, last size) [oSizeFromTo] :: Options -> Maybe (Int, Int) -- | Maximum number of counterexamples [oMaxCounter] :: Options -> Maybe Int [oSilent] :: Options -> Bool -- | (start-index, steps to skip) [oSkipping] :: Options -> Maybe (Index, Integer) -- | Maximum number of tests per size [oBounded] :: Options -> Maybe Integer -- | 60 seconds timeout, maximum size of 100, bound of 100000 tests per -- size defOptions :: Options -- | The most flexible test driver, can be configured to behave in almost -- any way. testFlex :: FlexibleOptions a -> (a -> Bool) -> IO (Result a) -- | Much more flexible options for configuring every part of the test -- execution. a is the parameter type of the property. type FlexibleOptions a = IO (FlexOptions a) -- | FlexOptions data FlexOptions a FlexOptions :: (IO Bool -> IO (Result a)) -> (a -> IO Bool) -> (String -> IO ()) -> (Enumerate a -> Enumerate a) -> Enumerate a -> FlexOptions a -- | The whole execution of the test is sent through this function. [fIO] :: FlexOptions a -> IO Bool -> IO (Result a) -- | Applied to each found counterexample, return False to stop testing [fReport] :: FlexOptions a -> a -> IO Bool -- | Print text [fOutput] :: FlexOptions a -> String -> IO () -- | Applied to the enumeration before running [fProcess] :: FlexOptions a -> Enumerate a -> Enumerate a -- | The base enumeration to use, before applying fProcess. [fEnum] :: FlexOptions a -> Enumerate a defFlex :: Enumerable a => FlexibleOptions a toFlex :: Enumerable a => Options -> FlexibleOptions a toFlexWith :: Enumerate a -> Options -> FlexibleOptions a instance GHC.Show.Show a => GHC.Show.Show (Test.Feat.Driver.Result a) instance GHC.Read.Read Test.Feat.Driver.Options instance GHC.Show.Show Test.Feat.Driver.Options -- | This module contains a (hopefully) manageable subset of the -- functionality of Feat. The rest resides only in the Test.Feat.* -- modules. module Test.Feat -- | Test with default options (defOptions). test :: Enumerable a => (a -> Bool) -> IO (Result a) -- | Test with basic options. testOptions :: Enumerable a => Options -> (a -> Bool) -> IO (Result a) -- | Basic options for executing a test. Unlike FlexibleOptions this -- type has Show/Read instances. data Options Options :: Maybe Int -> Maybe (Int, Int) -> Maybe Int -> Bool -> Maybe (Index, Integer) -> Maybe Integer -> Options [oTimeoutSec] :: Options -> Maybe Int -- | (first size, last size) [oSizeFromTo] :: Options -> Maybe (Int, Int) -- | Maximum number of counterexamples [oMaxCounter] :: Options -> Maybe Int [oSilent] :: Options -> Bool -- | (start-index, steps to skip) [oSkipping] :: Options -> Maybe (Index, Integer) -- | Maximum number of tests per size [oBounded] :: Options -> Maybe Integer -- | 60 seconds timeout, maximum size of 100, bound of 100000 tests per -- size defOptions :: Options -- | A functional enumeration of type t is a partition of -- t into finite numbered sets called Parts. Each parts contains -- values of a certain cost (typically the size of the value). data Enumerate a class Typeable * a => Enumerable a enumerate :: (Enumerable a, Typeable (* -> *) f, Sized f) => Shared f a -- | Builds an enumeration of a data type from a list of constructors (see -- c0-c7) datatype :: (Typeable * a, Sized f, Typeable (* -> *) f) => [Shareable f a] -> Shared f a -- | Takes a constructor with arity 0 (a pure value) c0 :: Sized f => a -> Shareable f a -- | Takes a constructor of arity 1 c1 :: (Enumerable a, Sized f, Typeable (* -> *) f) => (a -> x) -> Shareable f x c2 :: (Enumerable a, Enumerable b, Sized f, Typeable (* -> *) f) => (a -> b -> x) -> Shareable f x c3 :: (Enumerable a, Enumerable b, Enumerable c, Sized f, Typeable (* -> *) f) => (a -> b -> c -> x) -> Shareable f x c4 :: (Enumerable a, Enumerable b, Enumerable c, Enumerable d, Sized f, Typeable (* -> *) f) => (a -> b -> c -> d -> x) -> Shareable f x c5 :: (Enumerable a, Enumerable b, Enumerable c, Enumerable d, Enumerable e, Sized f, Typeable (* -> *) f) => (a -> b -> c -> d -> e -> x) -> Shareable f x c6 :: (Enumerable a, Enumerable b, Enumerable c, Enumerable d, Enumerable e, Enumerable g, Sized f, Typeable (* -> *) f) => (a -> b -> c -> d -> e -> g -> x) -> Shareable f x c7 :: (Enumerable a, Enumerable b, Enumerable c, Enumerable d, Enumerable e, Enumerable g, Enumerable h, Sized f, Typeable (* -> *) f) => (a -> b -> c -> d -> e -> g -> h -> x) -> Shareable f x deriveEnumerable :: Name -> Q [Dec] -- | Memoised enumeration. Note that all cardinalities are kept in memory -- until your program terminates. optimal :: Enumerable a => Enumerate a -- | Index into an enumeration. Mainly used for party tricks (give it a -- really large number), since usually you want to distinguish values by -- size. index :: Enumerable a => Integer -> a -- | A more fine grained version of index that takes a size and an index -- into the values of that size. select p i is only defined for -- i within bounds (meaning i < fst (values !! p)). select :: Enumerable a => Int -> Index -> a -- | All values of the enumeration by increasing cost (which is the number -- of constructors for most types). Also contains the length of each -- list. values :: Enumerable a => [(Integer, [a])] -- | Compatibility with QuickCheck. Distribution is uniform generator over -- values bounded by the given size. Typical use: sized uniform. uniform :: Enumerable a => Int -> Gen a -- | Modifiers for types, i.e. newtype wrappers where the values satisfy -- some constraint (non-empty, positive etc.). Suggestions on useful -- types are appreciated. -- -- To apply the modifiers types you can use the record label. For -- instance: -- --
-- data C a = C [a] [a] deriving Typeable -- instance Enumerable a => Enumerable (C a) where -- enumerate = c2 $ -- \xs ys -> C (nonEmpty xs) (nonEmpty ys) ---- -- Alternatively you can put everything in pattern postition: -- --
-- instance Enumerable a => Enumerable (C a) where -- enumerate = unary $ funcurry $ -- \(Free (NonEmpty xs,NonEmpty ys)) -> C xs ys) ---- -- The first approach has the advantage of being usable with a point free -- style: \xs -> C (nonEmpty xs) . nonEmpty . module Test.Feat.Modifiers