-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | QuickCheck common typeclasses -- -- This library provides QuickCheck properties to ensure that typeclass -- instances adhere to the set of laws that they are supposed to. There -- are other libraries that do similar things, such as -- `genvalidity-hspec` and checkers. This library differs from -- other solutions by not introducing any new typeclasses that the user -- needs to learn. -- -- Note: on GHC < 8.5, this library uses the higher-kinded -- typeclasses (Data.Functor.Classes.Show1, -- Data.Functor.Classes.Eq1, Data.Functor.Classes.Ord1, -- etc.), but on GHC >= 8.5, it uses `-XQuantifiedConstraints` to -- express these constraints more cleanly. @package quickcheck-classes @version 0.6.2.2 -- | This module provides property tests for functions that operate on -- list-like data types. If your data type is fully polymorphic in its -- element type, is it recommended that you use foldableLaws and -- traversableLaws from Test.QuickCheck.Classes. -- However, if your list-like data type is either monomorphic in its -- element type (like Text or ByteString) or if it -- requires a typeclass constraint on its element (like -- Data.Vector.Unboxed), the properties provided here can be -- helpful for testing that your functions have the expected behavior. -- All properties in this module require your data type to have an -- IsList instance. module Test.QuickCheck.Classes.IsList -- | Tests the following properties: -- -- -- -- Note: This property test is only available when using -- base-4.7 or newer. isListLaws :: (IsList a, Show a, Show (Item a), Arbitrary a, Arbitrary (Item a), Eq a) => Proxy a -> Laws foldrProp :: (IsList c, Item c ~ a, Arbitrary c, Show c, Show a, CoArbitrary a, Function a) => Proxy a -> (forall b. (a -> b -> b) -> b -> c -> b) -> Property foldlProp :: (IsList c, Item c ~ a, Arbitrary c, Show c, Show a, CoArbitrary a, Function a) => Proxy a -> (forall b. (b -> a -> b) -> b -> c -> b) -> Property foldlMProp :: (IsList c, Item c ~ a, Arbitrary c, Show c, Show a, CoArbitrary a, Function a) => Proxy a -> (forall s b. (b -> a -> ST s b) -> b -> c -> ST s b) -> Property mapProp :: (IsList c, IsList d, Eq d, Show d, Show b, Item c ~ a, Item d ~ b, Arbitrary c, Arbitrary b, Show c, Show a, CoArbitrary a, Function a) => Proxy a -> Proxy b -> ((a -> b) -> c -> d) -> Property imapProp :: (IsList c, IsList d, Eq d, Show d, Show b, Item c ~ a, Item d ~ b, Arbitrary c, Arbitrary b, Show c, Show a, CoArbitrary a, Function a) => Proxy a -> Proxy b -> ((Int -> a -> b) -> c -> d) -> Property imapMProp :: (IsList c, IsList d, Eq d, Show d, Show b, Item c ~ a, Item d ~ b, Arbitrary c, Arbitrary b, Show c, Show a, CoArbitrary a, Function a) => Proxy a -> Proxy b -> (forall s. (Int -> a -> ST s b) -> c -> ST s d) -> Property traverseProp :: (IsList c, IsList d, Eq d, Show d, Show b, Item c ~ a, Item d ~ b, Arbitrary c, Arbitrary b, Show c, Show a, CoArbitrary a, Function a) => Proxy a -> Proxy b -> (forall s. (a -> ST s b) -> c -> ST s d) -> Property -- | Property for the generate function, which builds a container -- of a given length by applying a function to each index. generateProp :: (Item c ~ a, Eq c, Show c, IsList c, Arbitrary a, Show a) => Proxy a -> (Int -> (Int -> a) -> c) -> Property generateMProp :: (Item c ~ a, Eq c, Show c, IsList c, Arbitrary a, Show a) => Proxy a -> (forall s. Int -> (Int -> ST s a) -> ST s c) -> Property replicateProp :: (Item c ~ a, Eq c, Show c, IsList c, Arbitrary a, Show a) => Proxy a -> (Int -> a -> c) -> Property replicateMProp :: (Item c ~ a, Eq c, Show c, IsList c, Arbitrary a, Show a) => Proxy a -> (forall s. Int -> ST s a -> ST s c) -> Property -- | Property for the filter function, which keeps elements for -- which the predicate holds true. filterProp :: (IsList c, Item c ~ a, Arbitrary c, Show c, Show a, Eq c, CoArbitrary a, Function a) => Proxy a -> ((a -> Bool) -> c -> c) -> Property -- | Property for the filterM function, which keeps elements for -- which the predicate holds true in an applicative context. filterMProp :: (IsList c, Item c ~ a, Arbitrary c, Show c, Show a, Eq c, CoArbitrary a, Function a) => Proxy a -> (forall s. (a -> ST s Bool) -> c -> ST s c) -> Property -- | Property for the mapMaybe function, which keeps elements for -- which the predicate holds true. mapMaybeProp :: (IsList c, Item c ~ a, Item d ~ b, Eq d, IsList d, Arbitrary b, Show d, Show b, Arbitrary c, Show c, Show a, Eq c, CoArbitrary a, Function a) => Proxy a -> Proxy b -> ((a -> Maybe b) -> c -> d) -> Property mapMaybeMProp :: (IsList c, IsList d, Eq d, Show d, Show b, Item c ~ a, Item d ~ b, Arbitrary c, Arbitrary b, Show c, Show a, CoArbitrary a, Function a) => Proxy a -> Proxy b -> (forall s. (a -> ST s (Maybe b)) -> c -> ST s d) -> Property -- | This library provides sets of properties that should hold for common -- typeclasses. -- -- Note: on GHC < 8.6, this library uses the higher-kinded -- typeclasses (Show1, Eq1, Ord1, etc.), but on GHC -- >= 8.6, it uses -XQuantifiedConstraints to express these -- constraints more cleanly. module Test.QuickCheck.Classes -- | A convenience function for testing properties in GHCi. For example, at -- GHCi: -- --
--   >>> lawsCheck (monoidLaws (Proxy :: Proxy Ordering))
--   Monoid: Associative +++ OK, passed 100 tests.
--   Monoid: Left Identity +++ OK, passed 100 tests.
--   Monoid: Right Identity +++ OK, passed 100 tests.
--   
-- -- Assuming that the Arbitrary instance for Ordering is -- good, we now have confidence that the Monoid instance for -- Ordering satisfies the monoid laws. lawsCheck :: Laws -> IO () -- | A convenience function for checking multiple typeclass instances of -- multiple types. Consider the following Haskell source file: -- --
--   import Data.Proxy (Proxy(..))
--   import Data.Map (Map)
--   import Data.Set (Set)
--   
--   -- A Proxy for Set Int.
--   setInt :: Proxy (Set Int)
--   setInt = Proxy
--   
--   -- A Proxy for Map Int Int.
--   mapInt :: Proxy (Map Int Int)
--   mapInt = Proxy
--   
--   myLaws :: Proxy a -> [Laws]
--   myLaws p = [eqLaws p, monoidLaws p]
--   
--   namedTests :: [(String, [Laws])]
--   namedTests =
--     [ ("Set Int", myLaws setInt)
--     , ("Map Int Int", myLaws mapInt)
--     ]
--   
-- -- Now, in GHCi: -- --
--   >>> lawsCheckMany namedTests
--   
-- --
--   Testing properties for common typeclasses
--   -------------
--   -- Set Int --
--   -------------
--   
--   Eq: Transitive +++ OK, passed 100 tests.
--   Eq: Symmetric +++ OK, passed 100 tests.
--   Eq: Reflexive +++ OK, passed 100 tests.
--   Monoid: Associative +++ OK, passed 100 tests.
--   Monoid: Left Identity +++ OK, passed 100 tests.
--   Monoid: Right Identity +++ OK, passed 100 tests.
--   Monoid: Concatenation +++ OK, passed 100 tests.
--   
--   -----------------
--   -- Map Int Int --
--   -----------------
--   
--   Eq: Transitive +++ OK, passed 100 tests.
--   Eq: Symmetric +++ OK, passed 100 tests.
--   Eq: Reflexive +++ OK, passed 100 tests.
--   Monoid: Associative +++ OK, passed 100 tests.
--   Monoid: Left Identity +++ OK, passed 100 tests.
--   Monoid: Right Identity +++ OK, passed 100 tests.
--   Monoid: Concatenation +++ OK, passed 100 tests.
--   
-- -- In the case of a failing test, the program terminates with exit code -- 1. lawsCheckMany :: [(String, [Laws])] -> IO () -- | A convenience function that allows one to check many typeclass -- instances of the same type. -- --
--   >>> specialisedLawsCheckMany (Proxy :: Proxy Word) [jsonLaws, showReadLaws]
--   ToJSON/FromJSON: Encoding Equals Value +++ OK, passed 100 tests.
--   ToJSON/FromJSON: Partial Isomorphism +++ OK, passed 100 tests.
--   Show/Read: Partial Isomorphism +++ OK, passed 100 tests.
--   
lawsCheckOne :: Proxy a -> [Proxy a -> Laws] -> IO () -- | Tests the following properties: -- -- -- -- All of the useful instances of the Bits typeclass also have -- FiniteBits instances, so these property tests actually require -- that instance as well. -- -- Note: This property test is only available when using -- base-4.7 or newer. bitsLaws :: (FiniteBits a, Arbitrary a, Show a) => Proxy a -> Laws -- | Tests the following properties: -- -- -- -- Some of these properties involve implication. In the case that the -- left hand side of the implication arrow does not hold, we do not -- retry. Consequently, these properties only end up being useful when -- the data type has a small number of inhabitants. eqLaws :: (Eq a, Arbitrary a, Show a) => Proxy a -> Laws -- | Tests the following properties: -- -- numLaws :: (Num a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws -- | Tests the following properties: -- -- integralLaws :: (Integral a, Arbitrary a, Show a) => Proxy a -> Laws -- | Tests the various Ix properties: -- --
--   inRange (l,u) i == elem i (range (l,u))
--   
-- -- range (l,u) !! index (l,u) i == -- i, when inRange (l,u) i -- --
--   map (index (l,u)) (range (l,u)) == [0 .. rangeSize (l,u) - 1]
--   
-- --
--   rangeSize (l,u) == length (range (l,u))
--   
ixLaws :: (Ix a, Arbitrary a, Show a) => Proxy a -> Laws -- | Tests the following properties: -- -- -- -- Note: This property test is only available when using -- base-4.7 or newer. isListLaws :: (IsList a, Show a, Show (Item a), Arbitrary a, Arbitrary (Item a), Eq a) => Proxy a -> Laws -- | Tests the following properties: -- -- -- -- Note that in the second property, the type of decode is ByteString -- -> Value, not ByteString -> a jsonLaws :: (ToJSON a, FromJSON a, Show a, Arbitrary a, Eq a) => Proxy a -> Laws -- | Tests the following properties: -- -- monoidLaws :: (Monoid a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws -- | Tests the following properties: -- -- -- -- Note that this does not test associativity or identity. Make sure to -- use monoidLaws in addition to this set of laws. commutativeMonoidLaws :: (Monoid a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws semigroupMonoidLaws :: forall a. (Semigroup a, Monoid a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws -- | Tests the following properties: -- -- ordLaws :: (Ord a, Arbitrary a, Show a) => Proxy a -> Laws -- | Tests the following properties: -- -- -- -- This only works for Enum types that are not bounded, meaning -- that succ and pred must be total. This means that these -- property tests work correctly for types like Integer but not -- for Int. -- -- Sadly, there is not a good way to test fromEnum and -- toEnum, since many types that have reasonable implementations -- for succ and pred have more inhabitants than Int -- does. enumLaws :: (Enum a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws -- | Tests the same properties as enumLaws except that it requires -- the type to have a Bounded instance. These tests avoid taking -- the successor of the maximum element or the predecessor of the minimal -- element. boundedEnumLaws :: (Enum a, Bounded a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws -- | Test that a Prim instance obey the several laws. primLaws :: (Prim a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws -- | Tests the following properties: -- -- semigroupLaws :: (Semigroup a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws -- | Tests the following properties: -- -- -- -- Note that this does not test associativity. Make sure to use -- semigroupLaws in addition to this set of laws. commutativeSemigroupLaws :: (Semigroup a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws -- | Tests the following properties: -- -- -- -- Note that this does not test associativity. Make sure to use -- semigroupLaws in addition to this set of laws. exponentialSemigroupLaws :: (Semigroup a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws -- | Tests the following properties: -- -- -- -- Note that this does not test associativity. Make sure to use -- semigroupLaws in addition to this set of laws. In literature, -- this class of semigroup is known as a band. idempotentSemigroupLaws :: (Semigroup a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws -- | Tests the following properties: -- -- -- -- Note that this does not test associativity. Make sure to use -- semigroupLaws in addition to this set of laws. rectangularBandSemigroupLaws :: (Semigroup a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws -- | Tests the following properties: -- -- semiringLaws :: (Semiring a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws -- | Tests the following properties: -- -- -- -- Note that this does not test any of the laws tested by -- semiringLaws. ringLaws :: (Ring a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws -- | Tests the following properties: -- -- showLaws :: (Show a, Arbitrary a) => Proxy a -> Laws -- | Tests the following properties: -- -- -- -- Note: When using base-4.5 or older, a shim -- implementation of readMaybe is used. showReadLaws :: (Show a, Read a, Eq a, Arbitrary a) => Proxy a -> Laws -- | Tests the following alternative properties: -- -- storableLaws :: (Storable a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws -- | Tests the following properties: -- -- -- -- Note: This property test is only available when using -- base-4.5 or newer. -- -- Note: from and to don't actually care about the -- type variable x in Rep a x, so here we -- instantiate it to '()' by default. If you would like to -- instantiate x as something else, please file a bug report. genericLaws :: (Generic a, Eq a, Arbitrary a, Show a, Show (Rep a ()), Arbitrary (Rep a ()), Eq (Rep a ())) => Proxy a -> Laws -- | Tests the following properties: -- -- -- -- Note: This property test is only available when using -- base-4.9 or newer. generic1Laws :: (Generic1 f, Eq1 f, Arbitrary1 f, Show1 f, Eq1 (Rep1 f), Show1 (Rep1 f), Arbitrary1 (Rep1 f)) => proxy f -> Laws -- | Tests the following alternative properties: -- -- alternativeLaws :: (Alternative f, forall a. Eq a => Eq (f a), forall a. Show a => Show (f a), forall a. Arbitrary a => Arbitrary (f a)) => proxy f -> Laws -- | Tests the following alt properties: -- -- altLaws :: forall proxy f. (Alt f, forall a. Eq a => Eq (f a), forall a. Show a => Show (f a), forall a. Arbitrary a => Arbitrary (f a)) => proxy f -> Laws -- | Tests the following alt properties: -- -- applyLaws :: (Apply f, forall a. Eq a => Eq (f a), forall a. Show a => Show (f a), forall a. Arbitrary a => Arbitrary (f a)) => proxy f -> Laws -- | Tests the following applicative properties: -- -- applicativeLaws :: (Applicative f, forall a. Eq a => Eq (f a), forall a. Show a => Show (f a), forall a. Arbitrary a => Arbitrary (f a)) => proxy f -> Laws -- | Tests the following contravariant properties: -- -- contravariantLaws :: (Contravariant f, forall a. Eq a => Eq (f a), forall a. Show a => Show (f a), forall a. Arbitrary a => Arbitrary (f a)) => proxy f -> Laws -- | Tests the following Foldable properties: -- -- -- -- Note that this checks to ensure that foldl' and -- foldr' are suitably strict. foldableLaws :: forall proxy f. (Foldable f, forall a. Eq a => Eq (f a), forall a. Show a => Show (f a), forall a. Arbitrary a => Arbitrary (f a)) => proxy f -> Laws -- | Tests the following functor properties: -- -- functorLaws :: (Functor f, forall a. Eq a => Eq (f a), forall a. Show a => Show (f a), forall a. Arbitrary a => Arbitrary (f a)) => proxy f -> Laws -- | Tests the following monadic properties: -- -- monadLaws :: (Monad f, Applicative f, forall a. Eq a => Eq (f a), forall a. Show a => Show (f a), forall a. Arbitrary a => Arbitrary (f a)) => proxy f -> Laws -- | Tests the following monad plus properties: -- -- monadPlusLaws :: (MonadPlus f, forall a. Eq a => Eq (f a), forall a. Show a => Show (f a), forall a. Arbitrary a => Arbitrary (f a)) => proxy f -> Laws -- | Tests the following monadic zipping properties: -- -- -- -- In the laws above, the infix function *** refers to a -- typeclass method of Arrow. monadZipLaws :: (MonadZip f, forall a. Eq a => Eq (f a), forall a. Show a => Show (f a), forall a. Arbitrary a => Arbitrary (f a)) => proxy f -> Laws -- | Tests the following alt properties: -- -- plusLaws :: forall proxy f. (Plus f, forall a. Eq a => Eq (f a), forall a. Show a => Show (f a), forall a. Arbitrary a => Arbitrary (f a)) => proxy f -> Laws -- | Tests everything from altLaws, plus the following: -- -- extendedPlusLaws :: forall proxy f. (Plus f, Alternative f, forall a. Eq a => Eq (f a), forall a. Show a => Show (f a), forall a. Arbitrary a => Arbitrary (f a)) => proxy f -> Laws -- | Tests the following Traversable properties: -- -- -- -- Where an applicative transformation is a function -- --
--   t :: (Applicative f, Applicative g) => f a -> g a
--   
-- -- preserving the Applicative operations, i.e. -- -- traversableLaws :: (Traversable f, forall a. Eq a => Eq (f a), forall a. Show a => Show (f a), forall a. Arbitrary a => Arbitrary (f a)) => proxy f -> Laws -- | Tests the following Bifunctor properties: -- -- -- -- Note: This property test is only available when this package is -- built with base-4.10+ or transformers-0.5+. bifoldableLaws :: forall proxy f. (Bifoldable f, forall a b. (Eq a, Eq b) => Eq (f a b), forall a b. (Show a, Show b) => Show (f a b), forall a b. (Arbitrary a, Arbitrary b) => Arbitrary (f a b)) => proxy f -> Laws -- | Tests the following Bifunctor properties: -- -- -- -- Note: This property test is only available when this package is -- built with base-4.9+ or transformers-0.5+. bifunctorLaws :: forall proxy f. (Bifunctor f, forall a b. (Eq a, Eq b) => Eq (f a b), forall a b. (Show a, Show b) => Show (f a b), forall a b. (Arbitrary a, Arbitrary b) => Arbitrary (f a b)) => proxy f -> Laws -- | Tests the following Bitraversable properties: -- -- -- -- Note: This property test is only available when this package is -- built with base-4.9+ or transformers-0.5+. bitraversableLaws :: forall proxy f. (Bitraversable f, forall a b. (Eq a, Eq b) => Eq (f a b), forall a b. (Show a, Show b) => Show (f a b), forall a b. (Arbitrary a, Arbitrary b) => Arbitrary (f a b)) => proxy f -> Laws -- | Tests the following Category properties: -- -- -- -- Note: This property test is only available when this package is -- built with base-4.9+ or transformers-0.5+. categoryLaws :: forall proxy c. (Category c, forall a b. (Eq a, Eq b) => Eq (c a b), forall a b. (Show a, Show b) => Show (c a b), forall a b. (Arbitrary a, Arbitrary b) => Arbitrary (c a b)) => proxy c -> Laws -- | Test everything from categoryLaws plus the following: -- -- -- -- Note: This property test is only available when this package is -- built with base-4.9+ or transformers-0.5+. commutativeCategoryLaws :: forall proxy c. (Category c, forall a b. (Eq a, Eq b) => Eq (c a b), forall a b. (Show a, Show b) => Show (c a b), forall a b. (Arbitrary a, Arbitrary b) => Arbitrary (c a b)) => proxy c -> Laws -- | Tests the following Semigroupoid properties: -- -- -- -- Note: This property test is only available when this package is -- built with base-4.9+ or transformers-0.5+. semigroupoidLaws :: forall proxy s. (Semigroupoid s, forall a b. (Eq a, Eq b) => Eq (s a b), forall a b. (Show a, Show b) => Show (s a b), forall a b. (Arbitrary a, Arbitrary b) => Arbitrary (s a b)) => proxy s -> Laws -- | Tests everything from semigroupoidLaws plus the following: -- -- -- -- Note: This property test is only available when this package is -- built with base-4.9+ or transformers-0.5+. commutativeSemigroupoidLaws :: forall proxy s. (Semigroupoid s, forall a b. (Eq a, Eq b) => Eq (s a b), forall a b. (Show a, Show b) => Show (s a b), forall a b. (Arbitrary a, Arbitrary b) => Arbitrary (s a b)) => proxy s -> Laws -- | Test that a MVector instance obey several laws. muvectorLaws :: (Eq a, Unbox a, Arbitrary a, Show a) => Proxy a -> Laws -- | A set of laws associated with a typeclass. data Laws Laws :: String -> [(String, Property)] -> Laws -- | Name of the typeclass whose laws are tested [lawsTypeclass] :: Laws -> String -- | Pairs of law name and property [lawsProperties] :: Laws -> [(String, Property)] -- | In older versions of GHC, Proxy is not poly-kinded, so we provide -- Proxy1. data Proxy1 (f :: * -> *) Proxy1 :: Proxy1 -- | In older versions of GHC, Proxy is not poly-kinded, so we provide -- Proxy2. data Proxy2 (f :: * -> * -> *) Proxy2 :: Proxy2 instance GHC.Base.Semigroup Test.QuickCheck.Classes.Status instance GHC.Base.Monoid Test.QuickCheck.Classes.Status