module Test.Validity.RelativeValidity
(
relativeValiditySpec
, relativeValidityImpliesValidA
, relativeValidityImpliesValidB
) where
import Data.Data
import Data.Proxy
import Data.GenRelativeValidity
import Data.GenValidity
import Test.Hspec
import Test.QuickCheck
import Test.Validity.Utils
relativeValiditySpec
:: (Typeable a, Typeable b,
Show a, Show b,
GenValidity a, GenValidity b, GenRelativeValidity a b)
=> Proxy a
-> Proxy b
-> Spec
relativeValiditySpec one two = do
let nameOne = nameOf one
nameTwo = nameOf two
describe ("RelativeValidity " ++ nameOne ++ " " ++ nameTwo) $
describe ("isValidFor :: "
++ nameOne
++ " -> "
++ nameTwo
++ " -> Bool") $ do
it ("implies isValid " ++ nameOne ++ " for any " ++ nameTwo) $
relativeValidityImpliesValidA one two
it ("implies isValid " ++ nameTwo ++ " for any " ++ nameOne) $
relativeValidityImpliesValidB one two
relativeValidityImpliesValidA
:: (Show a, Show b,
GenValidity a, GenValidity b, RelativeValidity a b)
=> Proxy a
-> Proxy b
-> Property
relativeValidityImpliesValidA one two =
forAll genUnchecked $ \a ->
forAll genUnchecked $ \b ->
not ((a `asProxyTypeOf` one) `isValidFor` (b `asProxyTypeOf` two))
|| isValid a
relativeValidityImpliesValidB
:: (Show a, Show b,
GenValidity a, GenValidity b, RelativeValidity a b)
=> Proxy a
-> Proxy b
-> Property
relativeValidityImpliesValidB one two =
forAll genUnchecked $ \a ->
forAll genUnchecked $ \b ->
not ((a `asProxyTypeOf` one) `isValidFor` (b `asProxyTypeOf` two))
|| isValid b