genvalidity-property-0.2.1.0/doctest/0000755000000000000000000000000013315612004015677 5ustar0000000000000000genvalidity-property-0.2.1.0/src/0000755000000000000000000000000013216764035015035 5ustar0000000000000000genvalidity-property-0.2.1.0/src/Test/0000755000000000000000000000000013216764035015754 5ustar0000000000000000genvalidity-property-0.2.1.0/src/Test/Validity/0000755000000000000000000000000013273275320017536 5ustar0000000000000000genvalidity-property-0.2.1.0/src/Test/Validity/Functions/0000755000000000000000000000000013315612004021475 5ustar0000000000000000genvalidity-property-0.2.1.0/src/Test/Validity/GenValidity/0000755000000000000000000000000013312413356021752 5ustar0000000000000000genvalidity-property-0.2.1.0/src/Test/Validity/Operations/0000755000000000000000000000000013216764035021664 5ustar0000000000000000genvalidity-property-0.2.1.0/src/Test/Validity/Property/0000755000000000000000000000000013315612004021351 5ustar0000000000000000genvalidity-property-0.2.1.0/src/Test/Validity/Relations/0000755000000000000000000000000013240064147021473 5ustar0000000000000000genvalidity-property-0.2.1.0/src/Test/Validity/Shrinking/0000755000000000000000000000000013315612004021461 5ustar0000000000000000genvalidity-property-0.2.1.0/src/Test/Validity/Functions.hs0000644000000000000000000000622413216764035022051 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.2.1.0/src/Test/Validity/Functions/CanFail.hs0000644000000000000000000002006113216764035023341 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.2.1.0/src/Test/Validity/Functions/Equivalence.hs0000644000000000000000000003027713240064147024311 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.2.1.0/src/Test/Validity/Functions/Idempotence.hs0000644000000000000000000000216713240064147024301 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.2.1.0/src/Test/Validity/Functions/Inverse.hs0000644000000000000000000001174213216764035023465 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.2.1.0/src/Test/Validity/Functions/Validity.hs0000644000000000000000000000723713315612004023627 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.2.1.0/src/Test/Validity/GenValidity/Property.hs0000644000000000000000000000144213271724403024135 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.2.1.0/src/Test/Validity/Operations.hs0000644000000000000000000000162013216764035022217 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.2.1.0/src/Test/Validity/Operations/Associativity.hs0000644000000000000000000000254613216764035025062 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.2.1.0/src/Test/Validity/Operations/Commutativity.hs0000644000000000000000000000264313216764035025103 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> commutative ((+) :: Double -> Double -> Double) -- prop> commutative ((*) :: Double -> Double -> Double) 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.2.1.0/src/Test/Validity/Operations/Identity.hs0000644000000000000000000001170713216764035024017 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 ((^) :: Double -> Int -> Double)) 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 ((^) :: Double -> Int -> Double) 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 ((*) :: Double -> Double -> Double) 1 -- prop> identityOnValid ((+) :: Double -> Double -> Double) 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.2.1.0/src/Test/Validity/Property.hs0000644000000000000000000001316313240064147021717 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.2.1.0/src/Test/Validity/Property/Utils.hs0000644000000000000000000000316313315612004023010 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 prettyValidation 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 prettyValidation 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.2.1.0/src/Test/Validity/Relations.hs0000644000000000000000000000200513216764035022032 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.2.1.0/src/Test/Validity/Relations/Antireflexivity.hs0000644000000000000000000000340713216764035025227 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 ((<) :: Double -> Double -> Bool) -- prop> antireflexivityOnValid ((/=) :: Double -> Double -> Bool) -- prop> antireflexivityOnValid ((>) :: Double -> Double -> 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.2.1.0/src/Test/Validity/Relations/Antisymmetry.hs0000644000000000000000000000645213216764035024551 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.2.1.0/src/Test/Validity/Relations/Reflexivity.hs0000644000000000000000000000447613216764035024362 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 ((<=) :: Double -> Double -> Bool) -- prop> reflexivityOnValid ((==) :: Double -> Double -> Bool) -- prop> reflexivityOnValid ((>=) :: Double -> Double -> Bool) -- prop> reflexivityOnValid (Data.List.isPrefixOf :: [Double] -> [Double] -> Bool) -- prop> reflexivityOnValid (Data.List.isSuffixOf :: [Double] -> [Double] -> Bool) -- prop> reflexivityOnValid (Data.List.isInfixOf :: [Double] -> [Double] -> 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.2.1.0/src/Test/Validity/Relations/Symmetry.hs0000644000000000000000000000303213216764035023664 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.2.1.0/src/Test/Validity/Relations/Transitivity.hs0000644000000000000000000000560413240064147024545 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.2.1.0/src/Test/Validity/Shrinking/Property.hs0000644000000000000000000000510713315612004023644 0ustar0000000000000000{-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE AllowAmbiguousTypes #-} {-# LANGUAGE ScopedTypeVariables #-} -- | Tests for shrinking functions module Test.Validity.Shrinking.Property ( shrinkPreservesValidOnGenValid , shrinkPreservesInvalidOnGenInvalid , shrinkValidPreservesValid , shrinkInvalidPreservesInvalid , shrinkingStaysValid , shrinkingStaysValidWithLimit , shrinkingStaysInvalid , shrinkingPreserves ) where import Data.GenValidity import Test.QuickCheck -- | -- -- prop> shrinkPreservesValidOnGenValid (:[]) shrinkPreservesValidOnGenValid :: forall a. (Show a, GenValid a) => (a -> [a]) -> Property shrinkPreservesValidOnGenValid = shrinkingStaysValid genValid -- | -- -- prop> shrinkPreservesInvalidOnGenInvalid (:[]) shrinkPreservesInvalidOnGenInvalid :: forall a. (Show a, GenInvalid a) => (a -> [a]) -> Property shrinkPreservesInvalidOnGenInvalid = shrinkingStaysValid genInvalid -- | -- -- prop> shrinkValidPreservesValid (pure 5) shrinkValidPreservesValid :: forall a. (Show a, GenValid a) => Gen a -> Property shrinkValidPreservesValid gen = shrinkingStaysValid gen shrinkValid -- | -- -- prop> shrinkInvalidPreservesInvalid (pure (1/0) :: Gen Double) 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 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) (:[]) (== 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) 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) genvalidity-property-0.2.1.0/src/Test/Validity/Types.hs0000644000000000000000000000116513216764035021204 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.2.1.0/doctest/DocTest.hs0000644000000000000000000000120113315612004017572 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.2.1.0/LICENSE0000644000000000000000000000207713216764035015261 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.2.1.0/Setup.hs0000644000000000000000000000005713216764035015704 0ustar0000000000000000import Distribution.Simple main = defaultMain genvalidity-property-0.2.1.0/genvalidity-property.cabal0000644000000000000000000000443313316174653021441 0ustar0000000000000000-- This file has been generated from package.yaml by hpack version 0.28.2. -- -- see: https://github.com/sol/hpack -- -- hash: b4c5c1e25f8ffaebf6e2edb821c698f82733cba7a41bfbbcf6d3b25be2e13734 name: genvalidity-property version: 0.2.1.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 hs-source-dirs: src build-depends: QuickCheck , base >=4.7 && <5 , genvalidity >=0.5 , hspec >=2.1 , validity >=0.5 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 default-language: Haskell2010 test-suite genvalidity-property-doctests type: exitcode-stdio-1.0 main-is: DocTest.hs hs-source-dirs: doctest ghc-options: -threaded build-depends: base , directory >=1.2 && <1.4 , doctest , filepath >=1.3 && <1.5 , genvalidity-property other-modules: Paths_genvalidity_property default-language: Haskell2010