{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_GHC -Wall #-}
module Test.QuickCheck.Classes.Enum
( enumLaws
, boundedEnumLaws
) where
import Data.Proxy (Proxy)
import Test.QuickCheck hiding ((.&.))
import Test.QuickCheck.Property (Property)
import Test.QuickCheck.Classes.Common (Laws(..), myForAllShrink)
enumLaws :: (Enum a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws
enumLaws p = Laws "Enum"
[ ("Succ Pred Identity", succPredIdentity p)
, ("Pred Succ Identity", predSuccIdentity p)
]
boundedEnumLaws :: (Enum a, Bounded a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws
boundedEnumLaws p = Laws "Enum"
[ ("Succ Pred Identity", succPredBoundedIdentity p)
, ("Pred Succ Identity", predSuccBoundedIdentity p)
]
succPredIdentity :: forall a. (Enum a, Eq a, Arbitrary a, Show a) => Proxy a -> Property
succPredIdentity _ = myForAllShrink False (const True)
(\(a :: a) -> ["a = " ++ show a])
"succ (pred x)"
(\a -> succ (pred a))
"x"
(\a -> a)
predSuccIdentity :: forall a. (Enum a, Eq a, Arbitrary a, Show a) => Proxy a -> Property
predSuccIdentity _ = myForAllShrink False (const True)
(\(a :: a) -> ["a = " ++ show a])
"pred (succ x)"
(\a -> pred (succ a))
"x"
(\a -> a)
succPredBoundedIdentity :: forall a. (Enum a, Bounded a, Eq a, Arbitrary a, Show a) => Proxy a -> Property
succPredBoundedIdentity _ = myForAllShrink False (\a -> a /= minBound)
(\(a :: a) -> ["a = " ++ show a])
"succ (pred x)"
(\a -> succ (pred a))
"x"
(\a -> a)
predSuccBoundedIdentity :: forall a. (Enum a, Bounded a, Eq a, Arbitrary a, Show a) => Proxy a -> Property
predSuccBoundedIdentity _ = myForAllShrink False (\a -> a /= maxBound)
(\(a :: a) -> ["a = " ++ show a])
"pred (succ x)"
(\a -> pred (succ a))
"x"
(\a -> a)