-- 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.
@package quickcheck-classes
@version 0.4.12
-- | 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:
--
--
-- - Partial Isomorphism fromList . toList ≡
-- id
-- - Length Preservation fromList xs ≡ fromListN
-- (length xs) xs
--
--
-- 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.
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.
--
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.
--
specialisedLawsCheckMany :: Proxy a -> [Proxy a -> Laws] -> IO ()
-- | Tests the following properties:
--
--
-- - Conjunction Idempotence n .&. n ≡
-- n
-- - Disjunction Idempotence n .|. n ≡ n
-- - Double Complement complement (complement n) ≡
-- n
-- - Set Bit setBit n i ≡ n .|. bit i
-- - Clear Bit clearBit n i ≡ n .&. complement
-- (bit i)
-- - Complement Bit complementBit n i ≡ xor n (bit
-- i)
-- - Clear Zero clearBit zeroBits i ≡
-- zeroBits
-- - Set Zero setBit zeroBits i ≡ bit i
-- - Test Zero testBit zeroBits i ≡ False
-- - Pop Zero popCount zeroBits ≡ 0
-- - Count Leading Zeros of Zero countLeadingZeros
-- zeroBits ≡ finiteBitSize ⊥
-- - Count Trailing Zeros of Zero countTrailingZeros
-- zeroBits ≡ finiteBitSize ⊥
--
--
-- 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 everything from monoidLaws plus the following:
--
--
-- - Commutative mappend a b ≡ mappend b a
--
commutativeMonoidLaws :: (Monoid a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws
-- | Tests the following properties:
--
--
-- - Transitive a == b ∧ b == c ⇒ a == c
-- - Symmetric a == b ⇒ b == a
-- - Reflexive a == a
--
--
-- 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:
--
--
-- - Quotient Remainder (quot x y) * y + (rem x y) ≡
-- x
-- - Division Modulus (div x y) * y + (mod x y) ≡
-- x
-- - Integer Roundtrip fromInteger (toInteger x) ≡
-- x
--
integralLaws :: (Integral a, Arbitrary a, Show a) => Proxy a -> Laws
-- | Tests the following properties:
--
--
-- - Partial Isomorphism fromList . toList ≡
-- id
-- - Length Preservation fromList xs ≡ fromListN
-- (length xs) xs
--
--
-- 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:
--
--
-- - Partial Isomorphism decode . encode ≡
-- Just
-- - Encoding Equals Value decode . encode ≡ Just .
-- toJSON
--
--
-- 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:
--
--
-- - Associative mappend a (mappend b c) ≡ mappend
-- (mappend a b) c
-- - Left Identity mappend mempty a ≡ a
-- - Right Identity mappend a mempty ≡ a
-- - Concatenation mconcat as ≡ foldr mappend mempty
-- as
--
monoidLaws :: (Monoid a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws
-- | Tests the following properties:
--
--
-- - Antisymmetry a ≤ b ∧ b ≤ a ⇒ a = b
-- - Transitivity a ≤ b ∧ b ≤ c ⇒ a ≤ c
-- - Totality a ≤ b ∨ a > b
--
ordLaws :: (Ord 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: When using base-4.5 or older, this instead test
-- the following:
--
--
-- - Partial Isomorphism read (show a)
-- == a
--
showReadLaws :: (Show a, Read a, Eq a, Arbitrary a) => Proxy a -> Laws
storableLaws :: (Storable a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws
-- | Tests the following alternative properties:
--
--
alternativeLaws :: (Alternative f, Eq1 f, Show1 f, Arbitrary1 f) => proxy f -> Laws
-- | Tests the following alt properties:
--
--
altLaws :: (Alt f, Eq1 f, Show1 f, Arbitrary1 f) => proxy f -> Laws
-- | Tests the following applicative properties:
--
--
applicativeLaws :: (Applicative f, Eq1 f, Show1 f, Arbitrary1 f) => 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 :: (Bifunctor f, Eq2 f, Show2 f, Arbitrary2 f) => proxy f -> Laws
-- | Tests the following Foldable properties:
--
--
--
-- Note that this checks to ensure that foldl' and
-- foldr' are suitably strict.
foldableLaws :: (Foldable f, Eq1 f, Show1 f, Arbitrary1 f) => proxy f -> Laws
-- | Tests the following functor properties:
--
--
functorLaws :: (Functor f, Eq1 f, Show1 f, Arbitrary1 f) => proxy f -> Laws
-- | Tests the following monadic properties:
--
--
monadLaws :: (Monad f, Applicative f, Eq1 f, Show1 f, Arbitrary1 f) => proxy f -> Laws
-- | Tests the following monad plus properties:
--
--
monadPlusLaws :: (MonadPlus f, Eq1 f, Show1 f, Arbitrary1 f) => 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, Applicative f, Eq1 f, Show1 f, Arbitrary1 f) => 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.
--
--
-- - Identity: t (pure x) ≡ pure x
-- - Distributivity: t (x <*> y) ≡ t x
-- <*> t y
--
traversableLaws :: (Traversable f, Eq1 f, Show1 f, Arbitrary1 f) => proxy f -> 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 Data.Semigroup.Semigroup Test.QuickCheck.Classes.Status
instance GHC.Base.Monoid Test.QuickCheck.Classes.Status