quickcheck-classes-0.6.5.0: QuickCheck common typeclasses
Safe HaskellSafe-Inferred
LanguageHaskell2010

Test.QuickCheck.Classes

Description

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.

Synopsis

Running

lawsCheck :: Laws -> IO () #

lawsCheckMany :: [(String, [Laws])] -> IO () #

lawsCheckOne :: Proxy a -> [Proxy a -> Laws] -> IO () #

Properties

Ground types

bitsLaws :: (FiniteBits a, Arbitrary a, Show a) => Proxy a -> Laws #

eqLaws :: (Eq a, Arbitrary a, Show a) => Proxy a -> Laws #

substitutiveEqLaws :: (Eq a, Arbitrary a, CoArbitrary a, Function a, Show a) => Proxy a -> Laws #

numLaws :: (Num a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws #

integralLaws :: (Integral a, Arbitrary a, Show a) => Proxy a -> Laws #

ixLaws :: (Ix a, Arbitrary a, Show a) => Proxy a -> Laws #

isListLaws :: (IsList a, Show a, Show (Item a), Arbitrary a, Arbitrary (Item a), Eq a) => Proxy a -> Laws #

jsonLaws :: (ToJSON a, FromJSON a, Show a, Arbitrary a, Eq a) => Proxy a -> Laws Source #

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

monoidLaws :: (Monoid a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws #

commutativeMonoidLaws :: (Monoid a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws #

semigroupMonoidLaws :: (Semigroup a, Monoid a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws #

ordLaws :: (Ord a, Arbitrary a, Show a) => Proxy a -> Laws #

enumLaws :: (Enum a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws #

boundedEnumLaws :: (Enum a, Bounded a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws #

primLaws :: (Prim a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws Source #

Test that a Prim instance obey the several laws.

semigroupLaws :: (Semigroup a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws #

commutativeSemigroupLaws :: (Semigroup a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws #

exponentialSemigroupLaws :: (Semigroup a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws #

idempotentSemigroupLaws :: (Semigroup a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws #

rectangularBandSemigroupLaws :: (Semigroup a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws #

semiringLaws :: (Semiring a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws Source #

Tests the following properties:

Additive Commutativity
a + b ≡ b + a
Additive Left Identity
0 + a ≡ a
Additive Right Identity
a + 0 ≡ a
Multiplicative Associativity
a * (b * c) ≡ (a * b) * c
Multiplicative Left Identity
1 * a ≡ a
Multiplicative Right Identity
a * 1 ≡ a
Multiplication Left Distributes Over Addition
a * (b + c) ≡ (a * b) + (a * c)
Multiplication Right Distributes Over Addition
(a + b) * c ≡ (a * c) + (b * c)
Multiplicative Left Annihilation
0 * a ≡ 0
Multiplicative Right Annihilation
a * 0 ≡ 0

Also tests that fromNatural is a homomorphism of semirings:

FromNatural Maps Zero
fromNatural 0 = zero
FromNatural Maps One
fromNatural 1 = one
FromNatural Maps Plus
fromNatural (a + b) = fromNatural a + fromNatural b
FromNatural Maps Times
fromNatural (a * b) = fromNatural a * fromNatural b

ringLaws :: (Ring a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws Source #

Tests the following properties:

Additive Inverse
negate a + a ≡ 0

Note that this does not test any of the laws tested by semiringLaws.

gcdDomainLaws :: (Eq a, GcdDomain a, Arbitrary a, Show a) => Proxy a -> Laws Source #

Test that a GcdDomain instance obey several laws.

Check that divide is an inverse of times:

  • y /= 0 => (x * y) `divide` y == Just x,
  • y /= 0, x `divide` y == Just z => x == z * y.

Check that gcd is a common divisor and is a multiple of any common divisor:

  • x /= 0, y /= 0 => isJust (x `divide` gcd x y) && isJust (y `divide` gcd x y),
  • z /= 0 => isJust (gcd (x * z) (y * z) `divide` z).

Check that lcm is a common multiple and is a factor of any common multiple:

  • x /= 0, y /= 0 => isJust (lcm x y `divide` x) && isJust (lcm x y `divide` y),
  • x /= 0, y /= 0, isJust (z `divide` x), isJust (z `divide` y) => isJust (z `divide` lcm x y).

Check that gcd of coprime numbers is a unit of the semiring (has an inverse):

  • y /= 0, coprime x y => isJust (1 `divide` gcd x y).

euclideanLaws :: (Eq a, Euclidean a, Arbitrary a, Show a) => Proxy a -> Laws Source #

Test that a Euclidean instance obey laws of a Euclidean domain.

  • y /= 0, r == x `rem` y => r == 0 || degree r < degree y,
  • y /= 0, (q, r) == x `quotRem` y => x == q * y + r,
  • y /= 0 => x `quot` x y == fst (x `quotRem` y),
  • y /= 0 => x `rem` x y == snd (x `quotRem` y).

showLaws :: (Show a, Arbitrary a) => Proxy a -> Laws #

showReadLaws :: (Show a, Read a, Eq a, Arbitrary a) => Proxy a -> Laws #

storableLaws :: (Storable a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws #

genericLaws :: (Generic a, Eq a, Arbitrary a, Show a, Show (Rep a ()), Arbitrary (Rep a ()), Eq (Rep a ())) => Proxy a -> Laws #

generic1Laws :: forall (f :: Type -> Type) proxy. (Generic1 f, Eq1 f, Arbitrary1 f, Show1 f, Eq1 (Rep1 f), Show1 (Rep1 f), Arbitrary1 (Rep1 f)) => proxy f -> Laws #

Unary type constructors

alternativeLaws :: forall (f :: Type -> Type) proxy. (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 #

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 Source #

Tests the following alt properties:

Associativity
(a <!> b) <!> c ≡ a <!> (b <!> c)
Left Distributivity
f <$> (a <!> b) ≡ (f <$> a) <!> (f <$> b)

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 Source #

Tests the following alt properties:

LiftF2 (1)
(<.>) ≡ liftF2 id
Associativity
fmap (.) u <.> v <.> w ≡ u <.> (v <.> w)

applicativeLaws :: forall (f :: Type -> Type) proxy. (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 #

contravariantLaws :: forall (f :: Type -> Type) proxy. (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 #

foldableLaws :: forall proxy (f :: Type -> Type). (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 #

functorLaws :: forall (f :: Type -> Type) proxy. (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 #

monadLaws :: forall (f :: Type -> Type) proxy. (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 #

monadPlusLaws :: forall (f :: Type -> Type) proxy. (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 #

monadZipLaws :: forall (f :: Type -> Type) proxy. (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 #

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 Source #

Tests the following alt properties:

Left Identity
zero <!> m ≡ m
Right Identity
m <!> zero ≡ m

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 Source #

Tests everything from altLaws, plus the following:

Congruency
zeroempty

traversableLaws :: forall (f :: Type -> Type) proxy. (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 #

Binary type constructors

bifoldableLaws :: forall proxy (f :: Type -> Type -> Type). (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 #

bifunctorLaws :: forall proxy (f :: Type -> Type -> Type). (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 #

bitraversableLaws :: forall proxy (f :: Type -> Type -> Type). (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 #

categoryLaws :: forall proxy (c :: Type -> Type -> Type). (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 #

commutativeCategoryLaws :: forall proxy (c :: Type -> Type -> Type). (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 #

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 Source #

Tests the following Semigroupoid properties:

Associativity
f `o' (g `o' h) ≡ (f `o' g) `o' h

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 Source #

Tests everything from semigroupoidLaws plus the following:

Commutative
f `o' g ≡ g `o' f

Note: This property test is only available when this package is built with base-4.9+ or transformers-0.5+.

muvectorLaws :: (Eq a, Unbox a, Arbitrary a, Show a) => Proxy a -> Laws Source #

Test that a MVector instance obey several laws.

Types

data Laws #

Constructors

Laws 

Fields

data Proxy1 (f :: Type -> Type) #

Constructors

Proxy1 

data Proxy2 (f :: Type -> Type -> Type) #

Constructors

Proxy2