genvalidity-property-0.3.0.0/doctest/0000755000000000000000000000000013325040557015710 5ustar0000000000000000genvalidity-property-0.3.0.0/src/0000755000000000000000000000000013325040557015032 5ustar0000000000000000genvalidity-property-0.3.0.0/src/Test/0000755000000000000000000000000013325040557015751 5ustar0000000000000000genvalidity-property-0.3.0.0/src/Test/Validity/0000755000000000000000000000000013325040557017536 5ustar0000000000000000genvalidity-property-0.3.0.0/src/Test/Validity/Functions/0000755000000000000000000000000013325040557021506 5ustar0000000000000000genvalidity-property-0.3.0.0/src/Test/Validity/GenValidity/0000755000000000000000000000000013325040557021755 5ustar0000000000000000genvalidity-property-0.3.0.0/src/Test/Validity/Operations/0000755000000000000000000000000013370523751021663 5ustar0000000000000000genvalidity-property-0.3.0.0/src/Test/Validity/Property/0000755000000000000000000000000013370523751021364 5ustar0000000000000000genvalidity-property-0.3.0.0/src/Test/Validity/Relations/0000755000000000000000000000000013370523751021500 5ustar0000000000000000genvalidity-property-0.3.0.0/src/Test/Validity/Shrinking/0000755000000000000000000000000013370523751021474 5ustar0000000000000000genvalidity-property-0.3.0.0/src/Test/Validity/Functions.hs0000644000000000000000000000622413325040557022046 0ustar0000000000000000{-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE ScopedTypeVariables #-} -- | Validity tests involving functions module Test.Validity.Functions ( producesValidsOnGen , producesValidsOnValids , producesValid , producesValidsOnArbitrary , producesValidsOnGens2 , producesValidsOnValids2 , producesValid2 , producesValidsOnArbitrary2 , producesValidsOnGens3 , producesValidsOnValids3 , producesValid3 , producesValidsOnArbitrary3 , succeedsOnGen , succeedsOnValid , succeeds , succeedsOnArbitrary , succeedsOnGens2 , succeedsOnValids2 , succeeds2 , succeedsOnArbitrary2 , failsOnGen , failsOnInvalid , failsOnGens2 , failsOnInvalid2 , validIfSucceedsOnGen , validIfSucceedsOnValid , validIfSucceedsOnArbitrary , validIfSucceeds , validIfSucceedsOnGens2 , validIfSucceedsOnValids2 , validIfSucceeds2 , validIfSucceedsOnArbitrary2 , validIfSucceedsOnGens3 , validIfSucceedsOnValids3 , validIfSucceeds3 , validIfSucceedsOnArbitrary3 , equivalentOnGen , equivalentOnValid , equivalent , equivalentOnArbitrary , equivalentOnGens2 , equivalentOnValids2 , equivalent2 , equivalentOnArbitrary2 , equivalentWhenFirstSucceedsOnGen , equivalentWhenFirstSucceedsOnValid , equivalentWhenFirstSucceeds , equivalentWhenFirstSucceedsOnArbitrary , equivalentWhenFirstSucceedsOnGens2 , equivalentWhenFirstSucceedsOnValids2 , equivalentWhenFirstSucceeds2 , equivalentWhenFirstSucceedsOnArbitrary2 , equivalentWhenSecondSucceedsOnGen , equivalentWhenSecondSucceedsOnValid , equivalentWhenSecondSucceeds , equivalentWhenSecondSucceedsOnArbitrary , equivalentWhenSecondSucceedsOnGens2 , equivalentWhenSecondSucceedsOnValids2 , equivalentWhenSecondSucceeds2 , equivalentWhenSecondSucceedsOnArbitrary2 , equivalentWhenSucceedOnGen , equivalentWhenSucceedOnValid , equivalentWhenSucceed , equivalentWhenSucceedOnArbitrary , equivalentWhenSucceedOnGens2 , equivalentWhenSucceedOnValids2 , equivalentWhenSucceed2 , equivalentWhenSucceedOnArbitrary2 , equivalentOnGens3 , equivalentOnValids3 , equivalent3 , equivalentOnArbitrary3 , inverseFunctionsOnGen , inverseFunctionsOnValid , inverseFunctions , inverseFunctionsOnArbitrary , inverseFunctionsIfFirstSucceedsOnGen , inverseFunctionsIfFirstSucceedsOnValid , inverseFunctionsIfFirstSucceeds , inverseFunctionsIfFirstSucceedsOnArbitrary , inverseFunctionsIfSecondSucceedsOnGen , inverseFunctionsIfSecondSucceedsOnValid , inverseFunctionsIfSecondSucceeds , inverseFunctionsIfSecondSucceedsOnArbitrary , inverseFunctionsIfSucceedOnGen , inverseFunctionsIfSucceedOnValid , inverseFunctionsIfSucceed , inverseFunctionsIfSucceedOnArbitrary , idempotentOnGen , idempotentOnValid , idempotent , idempotentOnArbitrary ) where import Test.Validity.Functions.CanFail import Test.Validity.Functions.Equivalence import Test.Validity.Functions.Idempotence import Test.Validity.Functions.Inverse import Test.Validity.Functions.Validity genvalidity-property-0.3.0.0/src/Test/Validity/Functions/CanFail.hs0000644000000000000000000002006113325040557023336 0ustar0000000000000000{-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE ScopedTypeVariables #-} module Test.Validity.Functions.CanFail ( succeedsOnGen , succeedsOnValid , succeeds , succeedsOnArbitrary , succeedsOnGens2 , succeedsOnValids2 , succeeds2 , succeedsOnArbitrary2 , failsOnGen , failsOnInvalid , failsOnGens2 , failsOnInvalid2 , validIfSucceedsOnGen , validIfSucceedsOnValid , validIfSucceedsOnArbitrary , validIfSucceeds , validIfSucceedsOnGens2 , validIfSucceedsOnValids2 , validIfSucceeds2 , validIfSucceedsOnArbitrary2 , validIfSucceedsOnGens3 , validIfSucceedsOnValids3 , validIfSucceeds3 , validIfSucceedsOnArbitrary3 ) where import Data.GenValidity import Test.Hspec import Test.QuickCheck import Test.Validity.Types -- | The function succeeds if the input is generated by the given generator succeedsOnGen :: (Show a, Show b, Show (f b), CanFail f) => (a -> f b) -> Gen a -> (a -> [a]) -> Property succeedsOnGen func gen s = forAllShrink gen s $ \a -> func a `shouldSatisfy` (not . hasFailed) -- | The function succeeds if the input is generated by @genValid@ succeedsOnValid :: (Show a, Show b, Show (f b), GenValid a, CanFail f) => (a -> f b) -> Property succeedsOnValid f = succeedsOnGen f genValid shrinkValid -- | The function succeeds if the input is generated by @genUnchecked@ succeeds :: (Show a, Show b, Show (f b), GenUnchecked a, CanFail f) => (a -> f b) -> Property succeeds f = succeedsOnGen f genUnchecked shrinkUnchecked -- | The function succeeds if the input is generated by @arbitrary@ succeedsOnArbitrary :: (Show a, Show b, Show (f b), Arbitrary a, CanFail f) => (a -> f b) -> Property succeedsOnArbitrary f = succeedsOnGen f arbitrary shrink -- | The function fails if the input is generated by the given generator failsOnGen :: (Show a, Show b, Show (f b), CanFail f) => (a -> f b) -> Gen a -> (a -> [a]) -> Property failsOnGen func gen s = forAllShrink gen s $ \a -> func a `shouldSatisfy` hasFailed -- | The function fails if the input is generated by @genInvalid@ failsOnInvalid :: (Show a, Show b, Show (f b), GenInvalid a, CanFail f) => (a -> f b) -> Property failsOnInvalid f = failsOnGen f genInvalid shrinkInvalid -- | The function produces output that satisfies @isValid@ if it is given input -- that is generated by the given generator. validIfSucceedsOnGen :: (Show a, Show b, Show (f b), Validity b, CanFail f) => (a -> f b) -> Gen a -> (a -> [a]) -> Property validIfSucceedsOnGen func gen s = forAllShrink gen s $ \a -> case resultIfSucceeded (func a) of Nothing -> return () -- Can happen Just res -> res `shouldSatisfy` isValid -- | The function produces output that satisfies @isValid@ if it is given input -- that is generated by @arbitrary@. validIfSucceedsOnValid :: (Show a, Show b, Show (f b), GenValid a, Validity b, CanFail f) => (a -> f b) -> Property validIfSucceedsOnValid f = validIfSucceedsOnGen f genValid shrinkValid -- | The function produces output that satisfies @isValid@ if it is given input -- that is generated by @arbitrary@. validIfSucceedsOnArbitrary :: (Show a, Show b, Show (f b), Arbitrary a, Validity b, CanFail f) => (a -> f b) -> Property validIfSucceedsOnArbitrary f = validIfSucceedsOnGen f arbitrary shrink -- | The function produces output that satisfies @isValid@ if it is given input -- that is generated by @genUnchecked@. validIfSucceeds :: (Show a, Show b, Show (f b), GenUnchecked a, Validity b, CanFail f) => (a -> f b) -> Property validIfSucceeds f = validIfSucceedsOnGen f genUnchecked shrinkUnchecked succeedsOnGens2 :: (Show a, Show b, Show c, Show (f c), CanFail f) => (a -> b -> f c) -> Gen (a, b) -> ((a, b) -> [(a, b)]) -> Property succeedsOnGens2 func gen s = forAllShrink gen s $ \(a, b) -> func a b `shouldSatisfy` (not . hasFailed) succeedsOnValids2 :: (Show a, Show b, Show c, Show (f c), GenValid a, GenValid b, CanFail f) => (a -> b -> f c) -> Property succeedsOnValids2 func = succeedsOnGens2 func genValid shrinkValid succeeds2 :: ( Show a , Show b , Show c , Show (f c) , GenUnchecked a , GenUnchecked b , CanFail f ) => (a -> b -> f c) -> Property succeeds2 func = succeedsOnGens2 func genUnchecked shrinkUnchecked succeedsOnArbitrary2 :: (Show a, Show b, Show c, Show (f c), Arbitrary a, Arbitrary b, CanFail f) => (a -> b -> f c) -> Property succeedsOnArbitrary2 func = succeedsOnGens2 func arbitrary shrink failsOnGens2 :: (Show a, Show b, Show c, Show (f c), CanFail f) => (a -> b -> f c) -> Gen a -> (a -> [a]) -> Gen b -> (b -> [b]) -> Property failsOnGens2 func genA sA genB sB = forAllShrink genA sA $ \a -> forAllShrink genB sB $ \b -> func a b `shouldSatisfy` hasFailed failsOnInvalid2 :: ( Show a , Show b , Show c , Show (f c) , GenInvalid a , GenInvalid b , CanFail f ) => (a -> b -> f c) -> Property failsOnInvalid2 func = failsOnGens2 func genInvalid shrinkInvalid genUnchecked shrinkUnchecked .&&. failsOnGens2 func genUnchecked shrinkUnchecked genInvalid shrinkInvalid validIfSucceedsOnGens2 :: (Show a, Show b, Show c, Show (f c), Validity c, CanFail f) => (a -> b -> f c) -> Gen (a, b) -> ((a, b) -> [(a, b)]) -> Property validIfSucceedsOnGens2 func gen s = forAllShrink gen s $ \(a, b) -> case resultIfSucceeded (func a b) of Nothing -> return () -- Can happen Just res -> res `shouldSatisfy` isValid validIfSucceedsOnValids2 :: ( Show a , Show b , Show c , Show (f c) , GenValid a , GenValid b , Validity c , CanFail f ) => (a -> b -> f c) -> Property validIfSucceedsOnValids2 func = validIfSucceedsOnGens2 func genValid shrinkValid validIfSucceeds2 :: ( Show a , Show b , Show c , Show (f c) , GenUnchecked a , GenUnchecked b , Validity c , CanFail f ) => (a -> b -> f c) -> Property validIfSucceeds2 func = validIfSucceedsOnGens2 func genUnchecked shrinkUnchecked validIfSucceedsOnArbitrary2 :: ( Show a , Show b , Show c , Show (f c) , Arbitrary a , Arbitrary b , Validity c , CanFail f ) => (a -> b -> f c) -> Property validIfSucceedsOnArbitrary2 func = validIfSucceedsOnGens2 func arbitrary shrink validIfSucceedsOnGens3 :: (Show a, Show b, Show c, Show d, Show (f d), Validity d, CanFail f) => (a -> b -> c -> f d) -> Gen (a, b, c) -> ((a, b, c) -> [(a, b, c)]) -> Property validIfSucceedsOnGens3 func gen s = forAllShrink gen s $ \(a, b, c) -> case resultIfSucceeded (func a b c) of Nothing -> return () -- Can happen Just res -> res `shouldSatisfy` isValid validIfSucceedsOnValids3 :: ( Show a , Show b , Show c , Show d , Show (f d) , GenValid a , GenValid b , GenValid c , Validity d , CanFail f ) => (a -> b -> c -> f d) -> Property validIfSucceedsOnValids3 func = validIfSucceedsOnGens3 func genValid shrinkValid validIfSucceeds3 :: ( Show a , Show b , Show c , Show d , Show (f d) , GenUnchecked a , GenUnchecked b , GenUnchecked c , Validity d , CanFail f ) => (a -> b -> c -> f d) -> Property validIfSucceeds3 func = validIfSucceedsOnGens3 func genUnchecked shrinkUnchecked validIfSucceedsOnArbitrary3 :: ( Show a , Show b , Show c , Show d , Show (f d) , Arbitrary a , Arbitrary b , Arbitrary c , Validity d , CanFail f ) => (a -> b -> c -> f d) -> Property validIfSucceedsOnArbitrary3 func = validIfSucceedsOnGens3 func arbitrary shrink genvalidity-property-0.3.0.0/src/Test/Validity/Functions/Equivalence.hs0000644000000000000000000003027713325040557024314 0ustar0000000000000000{-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE ScopedTypeVariables #-} module Test.Validity.Functions.Equivalence ( equivalentOnGen , equivalentOnValid , equivalent , equivalentOnArbitrary , equivalentOnGens2 , equivalentOnValids2 , equivalent2 , equivalentOnArbitrary2 , equivalentWhenFirstSucceedsOnGen , equivalentWhenFirstSucceedsOnValid , equivalentWhenFirstSucceeds , equivalentWhenFirstSucceedsOnArbitrary , equivalentWhenFirstSucceedsOnGens2 , equivalentWhenFirstSucceedsOnValids2 , equivalentWhenFirstSucceeds2 , equivalentWhenFirstSucceedsOnArbitrary2 , equivalentWhenSecondSucceedsOnGen , equivalentWhenSecondSucceedsOnValid , equivalentWhenSecondSucceeds , equivalentWhenSecondSucceedsOnArbitrary , equivalentWhenSecondSucceedsOnGens2 , equivalentWhenSecondSucceedsOnValids2 , equivalentWhenSecondSucceeds2 , equivalentWhenSecondSucceedsOnArbitrary2 , equivalentWhenSucceedOnGen , equivalentWhenSucceedOnValid , equivalentWhenSucceed , equivalentWhenSucceedOnArbitrary , equivalentWhenSucceedOnGens2 , equivalentWhenSucceedOnValids2 , equivalentWhenSucceed2 , equivalentWhenSucceedOnArbitrary2 , equivalentOnGens3 , equivalentOnValids3 , equivalent3 , equivalentOnArbitrary3 ) where import Data.GenValidity import Test.Hspec import Test.QuickCheck import Test.Validity.Types equivalentOnGen :: (Show a, Eq a, Show b, Eq b) => (a -> b) -> (a -> b) -> Gen a -> (a -> [a]) -> Property equivalentOnGen f g gen s = forAllShrink gen s $ \a -> f a `shouldBe` g a equivalentOnValid :: (Show a, Eq a, GenValid a, Show b, Eq b) => (a -> b) -> (a -> b) -> Property equivalentOnValid f g = equivalentOnGen f g genValid shrinkValid equivalent :: (Show a, Eq a, GenUnchecked a, Show b, Eq b) => (a -> b) -> (a -> b) -> Property equivalent f g = equivalentOnGen f g genUnchecked shrinkUnchecked -- | -- -- prop> equivalentOnArbitrary ((* 2) . (+ 1)) ((+ 2) . (* 2) :: Int -> Int) equivalentOnArbitrary :: (Show a, Eq a, Arbitrary a, Show b, Eq b) => (a -> b) -> (a -> b) -> Property equivalentOnArbitrary f g = equivalentOnGen f g arbitrary shrink equivalentOnGens2 :: (Show a, Show b, Show c, Eq c) => (a -> b -> c) -> (a -> b -> c) -> Gen (a, b) -> ((a, b) -> [(a, b)]) -> Property equivalentOnGens2 f g gen s = forAllShrink gen s $ \(a, b) -> f a b `shouldBe` g a b equivalentOnValids2 :: (Show a, GenValid a, Show b, GenValid b, Show c, Eq c) => (a -> b -> c) -> (a -> b -> c) -> Property equivalentOnValids2 f g = equivalentOnGens2 f g genValid shrinkValid equivalent2 :: (Show a, GenUnchecked a, Show b, GenUnchecked b, Show c, Eq c) => (a -> b -> c) -> (a -> b -> c) -> Property equivalent2 f g = equivalentOnGens2 f g genUnchecked shrinkUnchecked -- | -- -- prop> equivalentOnArbitrary2 (+) ((+) :: Int -> Int -> Int) equivalentOnArbitrary2 :: (Show a, Arbitrary a, Show b, Arbitrary b, Show c, Eq c) => (a -> b -> c) -> (a -> b -> c) -> Property equivalentOnArbitrary2 f g = equivalentOnGens2 f g arbitrary shrink equivalentWhenFirstSucceedsOnGen :: (Show a, Eq a, Show b, Eq b, CanFail f) => (a -> f b) -> (a -> b) -> Gen a -> (a -> [a]) -> Property equivalentWhenFirstSucceedsOnGen f g gen s = forAllShrink gen s $ \a -> case resultIfSucceeded (f a) of Nothing -> return () -- fine Just r -> r `shouldBe` g a equivalentWhenFirstSucceedsOnValid :: (Show a, Eq a, GenValid a, Show b, Eq b, CanFail f) => (a -> f b) -> (a -> b) -> Property equivalentWhenFirstSucceedsOnValid f g = equivalentWhenFirstSucceedsOnGen f g genValid shrinkValid equivalentWhenFirstSucceedsOnArbitrary :: (Show a, Eq a, Arbitrary a, Show b, Eq b, CanFail f) => (a -> f b) -> (a -> b) -> Property equivalentWhenFirstSucceedsOnArbitrary f g = equivalentWhenFirstSucceedsOnGen f g arbitrary shrink equivalentWhenFirstSucceeds :: (Show a, Eq a, GenUnchecked a, Show b, Eq b, CanFail f) => (a -> f b) -> (a -> b) -> Property equivalentWhenFirstSucceeds f g = equivalentWhenFirstSucceedsOnGen f g genUnchecked shrinkUnchecked equivalentWhenFirstSucceedsOnGens2 :: (Show a, Eq a, Show b, Eq b, Show c, Eq c, CanFail f) => (a -> b -> f c) -> (a -> b -> c) -> Gen (a, b) -> ((a, b) -> [(a, b)]) -> Property equivalentWhenFirstSucceedsOnGens2 f g gen s = forAllShrink gen s $ \(a, b) -> case resultIfSucceeded (f a b) of Nothing -> return () -- fine Just rs -> rs `shouldBe` g a b equivalentWhenFirstSucceedsOnValids2 :: ( Show a , Eq a , GenValid a , Show b , Eq b , GenValid b , Show c , Eq c , CanFail f ) => (a -> b -> f c) -> (a -> b -> c) -> Property equivalentWhenFirstSucceedsOnValids2 f g = equivalentWhenFirstSucceedsOnGens2 f g genValid shrinkValid equivalentWhenFirstSucceedsOnArbitrary2 :: ( Show a , Eq a , Arbitrary a , Show b , Eq b , Arbitrary b , Show c , Eq c , CanFail f ) => (a -> b -> f c) -> (a -> b -> c) -> Property equivalentWhenFirstSucceedsOnArbitrary2 f g = equivalentWhenFirstSucceedsOnGens2 f g arbitrary shrink equivalentWhenFirstSucceeds2 :: ( Show a , Eq a , GenUnchecked a , Show b , Eq b , GenUnchecked b , Show c , Eq c , CanFail f ) => (a -> b -> f c) -> (a -> b -> c) -> Property equivalentWhenFirstSucceeds2 f g = equivalentWhenFirstSucceedsOnGens2 f g genUnchecked shrinkUnchecked equivalentWhenSecondSucceedsOnGen :: (Show a, Eq a, Show b, Eq b, CanFail f) => (a -> b) -> (a -> f b) -> Gen a -> (a -> [a]) -> Property equivalentWhenSecondSucceedsOnGen f g gen s = forAllShrink gen s $ \a -> case resultIfSucceeded (g a) of Nothing -> return () -- fine Just r -> r `shouldBe` f a equivalentWhenSecondSucceedsOnValid :: (Show a, Eq a, GenValid a, Show b, Eq b, CanFail f) => (a -> b) -> (a -> f b) -> Property equivalentWhenSecondSucceedsOnValid f g = equivalentWhenSecondSucceedsOnGen f g genValid shrinkValid equivalentWhenSecondSucceedsOnArbitrary :: (Show a, Eq a, Arbitrary a, Show b, Eq b, CanFail f) => (a -> b) -> (a -> f b) -> Property equivalentWhenSecondSucceedsOnArbitrary f g = equivalentWhenSecondSucceedsOnGen f g arbitrary shrink equivalentWhenSecondSucceeds :: (Show a, Eq a, GenUnchecked a, Show b, Eq b, CanFail f) => (a -> b) -> (a -> f b) -> Property equivalentWhenSecondSucceeds f g = equivalentWhenSecondSucceedsOnGen f g genUnchecked shrinkUnchecked equivalentWhenSecondSucceedsOnGens2 :: (Show a, Eq a, Show b, Eq b, Show c, Eq c, CanFail f) => (a -> b -> c) -> (a -> b -> f c) -> Gen (a, b) -> ((a, b) -> [(a, b)]) -> Property equivalentWhenSecondSucceedsOnGens2 f g gen s = forAllShrink gen s $ \(a, b) -> case resultIfSucceeded (g a b) of Nothing -> return () -- fine Just rs -> rs `shouldBe` f a b equivalentWhenSecondSucceedsOnValids2 :: ( Show a , Eq a , GenValid a , Show b , Eq b , GenValid b , Show c , Eq c , CanFail f ) => (a -> b -> c) -> (a -> b -> f c) -> Property equivalentWhenSecondSucceedsOnValids2 f g = equivalentWhenSecondSucceedsOnGens2 f g genValid shrinkValid equivalentWhenSecondSucceedsOnArbitrary2 :: ( Show a , Eq a , Arbitrary a , Show b , Eq b , Arbitrary b , Show c , Eq c , CanFail f ) => (a -> b -> c) -> (a -> b -> f c) -> Property equivalentWhenSecondSucceedsOnArbitrary2 f g = equivalentWhenSecondSucceedsOnGens2 f g arbitrary shrink equivalentWhenSecondSucceeds2 :: ( Show a , Eq a , GenUnchecked a , Show b , Eq b , GenUnchecked b , Show c , Eq c , CanFail f ) => (a -> b -> c) -> (a -> b -> f c) -> Property equivalentWhenSecondSucceeds2 f g = equivalentWhenSecondSucceedsOnGens2 f g genUnchecked shrinkUnchecked equivalentWhenSucceedOnGen :: (Show a, Eq a, Show b, Eq b, CanFail f) => (a -> f b) -> (a -> f b) -> Gen a -> (a -> [a]) -> Property equivalentWhenSucceedOnGen f g gen s = forAllShrink gen s $ \a -> case do fa <- resultIfSucceeded $ f a ga <- resultIfSucceeded $ g a return (fa, ga) of Nothing -> return () -- fine Just (fa, ga) -> fa `shouldBe` ga equivalentWhenSucceedOnValid :: (Show a, Eq a, GenValid a, Show b, Eq b, CanFail f) => (a -> f b) -> (a -> f b) -> Property equivalentWhenSucceedOnValid f g = equivalentWhenSucceedOnGen f g genValid shrinkValid equivalentWhenSucceed :: (Show a, Eq a, GenUnchecked a, Show b, Eq b, CanFail f) => (a -> f b) -> (a -> f b) -> Property equivalentWhenSucceed f g = equivalentWhenSucceedOnGen f g genUnchecked shrinkUnchecked equivalentWhenSucceedOnArbitrary :: (Show a, Eq a, Arbitrary a, Show b, Eq b, CanFail f) => (a -> f b) -> (a -> f b) -> Property equivalentWhenSucceedOnArbitrary f g = equivalentWhenSucceedOnGen f g arbitrary shrink equivalentWhenSucceedOnGens2 :: (Show a, Eq a, Show b, Eq b, Show c, Eq c, CanFail f) => (a -> b -> f c) -> (a -> b -> f c) -> Gen (a, b) -> ((a, b) -> [(a, b)]) -> Property equivalentWhenSucceedOnGens2 f g gen s = forAllShrink gen s $ \(a, b) -> case do fab <- resultIfSucceeded $ f a b gab <- resultIfSucceeded $ g a b return (fab, gab) of Nothing -> return () -- fine Just (fab, gab) -> fab `shouldBe` gab equivalentWhenSucceedOnValids2 :: ( Show a , Eq a , GenValid a , Show b , Eq b , GenValid b , Show c , Eq c , CanFail f ) => (a -> b -> f c) -> (a -> b -> f c) -> Property equivalentWhenSucceedOnValids2 f g = equivalentWhenSucceedOnGens2 f g genValid shrinkValid equivalentWhenSucceedOnArbitrary2 :: ( Show a , Eq a , Arbitrary a , Show b , Eq b , Arbitrary b , Show c , Eq c , CanFail f ) => (a -> b -> f c) -> (a -> b -> f c) -> Property equivalentWhenSucceedOnArbitrary2 f g = equivalentWhenSucceedOnGens2 f g arbitrary shrink equivalentWhenSucceed2 :: ( Show a , Eq a , GenUnchecked a , Show b , Eq b , GenUnchecked b , Show c , Eq c , CanFail f ) => (a -> b -> f c) -> (a -> b -> f c) -> Property equivalentWhenSucceed2 f g = equivalentWhenSucceedOnGens2 f g genUnchecked shrinkUnchecked equivalentOnGens3 :: (Show a, Show b, Show c, Show d, Eq d) => (a -> b -> c -> d) -> (a -> b -> c -> d) -> Gen (a, b, c) -> ((a, b, c) -> [(a, b, c)]) -> Property equivalentOnGens3 f g gen s = forAllShrink gen s $ \(a, b, c) -> f a b c `shouldBe` g a b c equivalentOnValids3 :: ( Show a , GenValid a , Show b , GenValid b , Show c , GenValid c , Show d , Eq d ) => (a -> b -> c -> d) -> (a -> b -> c -> d) -> Property equivalentOnValids3 f g = equivalentOnGens3 f g genValid shrinkValid equivalent3 :: ( Show a , GenUnchecked a , Show b , GenUnchecked b , Show c , GenUnchecked c , Show d , Eq d ) => (a -> b -> c -> d) -> (a -> b -> c -> d) -> Property equivalent3 f g = equivalentOnGens3 f g genUnchecked shrinkUnchecked equivalentOnArbitrary3 :: ( Show a , Arbitrary a , Show b , Arbitrary b , Show c , Arbitrary c , Show d , Eq d ) => (a -> b -> c -> d) -> (a -> b -> c -> d) -> Property equivalentOnArbitrary3 f g = equivalentOnGens3 f g arbitrary shrink genvalidity-property-0.3.0.0/src/Test/Validity/Functions/Idempotence.hs0000644000000000000000000000216713325040557024304 0ustar0000000000000000{-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE ScopedTypeVariables #-} -- | Standard tests involving validity module Test.Validity.Functions.Idempotence ( idempotentOnGen , idempotentOnValid , idempotent , idempotentOnArbitrary ) where import Data.GenValidity import Test.Hspec import Test.QuickCheck idempotentOnGen :: (Show a, Eq a) => (a -> a) -> Gen a -> (a -> [a]) -> Property idempotentOnGen f gen s = forAllShrink gen s $ \a -> f (f a) `shouldBe` f a idempotentOnValid :: (Show a, Eq a, GenValid a) => (a -> a) -> Property idempotentOnValid func = idempotentOnGen func genValid shrinkValid idempotent :: (Show a, Eq a, GenUnchecked a) => (a -> a) -> Property idempotent func = idempotentOnGen func genUnchecked shrinkUnchecked -- | -- -- 'id' is idempotent for any type: -- -- prop> idempotentOnArbitrary (id :: Int -> Int) -- -- 'const', given any input, is idempotent for any type as well: -- -- prop> \int -> idempotentOnArbitrary (const int :: Int -> Int) idempotentOnArbitrary :: (Show a, Eq a, Arbitrary a) => (a -> a) -> Property idempotentOnArbitrary func = idempotentOnGen func arbitrary shrink genvalidity-property-0.3.0.0/src/Test/Validity/Functions/Inverse.hs0000644000000000000000000001174213325040557023462 0ustar0000000000000000{-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE ScopedTypeVariables #-} -- | Standard tests involving inverse functions module Test.Validity.Functions.Inverse ( inverseFunctionsOnGen , inverseFunctionsOnValid , inverseFunctions , inverseFunctionsOnArbitrary , inverseFunctionsIfFirstSucceedsOnGen , inverseFunctionsIfFirstSucceedsOnValid , inverseFunctionsIfFirstSucceeds , inverseFunctionsIfFirstSucceedsOnArbitrary , inverseFunctionsIfSecondSucceedsOnGen , inverseFunctionsIfSecondSucceedsOnValid , inverseFunctionsIfSecondSucceeds , inverseFunctionsIfSecondSucceedsOnArbitrary , inverseFunctionsIfSucceedOnGen , inverseFunctionsIfSucceedOnValid , inverseFunctionsIfSucceed , inverseFunctionsIfSucceedOnArbitrary ) where import Data.GenValidity import Test.Hspec import Test.QuickCheck import Test.Validity.Types inverseFunctionsOnGen :: (Show a, Eq a) => (a -> b) -> (b -> a) -> Gen a -> (a -> [a]) -> Property inverseFunctionsOnGen f g gen s = forAllShrink gen s $ \a -> g (f a) `shouldBe` a inverseFunctionsOnValid :: (Show a, Eq a, GenValid a) => (a -> b) -> (b -> a) -> Property inverseFunctionsOnValid f g = inverseFunctionsOnGen f g genValid shrinkValid inverseFunctions :: (Show a, Eq a, GenUnchecked a) => (a -> b) -> (b -> a) -> Property inverseFunctions f g = inverseFunctionsOnGen f g genUnchecked shrinkUnchecked -- | -- 'id' is its own inverse function for every type: -- prop> inverseFunctionsOnArbitrary id (id :: Int -> Int) inverseFunctionsOnArbitrary :: (Show a, Eq a, Arbitrary a) => (a -> b) -> (b -> a) -> Property inverseFunctionsOnArbitrary f g = inverseFunctionsOnGen f g arbitrary shrink inverseFunctionsIfFirstSucceedsOnGen :: (Show a, Eq a, CanFail f) => (a -> f b) -> (b -> a) -> Gen a -> (a -> [a]) -> Property inverseFunctionsIfFirstSucceedsOnGen f g gen s = forAllShrink gen s $ \a -> case resultIfSucceeded (f a) of Nothing -> return () -- fine Just b -> g b `shouldBe` a inverseFunctionsIfFirstSucceedsOnValid :: (Show a, Eq a, GenValid a, CanFail f) => (a -> f b) -> (b -> a) -> Property inverseFunctionsIfFirstSucceedsOnValid f g = inverseFunctionsIfFirstSucceedsOnGen f g genValid shrinkValid inverseFunctionsIfFirstSucceeds :: (Show a, Eq a, GenUnchecked a, CanFail f) => (a -> f b) -> (b -> a) -> Property inverseFunctionsIfFirstSucceeds f g = inverseFunctionsIfFirstSucceedsOnGen f g genUnchecked shrinkUnchecked inverseFunctionsIfFirstSucceedsOnArbitrary :: (Show a, Eq a, Arbitrary a, CanFail f) => (a -> f b) -> (b -> a) -> Property inverseFunctionsIfFirstSucceedsOnArbitrary f g = inverseFunctionsIfFirstSucceedsOnGen f g arbitrary shrink inverseFunctionsIfSecondSucceedsOnGen :: (Show a, Eq a, CanFail f) => (a -> b) -> (b -> f a) -> Gen a -> (a -> [a]) -> Property inverseFunctionsIfSecondSucceedsOnGen f g gen s = forAllShrink gen s $ \a -> case resultIfSucceeded (g (f a)) of Nothing -> return () -- fine Just r -> r `shouldBe` a inverseFunctionsIfSecondSucceedsOnValid :: (Show a, Eq a, GenValid a, CanFail f) => (a -> b) -> (b -> f a) -> Property inverseFunctionsIfSecondSucceedsOnValid f g = inverseFunctionsIfSecondSucceedsOnGen f g genValid shrinkValid inverseFunctionsIfSecondSucceeds :: (Show a, Eq a, GenUnchecked a, CanFail f) => (a -> b) -> (b -> f a) -> Property inverseFunctionsIfSecondSucceeds f g = inverseFunctionsIfSecondSucceedsOnGen f g genUnchecked shrinkUnchecked inverseFunctionsIfSecondSucceedsOnArbitrary :: (Show a, Eq a, Arbitrary a, CanFail f) => (a -> b) -> (b -> f a) -> Property inverseFunctionsIfSecondSucceedsOnArbitrary f g = inverseFunctionsIfSecondSucceedsOnGen f g arbitrary shrink inverseFunctionsIfSucceedOnGen :: (Show a, Eq a, CanFail f, CanFail g) => (a -> f b) -> (b -> g a) -> Gen a -> (a -> [a]) -> Property inverseFunctionsIfSucceedOnGen f g gen s = forAllShrink gen s $ \a -> case do fa <- resultIfSucceeded $ f a resultIfSucceeded $ g fa of Nothing -> return () -- fine Just r -> r `shouldBe` a inverseFunctionsIfSucceedOnValid :: (Show a, Eq a, GenValid a, CanFail f, CanFail g) => (a -> f b) -> (b -> g a) -> Property inverseFunctionsIfSucceedOnValid f g = inverseFunctionsIfSucceedOnGen f g genValid shrinkValid inverseFunctionsIfSucceed :: (Show a, Eq a, GenUnchecked a, CanFail f, CanFail g) => (a -> f b) -> (b -> g a) -> Property inverseFunctionsIfSucceed f g = inverseFunctionsIfSucceedOnGen f g genUnchecked shrinkUnchecked inverseFunctionsIfSucceedOnArbitrary :: (Show a, Eq a, Arbitrary a, CanFail f, CanFail g) => (a -> f b) -> (b -> g a) -> Property inverseFunctionsIfSucceedOnArbitrary f g = inverseFunctionsIfSucceedOnGen f g arbitrary shrink genvalidity-property-0.3.0.0/src/Test/Validity/Functions/Validity.hs0000644000000000000000000000723713325040557023640 0ustar0000000000000000{-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE ScopedTypeVariables #-} -- | Standard tests involving validity module Test.Validity.Functions.Validity ( producesValidsOnGen , producesValidsOnValids , producesValid , producesValidsOnArbitrary , producesValidsOnGens2 , producesValidsOnValids2 , producesValid2 , producesValidsOnArbitrary2 , producesValidsOnGens3 , producesValidsOnValids3 , producesValid3 , producesValidsOnArbitrary3 ) where import Data.GenValidity import Test.QuickCheck import Test.Validity.Property.Utils -- | The function produces valid output when the input is generated as -- specified by the given generator. producesValidsOnGen :: forall a b. (Show a, Show b, Validity b) => (a -> b) -> Gen a -> (a -> [a]) -> Property producesValidsOnGen func gen s = forAllShrink gen s $ shouldBeValid . func -- | The function produces valid output when the input is generated by -- @genValid@ producesValidsOnValids :: (Show a, Show b, GenValid a, Validity b) => (a -> b) -> Property producesValidsOnValids f = producesValidsOnGen f genValid shrinkValid -- | The function produces valid output when the input is generated by -- @genUnchecked@ producesValid :: (Show a, Show b, GenUnchecked a, Validity b) => (a -> b) -> Property producesValid f = producesValidsOnGen f genUnchecked shrinkUnchecked -- | The function produces valid output when the input is generated by -- @arbitrary@ producesValidsOnArbitrary :: (Show a, Show b, Arbitrary a, Validity b) => (a -> b) -> Property producesValidsOnArbitrary f = producesValidsOnGen f arbitrary shrink producesValidsOnGens2 :: (Show a, Show b, Show c, Validity c) => (a -> b -> c) -> Gen (a, b) -> ((a, b) -> [(a, b)]) -> Property producesValidsOnGens2 func gen s = forAllShrink gen s $ \(a, b) -> shouldBeValid $ func a b producesValidsOnValids2 :: (Show a, Show b, Show c, GenValid a, GenValid b, Validity c) => (a -> b -> c) -> Property producesValidsOnValids2 func = producesValidsOnGens2 func genValid shrinkValid producesValid2 :: (Show a, Show b, Show c, GenUnchecked a, GenUnchecked b, Validity c) => (a -> b -> c) -> Property producesValid2 func = producesValidsOnGens2 func genUnchecked shrinkUnchecked producesValidsOnArbitrary2 :: (Show a, Show b, Show c, Arbitrary a, Arbitrary b, Validity c) => (a -> b -> c) -> Property producesValidsOnArbitrary2 func = producesValidsOnGens2 func arbitrary shrink producesValidsOnGens3 :: (Show a, Show b, Show c, Show d, Validity d) => (a -> b -> c -> d) -> Gen (a, b, c) -> ((a, b, c) -> [(a, b, c)]) -> Property producesValidsOnGens3 func gen s = forAllShrink gen s $ \(a, b, c) -> shouldBeValid $ func a b c producesValidsOnValids3 :: ( Show a , Show b , Show c , Show d , GenValid a , GenValid b , GenValid c , Validity d ) => (a -> b -> c -> d) -> Property producesValidsOnValids3 func = producesValidsOnGens3 func genValid shrinkValid producesValid3 :: ( Show a , Show b , Show c , Show d , GenUnchecked a , GenUnchecked b , GenUnchecked c , Validity d ) => (a -> b -> c -> d) -> Property producesValid3 func = producesValidsOnGens3 func genUnchecked shrinkUnchecked producesValidsOnArbitrary3 :: ( Show a , Show b , Show c , Show d , Arbitrary a , Arbitrary b , Arbitrary c , Validity d ) => (a -> b -> c -> d) -> Property producesValidsOnArbitrary3 func = producesValidsOnGens3 func arbitrary shrink genvalidity-property-0.3.0.0/src/Test/Validity/GenValidity/Property.hs0000644000000000000000000000144213325040557024136 0ustar0000000000000000{-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE AllowAmbiguousTypes #-} {-# LANGUAGE ScopedTypeVariables #-} -- | Tests for GenValidity instances module Test.Validity.GenValidity.Property ( genGeneratesValid , genGeneratesInvalid ) where import Data.GenValidity import Test.Hspec import Test.QuickCheck -- | The given generator generates only valid data points genGeneratesValid :: forall a. (Show a, Validity a) => Gen a -> (a -> [a]) -> Property genGeneratesValid gen s = forAllShrink gen s (`shouldSatisfy` isValid) -- | The given generator generates only invalid data points genGeneratesInvalid :: forall a. (Show a, Validity a) => Gen a -> (a -> [a]) -> Property genGeneratesInvalid gen s = forAllShrink gen s (`shouldSatisfy` isInvalid) genvalidity-property-0.3.0.0/src/Test/Validity/Operations.hs0000644000000000000000000000162013325040557022214 0ustar0000000000000000{-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE ScopedTypeVariables #-} -- | Properties of operations module Test.Validity.Operations ( leftIdentityOnElemWithEquality , leftIdentityOnGenWithEquality , leftIdentityOnGen , leftIdentityOnValid , leftIdentity , leftIdentityOnArbitrary , rightIdentityOnElemWithEquality , rightIdentityOnGenWithEquality , rightIdentityOnGen , rightIdentityOnValid , rightIdentity , rightIdentityOnArbitrary , identityOnGen , identityOnValid , identity , identityOnArbitrary , associativeOnGens , associativeOnValids , associative , associativeOnArbitrary , commutativeOnGens , commutativeOnValids , commutative , commutativeOnArbitrary ) where import Test.Validity.Operations.Associativity import Test.Validity.Operations.Commutativity import Test.Validity.Operations.Identity genvalidity-property-0.3.0.0/src/Test/Validity/Operations/Associativity.hs0000644000000000000000000000254613325040557025057 0ustar0000000000000000{-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE ScopedTypeVariables #-} module Test.Validity.Operations.Associativity ( associativeOnGens , associativeOnValids , associative , associativeOnArbitrary ) where import Data.GenValidity import Test.Hspec import Test.QuickCheck -- | -- -- \[ -- Associative(\star) -- \quad\equiv\quad -- \forall a, b, c: -- (a \star b) \star c = a \star (b \star c) -- \] associativeOnGens :: (Show a, Eq a) => (a -> a -> a) -> Gen (a, a, a) -> ((a, a, a) -> [(a, a, a)]) -> Property associativeOnGens op gen s = forAllShrink gen s $ \(a, b, c) -> ((a `op` b) `op` c) `shouldBe` (a `op` (b `op` c)) associativeOnValids :: (Show a, Eq a, GenValid a) => (a -> a -> a) -> Property associativeOnValids op = associativeOnGens op genValid shrinkValid -- | -- -- prop> associative ((*) :: Int -> Int -> Int) -- prop> associative ((+) :: Int -> Int -> Int) associative :: (Show a, Eq a, GenUnchecked a) => (a -> a -> a) -> Property associative op = associativeOnGens op genUnchecked shrinkUnchecked -- | -- -- prop> associativeOnArbitrary ((*) :: Int -> Int -> Int) -- prop> associativeOnArbitrary ((+) :: Int -> Int -> Int) associativeOnArbitrary :: (Show a, Eq a, Arbitrary a) => (a -> a -> a) -> Property associativeOnArbitrary op = associativeOnGens op arbitrary shrink genvalidity-property-0.3.0.0/src/Test/Validity/Operations/Commutativity.hs0000644000000000000000000000267713370523751025111 0ustar0000000000000000{-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE ScopedTypeVariables #-} module Test.Validity.Operations.Commutativity ( commutativeOnGens , commutativeOnValids , commutative , commutativeOnArbitrary ) where import Data.GenValidity import Test.Hspec import Test.QuickCheck -- | -- -- \[ -- Commutative(\star) -- \quad\equiv\quad -- \forall a, b: -- a \star b = b \star a -- \] commutativeOnGens :: (Show a, Eq a) => (a -> a -> a) -> Gen (a, a) -> ((a, a) -> [(a, a)]) -> Property commutativeOnGens op gen s = forAllShrink gen s $ \(a, b) -> (a `op` b) `shouldBe` (b `op` a) -- | -- -- prop> commutativeOnValids ((+) :: Rational -> Rational -> Rational) -- prop> commutativeOnValids ((*) :: Rational -> Rational -> Rational) commutativeOnValids :: (Show a, Eq a, GenValid a) => (a -> a -> a) -> Property commutativeOnValids op = commutativeOnGens op genValid shrinkValid -- | -- -- prop> commutative ((+) :: Int -> Int -> Int) -- prop> commutative ((*) :: Int -> Int -> Int) commutative :: (Show a, Eq a, GenUnchecked a) => (a -> a -> a) -> Property commutative op = commutativeOnGens op genUnchecked shrinkUnchecked -- | -- -- prop> commutativeOnArbitrary ((+) :: Int -> Int -> Int) -- prop> commutativeOnArbitrary ((*) :: Int -> Int -> Int) commutativeOnArbitrary :: (Show a, Eq a, Arbitrary a) => (a -> a -> a) -> Property commutativeOnArbitrary op = commutativeOnGens op arbitrary shrink genvalidity-property-0.3.0.0/src/Test/Validity/Operations/Identity.hs0000644000000000000000000001173313370523751024015 0ustar0000000000000000{-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE ScopedTypeVariables #-} module Test.Validity.Operations.Identity ( leftIdentityOnElemWithEquality , leftIdentityOnGenWithEquality , leftIdentityOnGen , leftIdentityOnValid , leftIdentity , leftIdentityOnArbitrary , rightIdentityOnElemWithEquality , rightIdentityOnGenWithEquality , rightIdentityOnGen , rightIdentityOnValid , rightIdentity , rightIdentityOnArbitrary , identityOnGen , identityOnValid , identity , identityOnArbitrary ) where import Data.GenValidity import Test.QuickCheck -- | -- -- \[ -- LeftIdentity(\star, \doteq, b) -- \quad\equiv\quad -- \forall a: (b \star a) \doteq a -- \] leftIdentityOnElemWithEquality :: (b -> a -> a) -- ^ A binary operation -> (a -> a -> Bool) -- ^ An equality -> b -- ^ A candidate left-identity -> a -- ^ An element -> Bool leftIdentityOnElemWithEquality op eq b a = (b `op` a) `eq` a leftIdentityOnGenWithEquality :: Show a => (b -> a -> a) -- ^ A binary operation -> (a -> a -> Bool) -- ^ An equality -> b -- ^ A candidate left-identity -> Gen a -> (a -> [a]) -> Property leftIdentityOnGenWithEquality op eq b gen s = forAllShrink gen s $ leftIdentityOnElemWithEquality op eq b leftIdentityOnGen :: (Show a, Eq a) => (b -> a -> a) -- ^ A binary operation -> b -- ^ A candidate left-identity -> Gen a -> (a -> [a]) -> Property leftIdentityOnGen op = leftIdentityOnGenWithEquality op (==) -- | -- -- prop> leftIdentityOnValid (flip ((^) :: Rational -> Int -> Rational)) 1 leftIdentityOnValid :: (Show a, Eq a, GenValid a) => (b -> a -> a) -> b -> Property leftIdentityOnValid op b = leftIdentityOnGen op b genValid shrinkValid -- | -- -- prop> leftIdentity (flip ((^) :: Int -> Int -> Int)) 1 leftIdentity :: (Show a, Eq a, GenUnchecked a) => (b -> a -> a) -> b -> Property leftIdentity op b = leftIdentityOnGen op b genUnchecked shrinkUnchecked -- | -- -- prop> leftIdentityOnArbitrary (flip ((^) :: Int -> Int -> Int)) 1 leftIdentityOnArbitrary :: (Show a, Eq a, Arbitrary a) => (b -> a -> a) -> b -> Property leftIdentityOnArbitrary op b = leftIdentityOnGen op b arbitrary shrink -- | -- -- \[ -- RightIdentity(\star, \doteq, b) -- \quad\equiv\quad -- \forall a: (a \star b) \doteq a -- \] rightIdentityOnElemWithEquality :: (a -> b -> a) -- ^ A binary operation -> (a -> a -> Bool) -- ^ An equality -> b -- ^ A candidate right-identity -> a -- ^ An element -> Bool rightIdentityOnElemWithEquality op eq b a = (a `op` b) `eq` a rightIdentityOnGenWithEquality :: Show a => (a -> b -> a) -- ^ A binary operation -> (a -> a -> Bool) -- ^ An equality -> b -- ^ A candidate right-identity -> Gen a -> (a -> [a]) -> Property rightIdentityOnGenWithEquality op eq b gen s = forAllShrink gen s $ rightIdentityOnElemWithEquality op eq b rightIdentityOnGen :: (Show a, Eq a) => (a -> b -> a) -- ^ A binary operation -> b -- ^ A candidate right-identity -> Gen a -> (a -> [a]) -> Property rightIdentityOnGen op = rightIdentityOnGenWithEquality op (==) -- | -- -- prop> rightIdentityOnValid ((^) :: Rational -> Int -> Rational) 1 rightIdentityOnValid :: (Show a, Eq a, GenValid a) => (a -> b -> a) -> b -> Property rightIdentityOnValid op b = rightIdentityOnGen op b genValid shrinkValid -- | -- -- prop> rightIdentity ((^) :: Int -> Int -> Int) 1 rightIdentity :: (Show a, Eq a, GenUnchecked a) => (a -> b -> a) -> b -> Property rightIdentity op b = rightIdentityOnGen op b genUnchecked shrinkUnchecked -- | -- -- prop> rightIdentityOnArbitrary ((^) :: Int -> Int -> Int) 1 rightIdentityOnArbitrary :: (Show a, Eq a, Arbitrary a) => (a -> b -> a) -> b -> Property rightIdentityOnArbitrary op b = rightIdentityOnGen op b arbitrary shrink -- | -- -- \[ -- Identity(\star, \doteq, b) -- \quad\equiv\quad -- LeftIdentity(\star, \doteq, b) \wedge RightIdentity(\star, \doteq, b) -- \] identityOnGen :: (Show a, Eq a) => (a -> a -> a) -> a -> Gen a -> (a -> [a]) -> Property identityOnGen op e gen s = leftIdentityOnGen op e gen s .&&. rightIdentityOnGen op e gen s -- | -- -- prop> identityOnValid ((*) :: Rational -> Rational -> Rational) 1 -- prop> identityOnValid ((+) :: Rational -> Rational -> Rational) 0 identityOnValid :: (Show a, Eq a, GenValid a) => (a -> a -> a) -> a -> Property identityOnValid op a = identityOnGen op a genValid shrinkValid -- | -- -- prop> identity ((*) :: Int -> Int -> Int) 1 -- prop> identity ((+) :: Int -> Int -> Int) 0 identity :: (Show a, Eq a, GenUnchecked a) => (a -> a -> a) -> a -> Property identity op e = identityOnGen op e genUnchecked shrinkUnchecked -- | -- -- prop> identityOnArbitrary ((*) :: Int -> Int -> Int) 1 -- prop> identityOnArbitrary ((+) :: Int -> Int -> Int) 0 identityOnArbitrary :: (Show a, Eq a, Arbitrary a) => (a -> a -> a) -> a -> Property identityOnArbitrary op a = identityOnGen op a arbitrary shrink genvalidity-property-0.3.0.0/src/Test/Validity/Property.hs0000644000000000000000000001316313325040557021722 0ustar0000000000000000{-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE ScopedTypeVariables #-} module Test.Validity.Property ( module Data.GenValidity , forAllUnchecked , forAllValid , forAllInvalid -- * Tests for GenValidity instances , genGeneratesValid , genGeneratesInvalid -- * Standard tests involving functions -- ** Standard tests involving validity , producesValidsOnGen , producesValidsOnValids , producesValid , producesValidsOnArbitrary , producesValidsOnGens2 , producesValidsOnValids2 , producesValid2 , producesValidsOnArbitrary2 , producesValidsOnGens3 , producesValidsOnValids3 , producesValid3 , producesValidsOnArbitrary3 -- ** Standard tests involving functions that can fail , CanFail(..) , succeedsOnGen , succeedsOnValid , succeeds , succeedsOnArbitrary , succeedsOnGens2 , succeedsOnValids2 , succeeds2 , succeedsOnArbitrary2 , failsOnGen , failsOnInvalid , failsOnGens2 , failsOnInvalid2 , validIfSucceedsOnGen , validIfSucceedsOnValid , validIfSucceedsOnArbitrary , validIfSucceeds , validIfSucceedsOnGens2 , validIfSucceedsOnValids2 , validIfSucceeds2 , validIfSucceedsOnArbitrary2 , validIfSucceedsOnGens3 , validIfSucceedsOnValids3 , validIfSucceeds3 , validIfSucceedsOnArbitrary3 -- ** Standard tests involving equivalence of functions -- *** Simple functions -- **** One argument , equivalentOnGen , equivalentOnValid , equivalent , equivalentOnArbitrary -- **** Two arguments , equivalentOnGens2 , equivalentOnValids2 , equivalent2 , equivalentOnArbitrary2 -- **** Three arguments , equivalentOnGens3 , equivalentOnValids3 , equivalent3 , equivalentOnArbitrary3 -- *** First function can fail -- **** One argument , equivalentWhenFirstSucceedsOnGen , equivalentWhenFirstSucceedsOnValid , equivalentWhenFirstSucceeds , equivalentWhenFirstSucceedsOnArbitrary -- **** Two arguments , equivalentWhenFirstSucceedsOnGens2 , equivalentWhenFirstSucceedsOnValids2 , equivalentWhenFirstSucceeds2 , equivalentWhenFirstSucceedsOnArbitrary2 -- *** Second function can fail -- **** One argument , equivalentWhenSecondSucceedsOnGen , equivalentWhenSecondSucceedsOnValid , equivalentWhenSecondSucceeds , equivalentWhenSecondSucceedsOnArbitrary -- **** Two arguments , equivalentWhenSecondSucceedsOnGens2 , equivalentWhenSecondSucceedsOnValids2 , equivalentWhenSecondSucceeds2 , equivalentWhenSecondSucceedsOnArbitrary2 -- *** Both functions can fail -- **** One argument , equivalentWhenSucceedOnGen , equivalentWhenSucceedOnValid , equivalentWhenSucceed , equivalentWhenSucceedOnArbitrary -- **** Two arguments , equivalentWhenSucceedOnGens2 , equivalentWhenSucceedOnValids2 , equivalentWhenSucceed2 , equivalentWhenSucceedOnArbitrary2 -- ** Standard tests involving inverse functions , inverseFunctionsOnGen , inverseFunctionsOnValid , inverseFunctions , inverseFunctionsOnArbitrary , inverseFunctionsIfFirstSucceedsOnGen , inverseFunctionsIfFirstSucceedsOnValid , inverseFunctionsIfFirstSucceeds , inverseFunctionsIfFirstSucceedsOnArbitrary , inverseFunctionsIfSecondSucceedsOnGen , inverseFunctionsIfSecondSucceedsOnValid , inverseFunctionsIfSecondSucceeds , inverseFunctionsIfSecondSucceedsOnArbitrary , inverseFunctionsIfSucceedOnGen , inverseFunctionsIfSucceedOnValid , inverseFunctionsIfSucceed , inverseFunctionsIfSucceedOnArbitrary -- ** Properties involving idempotence , idempotentOnGen , idempotentOnValid , idempotent , idempotentOnArbitrary -- * Properties of relations -- ** Reflexivity , reflexiveOnElem , reflexivityOnGen , reflexivityOnValid , reflexivity , reflexivityOnArbitrary -- ** Transitivity , transitiveOnElems , transitivityOnGens , transitivityOnValid , transitivity , transitivityOnArbitrary -- ** Antisymmetry , antisymmetricOnElemsWithEquality , antisymmetryOnGensWithEquality , antisymmetryOnGens , antisymmetryOnValid , antisymmetry , antisymmetryOnArbitrary -- ** Antireflexivity , antireflexiveOnElem , antireflexivityOnGen , antireflexivityOnValid , antireflexivity , antireflexivityOnArbitrary -- ** Symmetry , symmetricOnElems , symmetryOnGens , symmetryOnValid , symmetry , symmetryOnArbitrary -- * Properties of operations -- ** Identity element -- *** Left Identity , leftIdentityOnElemWithEquality , leftIdentityOnGenWithEquality , leftIdentityOnGen , leftIdentityOnValid , leftIdentity , leftIdentityOnArbitrary -- *** Right Identity , rightIdentityOnElemWithEquality , rightIdentityOnGenWithEquality , rightIdentityOnGen , rightIdentityOnValid , rightIdentity , rightIdentityOnArbitrary -- *** Identity , identityOnGen , identityOnValid , identity , identityOnArbitrary -- ** Associativity , associativeOnGens , associativeOnValids , associative , associativeOnArbitrary -- ** Commutativity , commutativeOnGens , commutativeOnValids , commutative , commutativeOnArbitrary ) where import Data.GenValidity import Test.Validity.Functions import Test.Validity.GenValidity.Property import Test.Validity.Operations import Test.Validity.Property.Utils import Test.Validity.Relations import Test.Validity.Types genvalidity-property-0.3.0.0/src/Test/Validity/Property/Utils.hs0000644000000000000000000000316113370523751023021 0ustar0000000000000000{-# LANGUAGE CPP #-} module Test.Validity.Property.Utils ( forAllUnchecked , forAllValid , forAllInvalid , shouldBeValid , shouldBeInvalid , (<==>) , (===>) ) where import Data.GenValidity import Test.Hspec import Test.QuickCheck #if !MIN_VERSION_base(4,8,0) import Control.Applicative (pure) #endif forAllUnchecked :: (Show a, GenUnchecked a, Testable prop) => (a -> prop) -> Property forAllUnchecked = forAllShrink genUnchecked shrinkUnchecked forAllValid :: (Show a, GenValid a, Testable prop) => (a -> prop) -> Property forAllValid = forAllShrink genValid shrinkValid forAllInvalid :: (Show a, GenInvalid a, Testable prop) => (a -> prop) -> Property forAllInvalid = forAllShrink genInvalid shrinkInvalid (===>) :: Bool -> Bool -> Bool (===>) a b = not a || b (<==>) :: Bool -> Bool -> Bool (<==>) a b = a ===> b && b ===> a shouldBeValid :: (Show a, Validity a) => a -> Expectation shouldBeValid a = case prettyValidate a of Right _ -> pure () Left err -> expectationFailure $ unlines [ "'validate' reported this value to be invalid: " , show a , "with explanation" , err , "" ] shouldBeInvalid :: (Show a, Validity a) => a -> Expectation shouldBeInvalid a = case prettyValidate a of Right _ -> expectationFailure $ unlines [ "'validate' reported this value to be valid: " , show a , "where we expected it to be invalid" ] Left _ -> pure () genvalidity-property-0.3.0.0/src/Test/Validity/Relations.hs0000644000000000000000000000200513325040557022027 0ustar0000000000000000{-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE ScopedTypeVariables #-} -- | Properties of relations module Test.Validity.Relations ( reflexiveOnElem , reflexivityOnGen , reflexivityOnValid , reflexivity , reflexivityOnArbitrary , transitiveOnElems , transitivityOnGens , transitivityOnValid , transitivity , transitivityOnArbitrary , antisymmetricOnElemsWithEquality , antisymmetryOnGensWithEquality , antisymmetryOnGens , antisymmetryOnValid , antisymmetry , antisymmetryOnArbitrary , antireflexiveOnElem , antireflexivityOnGen , antireflexivityOnValid , antireflexivity , antireflexivityOnArbitrary , symmetricOnElems , symmetryOnGens , symmetryOnValid , symmetry , symmetryOnArbitrary ) where import Test.Validity.Relations.Antireflexivity import Test.Validity.Relations.Antisymmetry import Test.Validity.Relations.Reflexivity import Test.Validity.Relations.Symmetry import Test.Validity.Relations.Transitivity genvalidity-property-0.3.0.0/src/Test/Validity/Relations/Antireflexivity.hs0000644000000000000000000000342313370523751025224 0ustar0000000000000000{-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE ScopedTypeVariables #-} module Test.Validity.Relations.Antireflexivity ( antireflexiveOnElem , antireflexivityOnGen , antireflexivityOnValid , antireflexivity , antireflexivityOnArbitrary ) where import Data.GenValidity import Test.QuickCheck -- | -- -- \[ -- Antireflexive(\prec) -- \quad\equiv\quad -- \forall a: \neg (a \prec a) -- \] antireflexiveOnElem :: (a -> a -> Bool) -- ^ A relation -> a -- ^ An element -> Bool antireflexiveOnElem func a = not $ func a a antireflexivityOnGen :: Show a => (a -> a -> Bool) -> Gen a -> (a -> [a]) -> Property antireflexivityOnGen func gen s = forAllShrink gen s $ antireflexiveOnElem func -- | -- -- prop> antireflexivityOnValid ((<) :: Rational -> Rational -> Bool) -- prop> antireflexivityOnValid ((/=) :: Rational -> Rational -> Bool) -- prop> antireflexivityOnValid ((>) :: Rational -> Rational -> Bool) antireflexivityOnValid :: (Show a, GenValid a) => (a -> a -> Bool) -> Property antireflexivityOnValid func = antireflexivityOnGen func genValid shrinkValid -- | -- -- prop> antireflexivity ((<) :: Int -> Int -> Bool) -- prop> antireflexivity ((/=) :: Int -> Int -> Bool) -- prop> antireflexivity ((>) :: Int -> Int -> Bool) antireflexivity :: (Show a, GenUnchecked a) => (a -> a -> Bool) -> Property antireflexivity func = antireflexivityOnGen func genUnchecked shrinkUnchecked -- | -- -- prop> antireflexivityOnArbitrary ((<) :: Int -> Int -> Bool) -- prop> antireflexivityOnArbitrary ((/=) :: Int -> Int -> Bool) -- prop> antireflexivityOnArbitrary ((>) :: Int -> Int -> Bool) antireflexivityOnArbitrary :: (Show a, Arbitrary a) => (a -> a -> Bool) -> Property antireflexivityOnArbitrary func = antireflexivityOnGen func arbitrary shrink genvalidity-property-0.3.0.0/src/Test/Validity/Relations/Antisymmetry.hs0000644000000000000000000000645213325040557024546 0ustar0000000000000000{-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE ScopedTypeVariables #-} module Test.Validity.Relations.Antisymmetry ( antisymmetricOnElemsWithEquality , antisymmetryOnGensWithEquality , antisymmetryOnGens , antisymmetryOnValid , antisymmetry , antisymmetryOnArbitrary ) where import Data.GenValidity import Test.QuickCheck import Test.Validity.Property.Utils -- | -- -- \[ -- Antisymmetric(\prec, \doteq) -- \quad\equiv\quad -- \forall a, b: ((a \prec b) \wedge (b \prec a)) \Rightarrow (a \doteq b) -- \] antisymmetricOnElemsWithEquality :: (a -> a -> Bool) -- ^ A relation -> (a -> a -> Bool) -- ^ An equivalence relation -> a -> a -- ^ Two elements -> Bool antisymmetricOnElemsWithEquality func eq a b = (func a b && func b a) ===> (a `eq` b) antisymmetryOnGensWithEquality :: Show a => (a -> a -> Bool) -> Gen (a, a) -> (a -> a -> Bool) -> (a -> [a]) -> Property antisymmetryOnGensWithEquality func gen eq s = forAllShrink gen (shrinkT2 s) $ uncurry $ antisymmetricOnElemsWithEquality func eq antisymmetryOnGens :: (Show a, Eq a) => (a -> a -> Bool) -> Gen (a, a) -> (a -> [a]) -> Property antisymmetryOnGens func gen = antisymmetryOnGensWithEquality func gen (==) -- | -- -- prop> antisymmetryOnValid ((>) :: Double -> Double -> Bool) -- prop> antisymmetryOnValid ((>=) :: Double -> Double -> Bool) -- prop> antisymmetryOnValid ((<=) :: Double -> Double -> Bool) -- prop> antisymmetryOnValid ((<) :: Double -> Double -> Bool) -- prop> antisymmetryOnValid (Data.List.isPrefixOf :: [Double] -> [Double] -> Bool) -- prop> antisymmetryOnValid (Data.List.isSuffixOf :: [Double] -> [Double] -> Bool) -- prop> antisymmetryOnValid (Data.List.isInfixOf :: [Double] -> [Double] -> Bool) antisymmetryOnValid :: (Show a, Eq a, GenValid a) => (a -> a -> Bool) -> Property antisymmetryOnValid func = antisymmetryOnGens func genValid shrinkValid -- | -- -- prop> antisymmetry ((>) :: Int -> Int -> Bool) -- prop> antisymmetry ((>=) :: Int -> Int -> Bool) -- prop> antisymmetry ((<=) :: Int -> Int -> Bool) -- prop> antisymmetry ((<) :: Int -> Int -> Bool) -- prop> antisymmetry (Data.List.isPrefixOf :: [Int] -> [Int] -> Bool) -- prop> antisymmetry (Data.List.isSuffixOf :: [Int] -> [Int] -> Bool) -- prop> antisymmetry (Data.List.isInfixOf :: [Int] -> [Int] -> Bool) -- prop> antisymmetry ((\x y -> even x && odd y) :: Int -> Int -> Bool) antisymmetry :: (Show a, Eq a, GenUnchecked a) => (a -> a -> Bool) -> Property antisymmetry func = antisymmetryOnGens func genUnchecked shrinkUnchecked -- | -- -- prop> antisymmetryOnArbitrary ((>) :: Int -> Int -> Bool) -- prop> antisymmetryOnArbitrary ((>=) :: Int -> Int -> Bool) -- prop> antisymmetryOnArbitrary ((<=) :: Int -> Int -> Bool) -- prop> antisymmetryOnArbitrary ((<) :: Int -> Int -> Bool) -- prop> antisymmetryOnArbitrary (Data.List.isPrefixOf :: [Int] -> [Int] -> Bool) -- prop> antisymmetryOnArbitrary (Data.List.isSuffixOf :: [Int] -> [Int] -> Bool) -- prop> antisymmetryOnArbitrary (Data.List.isInfixOf :: [Int] -> [Int] -> Bool) -- prop> antisymmetryOnArbitrary ((\x y -> even x && odd y) :: Int -> Int -> Bool) antisymmetryOnArbitrary :: (Show a, Eq a, Arbitrary a) => (a -> a -> Bool) -> Property antisymmetryOnArbitrary func = antisymmetryOnGens func arbitrary shrink genvalidity-property-0.3.0.0/src/Test/Validity/Relations/Reflexivity.hs0000644000000000000000000000452613370523751024355 0ustar0000000000000000{-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE ScopedTypeVariables #-} module Test.Validity.Relations.Reflexivity ( reflexiveOnElem , reflexivityOnGen , reflexivityOnValid , reflexivity , reflexivityOnArbitrary ) where import Data.GenValidity import Test.QuickCheck -- | -- -- \[ -- Reflexive(\prec) -- \quad\equiv\quad -- \forall a: (a \prec a) -- \] reflexiveOnElem :: (a -> a -> Bool) -- ^ A relation -> a -- ^ An element -> Bool reflexiveOnElem func a = func a a reflexivityOnGen :: Show a => (a -> a -> Bool) -> Gen a -> (a -> [a]) -> Property reflexivityOnGen func gen s = forAllShrink gen s $ reflexiveOnElem func -- | -- -- prop> reflexivityOnValid ((<=) :: Rational -> Rational -> Bool) -- prop> reflexivityOnValid ((==) :: Rational -> Rational -> Bool) -- prop> reflexivityOnValid ((>=) :: Rational -> Rational -> Bool) -- prop> reflexivityOnValid (Data.List.isPrefixOf :: [Rational] -> [Rational] -> Bool) -- prop> reflexivityOnValid (Data.List.isSuffixOf :: [Rational] -> [Rational] -> Bool) -- prop> reflexivityOnValid (Data.List.isInfixOf :: [Rational] -> [Rational] -> Bool) reflexivityOnValid :: (Show a, GenValid a) => (a -> a -> Bool) -> Property reflexivityOnValid func = reflexivityOnGen func genValid shrinkValid -- | -- -- prop> reflexivity ((<=) :: Int -> Int -> Bool) -- prop> reflexivity ((==) :: Int -> Int -> Bool) -- prop> reflexivity ((>=) :: Int -> Int -> Bool) -- prop> reflexivity (Data.List.isPrefixOf :: [Int] -> [Int] -> Bool) -- prop> reflexivity (Data.List.isSuffixOf :: [Int] -> [Int] -> Bool) -- prop> reflexivity (Data.List.isInfixOf :: [Int] -> [Int] -> Bool) reflexivity :: (Show a, GenUnchecked a) => (a -> a -> Bool) -> Property reflexivity func = reflexivityOnGen func genUnchecked shrinkUnchecked -- | -- -- prop> reflexivityOnArbitrary ((<=) :: Int -> Int -> Bool) -- prop> reflexivityOnArbitrary ((==) :: Int -> Int -> Bool) -- prop> reflexivityOnArbitrary ((>=) :: Int -> Int -> Bool) -- prop> reflexivityOnArbitrary (Data.List.isPrefixOf :: [Int] -> [Int] -> Bool) -- prop> reflexivityOnArbitrary (Data.List.isSuffixOf :: [Int] -> [Int] -> Bool) -- prop> reflexivityOnArbitrary (Data.List.isInfixOf :: [Int] -> [Int] -> Bool) reflexivityOnArbitrary :: (Show a, Arbitrary a) => (a -> a -> Bool) -> Property reflexivityOnArbitrary func = reflexivityOnGen func arbitrary shrink genvalidity-property-0.3.0.0/src/Test/Validity/Relations/Symmetry.hs0000644000000000000000000000303213325040557023661 0ustar0000000000000000{-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE ScopedTypeVariables #-} module Test.Validity.Relations.Symmetry ( symmetricOnElems , symmetryOnGens , symmetryOnValid , symmetry , symmetryOnArbitrary ) where import Data.GenValidity import Test.QuickCheck import Test.Validity.Property.Utils -- | -- -- \[ -- Symmetric(\prec) -- \quad\equiv\quad -- \forall a, b: (a \prec b) \Leftrightarrow (b \prec a) -- \] symmetricOnElems :: (a -> a -> Bool) -- ^ A relation -> a -> a -- ^ Two elements -> Bool symmetricOnElems func a b = func a b <==> func b a symmetryOnGens :: Show a => (a -> a -> Bool) -> Gen (a, a) -> (a -> [a]) -> Property symmetryOnGens func gen s = forAllShrink gen (shrinkT2 s) $ uncurry $ symmetricOnElems func -- | -- -- prop> symmetryOnValid ((==) :: Double -> Double -> Bool) -- prop> symmetryOnValid ((/=) :: Double -> Double -> Bool) symmetryOnValid :: (Show a, GenValid a) => (a -> a -> Bool) -> Property symmetryOnValid func = symmetryOnGens func genValid shrinkValid -- | -- -- prop> symmetry ((==) :: Int -> Int -> Bool) -- prop> symmetry ((/=) :: Int -> Int -> Bool) symmetry :: (Show a, GenUnchecked a) => (a -> a -> Bool) -> Property symmetry func = symmetryOnGens func genUnchecked shrinkUnchecked -- | -- -- prop> symmetryOnArbitrary ((==) :: Int -> Int -> Bool) -- prop> symmetryOnArbitrary ((/=) :: Int -> Int -> Bool) symmetryOnArbitrary :: (Show a, Arbitrary a) => (a -> a -> Bool) -> Property symmetryOnArbitrary func = symmetryOnGens func arbitrary shrink genvalidity-property-0.3.0.0/src/Test/Validity/Relations/Transitivity.hs0000644000000000000000000000560413325040557024550 0ustar0000000000000000{-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE ScopedTypeVariables #-} module Test.Validity.Relations.Transitivity ( transitiveOnElems , transitivityOnGens , transitivityOnValid , transitivity , transitivityOnArbitrary ) where import Data.GenValidity import Test.QuickCheck import Test.Validity.Property.Utils -- | -- -- \[ -- Transitive(\prec) -- \quad\equiv\quad -- \forall a, b, c: ((a \prec b) \wedge (b \prec c)) \Rightarrow (a \prec c) -- \] transitiveOnElems :: (a -> a -> Bool) -- ^ A relation -> a -> a -> a -- ^ Three elements -> Bool transitiveOnElems func a b c = (func a b && func b c) ===> func a c transitivityOnGens :: Show a => (a -> a -> Bool) -> Gen (a, a, a) -> (a -> [a]) -> Property transitivityOnGens func gen s = forAllShrink gen (shrinkT3 s) $ \(a, b, c) -> transitiveOnElems func a b c -- | -- -- prop> transitivityOnValid ((>) :: Double -> Double -> Bool) -- prop> transitivityOnValid ((>=) :: Double -> Double -> Bool) -- prop> transitivityOnValid ((==) :: Double -> Double -> Bool) -- prop> transitivityOnValid ((<=) :: Double -> Double -> Bool) -- prop> transitivityOnValid ((<) :: Double -> Double -> Bool) -- prop> transitivityOnValid (Data.List.isPrefixOf :: [Double] -> [Double] -> Bool) -- prop> transitivityOnValid (Data.List.isSuffixOf :: [Double] -> [Double] -> Bool) -- prop> transitivityOnValid (Data.List.isInfixOf :: [Double] -> [Double] -> Bool) transitivityOnValid :: (Show a, GenValid a) => (a -> a -> Bool) -> Property transitivityOnValid func = transitivityOnGens func genValid shrinkValid -- | -- -- prop> transitivity ((>) :: Int -> Int -> Bool) -- prop> transitivity ((>=) :: Int -> Int -> Bool) -- prop> transitivity ((==) :: Int -> Int -> Bool) -- prop> transitivity ((<=) :: Int -> Int -> Bool) -- prop> transitivity ((<) :: Int -> Int -> Bool) -- prop> transitivity (Data.List.isPrefixOf :: [Int] -> [Int] -> Bool) -- prop> transitivity (Data.List.isSuffixOf :: [Int] -> [Int] -> Bool) -- prop> transitivity (Data.List.isInfixOf :: [Int] -> [Int] -> Bool) transitivity :: (Show a, GenUnchecked a) => (a -> a -> Bool) -> Property transitivity func = transitivityOnGens func genUnchecked shrinkUnchecked -- | -- -- prop> transitivityOnArbitrary ((>) :: Int -> Int -> Bool) -- prop> transitivityOnArbitrary ((>=) :: Int -> Int -> Bool) -- prop> transitivityOnArbitrary ((==) :: Int -> Int -> Bool) -- prop> transitivityOnArbitrary ((<=) :: Int -> Int -> Bool) -- prop> transitivityOnArbitrary ((<) :: Int -> Int -> Bool) -- prop> transitivityOnArbitrary (Data.List.isPrefixOf :: [Int] -> [Int] -> Bool) -- prop> transitivityOnArbitrary (Data.List.isSuffixOf :: [Int] -> [Int] -> Bool) -- prop> transitivityOnArbitrary (Data.List.isInfixOf :: [Int] -> [Int] -> Bool) transitivityOnArbitrary :: (Show a, Arbitrary a) => (a -> a -> Bool) -> Property transitivityOnArbitrary func = transitivityOnGens func arbitrary shrink genvalidity-property-0.3.0.0/src/Test/Validity/Shrinking/Property.hs0000644000000000000000000001265713370523751023667 0ustar0000000000000000{-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE AllowAmbiguousTypes #-} {-# LANGUAGE ScopedTypeVariables #-} -- | Tests for shrinking functions module Test.Validity.Shrinking.Property ( shrinkPreservesValidOnGenValid , shrinkPreservesInvalidOnGenInvalid , shrinkValidPreservesValid , shrinkInvalidPreservesInvalid , shrinkingStaysValid , shrinkingStaysValidWithLimit , shrinkingStaysInvalid , shrinkingPreserves , shrinkingPreservesWithLimit , shrinkDoesNotShrinkToItself , shrinkDoesNotShrinkToItselfWithLimit , shrinkDoesNotShrinkToItselfOnValid , shrinkDoesNotShrinkToItselfOnValidWithLimit , shrinkDoesNotShrinkToItselfOnInvalid , shrinkDoesNotShrinkToItselfOnInvalidWithLimit , doesNotShrinkToItself , doesNotShrinkToItselfWithLimit ) where import Data.GenValidity import Test.QuickCheck -- | -- -- prop> shrinkPreservesValidOnGenValid ((:[]) :: Int -> [Int]) shrinkPreservesValidOnGenValid :: forall a. (Show a, GenValid a) => (a -> [a]) -> Property shrinkPreservesValidOnGenValid = shrinkingStaysValid genValid -- | -- -- prop> shrinkPreservesInvalidOnGenInvalid ((:[]) :: Rational -> [Rational]) shrinkPreservesInvalidOnGenInvalid :: forall a. (Show a, GenInvalid a) => (a -> [a]) -> Property shrinkPreservesInvalidOnGenInvalid = shrinkingStaysValid genInvalid -- | -- -- prop> shrinkValidPreservesValid (pure 5 :: Gen Rational) shrinkValidPreservesValid :: forall a. (Show a, GenValid a) => Gen a -> Property shrinkValidPreservesValid gen = shrinkingStaysValid gen shrinkValid -- | -- shrinkInvalidPreservesInvalid :: forall a. (Show a, GenInvalid a) => Gen a -> Property shrinkInvalidPreservesInvalid gen = shrinkingStaysValid gen shrinkInvalid -- | -- -- prop> shrinkingStaysValid (pure 5 :: Gen Double) (\d -> [d - 1, d - 2]) shrinkingStaysValid :: forall a. (Show a, Validity a) => Gen a -> (a -> [a]) -> Property shrinkingStaysValid gen s = shrinkingPreserves gen s isValid -- | -- -- prop> shrinkingStaysValidWithLimit (pure 5 :: Gen Double) (\d -> [d - 1, read "NaN"]) 1 shrinkingStaysValidWithLimit :: forall a. (Show a, Validity a) => Gen a -> (a -> [a]) -> Int -> Property shrinkingStaysValidWithLimit gen s l = shrinkingPreservesWithLimit gen s l isValid -- | -- -- prop> shrinkingStaysInvalid (pure (1/0) :: Gen Double) (:[]) shrinkingStaysInvalid :: forall a. (Show a, Validity a) => Gen a -> (a -> [a]) -> Property shrinkingStaysInvalid gen s = shrinkingPreserves gen s isInvalid -- | -- -- prop> shrinkingPreserves (pure 5 :: Gen Int) (:[]) (== 5) shrinkingPreserves :: forall a. Show a => Gen a -> (a -> [a]) -> (a -> Bool) -> Property shrinkingPreserves gen s p = forAll gen $ \d -> not (p d) || all p (s d) -- | -- -- prop> shrinkingPreservesWithLimit (pure 4) (:[]) 100 (== 4) shrinkingPreservesWithLimit :: forall a. Show a => Gen a -> (a -> [a]) -> Int -> (a -> Bool) -> Property shrinkingPreservesWithLimit gen s l p = forAll gen $ \d -> not (p d) || all p (take l $ s d) -- | -- -- prop> shrinkDoesNotShrinkToItself (shrinkUnchecked :: Double -> [Double]) shrinkDoesNotShrinkToItself :: forall a. (Show a, Eq a, GenUnchecked a) => (a -> [a]) -> Property shrinkDoesNotShrinkToItself = doesNotShrinkToItself genUnchecked -- | -- -- prop> shrinkDoesNotShrinkToItselfWithLimit (shrinkUnchecked :: Double -> [Double]) 100 shrinkDoesNotShrinkToItselfWithLimit :: forall a. (Show a, Eq a, GenUnchecked a) => (a -> [a]) -> Int -> Property shrinkDoesNotShrinkToItselfWithLimit = doesNotShrinkToItselfWithLimit genUnchecked -- | -- -- prop> shrinkDoesNotShrinkToItselfOnValid (shrinkValid :: Rational -> [Rational]) shrinkDoesNotShrinkToItselfOnValid :: forall a. (Show a, Eq a, GenValid a) => (a -> [a]) -> Property shrinkDoesNotShrinkToItselfOnValid = doesNotShrinkToItself genValid -- | -- -- prop> shrinkDoesNotShrinkToItselfOnValidWithLimit (shrinkValid :: Rational -> [Rational]) 100 shrinkDoesNotShrinkToItselfOnValidWithLimit :: forall a. (Show a, Eq a, GenValid a) => (a -> [a]) -> Int -> Property shrinkDoesNotShrinkToItselfOnValidWithLimit = doesNotShrinkToItselfWithLimit genValid -- | -- -- prop> shrinkDoesNotShrinkToItselfOnInvalid (shrinkInvalid :: Rational -> [Rational]) shrinkDoesNotShrinkToItselfOnInvalid :: forall a. (Show a, Eq a, GenInvalid a) => (a -> [a]) -> Property shrinkDoesNotShrinkToItselfOnInvalid = doesNotShrinkToItself genInvalid -- | -- -- prop> shrinkDoesNotShrinkToItselfOnInvalidWithLimit (shrinkInvalid :: Rational -> [Rational]) 100 shrinkDoesNotShrinkToItselfOnInvalidWithLimit :: forall a. (Show a, Eq a, GenInvalid a) => (a -> [a]) -> Int -> Property shrinkDoesNotShrinkToItselfOnInvalidWithLimit = doesNotShrinkToItselfWithLimit genInvalid -- | -- -- prop> doesNotShrinkToItself (pure 5 :: Gen Double) shrinkUnchecked doesNotShrinkToItself :: forall a. (Show a, Eq a) => Gen a -> (a -> [a]) -> Property doesNotShrinkToItself gen s = forAll gen $ \a -> all (/= a) $ s a -- | -- -- prop> doesNotShrinkToItselfWithLimit (pure 5 :: Gen Double) shrinkUnchecked 100 doesNotShrinkToItselfWithLimit :: forall a. (Show a, Eq a) => Gen a -> (a -> [a]) -> Int -> Property doesNotShrinkToItselfWithLimit gen s l = forAll gen $ \a -> all (/= a) $ take l $ s a genvalidity-property-0.3.0.0/src/Test/Validity/Types.hs0000644000000000000000000000116513325040557021201 0ustar0000000000000000{-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE ScopedTypeVariables #-} module Test.Validity.Types ( CanFail(..) ) where -- | A class of types that are the result of functions that can fail class CanFail f where hasFailed :: f a -> Bool resultIfSucceeded :: f a -> Maybe a instance CanFail Maybe where hasFailed Nothing = True hasFailed _ = False resultIfSucceeded Nothing = Nothing resultIfSucceeded (Just r) = Just r instance CanFail (Either e) where hasFailed (Left _) = True hasFailed _ = False resultIfSucceeded (Left _) = Nothing resultIfSucceeded (Right r) = Just r genvalidity-property-0.3.0.0/doctest/DocTest.hs0000644000000000000000000000120113325040557017603 0ustar0000000000000000{-# LANGUAGE CPP #-} #if !MIN_VERSION_base(4,8,0) import Data.Functor ((<$>)) #endif import Test.DocTest import Control.Monad import System.Directory import System.FilePath main :: IO () main = do fs <- listFilesRecur "src" doctest $ "-isrc" : fs listFilesRecur :: FilePath -> IO [FilePath] listFilesRecur dir = do entries <- map (dir ) . filter (\f -> f /= "." && f /= ".." && takeExtension f /= ".swp") <$> getDirectoryContents dir dirs <- filterM doesDirectoryExist entries files <- filterM doesFileExist entries rests <- mapM listFilesRecur dirs return $ concat $ files : rests genvalidity-property-0.3.0.0/LICENSE0000644000000000000000000000207713325040557015256 0ustar0000000000000000The MIT License (MIT) Copyright (c) 2016 Tom Sydney Kerckhove Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. genvalidity-property-0.3.0.0/Setup.hs0000644000000000000000000000005713325040557015701 0ustar0000000000000000import Distribution.Simple main = defaultMain genvalidity-property-0.3.0.0/genvalidity-property.cabal0000644000000000000000000000441313370533227021433 0ustar0000000000000000-- This file has been generated from package.yaml by hpack version 0.28.2. -- -- see: https://github.com/sol/hpack -- -- hash: e10039becc2df447bf74a5317c786e342f17d4408e0c705530ef0e5fbd93a8f1 name: genvalidity-property version: 0.3.0.0 synopsis: Standard properties for functions on `Validity` types description: Standard properties for functions on `Validity` types category: Testing homepage: https://github.com/NorfairKing/validity#readme bug-reports: https://github.com/NorfairKing/validity/issues author: Tom Sydney Kerckhove maintainer: syd.kerckhove@gmail.com, nick.van.den.broeck666@gmail.com copyright: Copyright: (c) 2016-2018 Tom Sydney Kerckhove license: MIT license-file: LICENSE build-type: Simple cabal-version: >= 1.10 source-repository head type: git location: https://github.com/NorfairKing/validity library exposed-modules: Test.Validity.Functions Test.Validity.Functions.CanFail Test.Validity.Functions.Equivalence Test.Validity.Functions.Idempotence Test.Validity.Functions.Inverse Test.Validity.Functions.Validity Test.Validity.GenValidity.Property Test.Validity.Operations Test.Validity.Operations.Associativity Test.Validity.Operations.Commutativity Test.Validity.Operations.Identity Test.Validity.Property Test.Validity.Property.Utils Test.Validity.Relations Test.Validity.Relations.Antireflexivity Test.Validity.Relations.Antisymmetry Test.Validity.Relations.Reflexivity Test.Validity.Relations.Symmetry Test.Validity.Relations.Transitivity Test.Validity.Shrinking.Property Test.Validity.Types other-modules: Paths_genvalidity_property hs-source-dirs: src build-depends: QuickCheck , base >=4.7 && <5 , genvalidity >=0.7 , hspec >=2.1 , validity >=0.9 default-language: Haskell2010 test-suite genvalidity-property-doctests type: exitcode-stdio-1.0 main-is: DocTest.hs other-modules: Paths_genvalidity_property hs-source-dirs: doctest ghc-options: -threaded build-depends: base , directory >=1.2 , doctest , filepath >=1.3 , genvalidity-property default-language: Haskell2010