quickcheck-assertions 0.1.0 → 0.1.1
raw patch · 2 files changed
+46/−24 lines, 2 files
Files
- Test/QuickCheck/Assertions.hs +45/−23
- quickcheck-assertions.cabal +1/−1
Test/QuickCheck/Assertions.hs view
@@ -2,18 +2,18 @@ For example you can do something like that: > module Main where-> +> > import Test.Hspec > import Test.Hspec.QuickCheck > import Test.QuickCheck.Assertions > import Test.QuickCheck.Property-> +> > someProp :: Int -> Int -> Result > someProp a b = (a ?> b)-> +> > someOtherProp :: Double -> Double -> Result > someOtherProp a b = (a ?== b)-> +> > main = hspec $ describe "failing test" $ do > prop "must fail" $ someProp > prop "must fail again" $ someOtherProp@@ -21,21 +21,21 @@ And receive pretty printed fail message when testing: > failing test-> - must fail FAILED [1] -> - must fail again FAILED [2] -> +> - must fail FAILED [1]+> - must fail again FAILED [2]+> > 1) failing test must fail FAILED-> *** Failed! (after 1 test): +> *** Failed! (after 1 test): > >>>>>>>>>>>>>> the value > 0 > >>>>>>>>>>>>>> should be greater than value > 0 > 0 > 0-> -> +>+> > 2) failing test must fail again FAILED-> *** Failed! (after 2 tests and 4 shrinks): +> *** Failed! (after 2 tests and 4 shrinks): > >>>>>>>>>>>>>> expected > 0.0 > >>>>>>>>>>>>>> but got@@ -68,7 +68,7 @@ -binAsrt :: String -- ^ The reason of fail+binAsrt :: String -- ^ The reason of fail -> Bool -- ^ If True then test pass -> Result -- ^ The result with fail reason binAsrt fmt pre = if pre@@ -76,24 +76,30 @@ else failed {reason = fmt} -(==?), (?==) :: (Eq a, Show a) => a -> a -> Result+-- | Left argument should be equal to right+(?==) :: (Eq a, Show a) => a -> a -> Result (?==) a b = binAsrt s (a == b) where- s = ">>>>>>>>>>>>>> expected\n" -- very stupid formater for now- ++ show a +++ s = "\n>>>>>>>>>>>>>> expected\n" -- very stupid formater for now+ ++ show b ++ "\n>>>>>>>>>>>>>> but got\n"- ++ show b+ ++ show a +-- | Right argument should be equal to left+(==?) :: (Eq a, Show a) => a -> a -> Result (==?) = flip (?==) -(?/=), (/=?) :: (Eq a, Show a) => a -> a -> Result+-- | Left argument should not equal to right+(?/=):: (Eq a, Show a) => a -> a -> Result (?/=) a b = binAsrt s (a /= b) where- s = ">>>>>>>>>>>>>> expected the value\n"+ s = "\n>>>>>>>>>>>>>> expected the value\n" ++ show a ++ "\n>>>>>>>>>>>>>> should not equal to\n" ++ show b +-- | Right argument should not equal to left+(/=?) :: (Eq a, Show a) => a -> a -> Result (/=?) = flip (?/=) @@ -105,37 +111,53 @@ -> Result binOrdering pre fmt a b = binAsrt s (pre $ compare a b) where- s = ">>>>>>>>>>>>>> the value\n"+ s = "\n>>>>>>>>>>>>>> the value\n" ++ show a ++ "\n>>>>>>>>>>>>>> should be " ++ fmt ++ " than value\n" ++ show b- -(>?), (<?), (?>), (?<), (>=?), (<=?), (?>=), (?<=) :: (Show a, Ord a) => a -> a -> Result + -- | Left argument is greater than right+(?>) :: (Show a, Ord a) => a -> a -> Result (?>) a b = binOrdering (== GT) "greater" a b+ -- | Left argument is less then right+(?<) :: (Show a, Ord a) => a -> a -> Result (?<) a b = binOrdering (== LT) "less" a b+ -- | Right argument is less then left+(>?) :: (Show a, Ord a) => a -> a -> Result (>?) = flip (?<)+ -- | Right argument is greater than left+(<?) :: (Show a, Ord a) => a -> a -> Result (<?) = flip (?>)+ -- | Left argument is greater or equal to right+(?>=) :: (Show a, Ord a) => a -> a -> Result (?>=) a b = binOrdering (\x -> x == EQ || x == GT) "greater or equal" a b+ -- | Left argument is less or equal to right+(?<=) :: (Show a, Ord a) => a -> a -> Result (?<=) a b = binOrdering (\x -> x == EQ || x == LT) "less or equal" a b+ -- | Right argument is less or equal to left+(>=?) :: (Show a, Ord a) => a -> a -> Result (>=?) = flip (?<=)+ -- | Right argument is greater or equal to left+(<=?) :: (Show a, Ord a) => a -> a -> Result (<=?) = flip (?>=) -(?~==), (~==?) :: (AEq a, Show a) => a -> a -> Result -- | Left value is almost equal to right+(?~==) :: (AEq a, Show a) => a -> a -> Result (?~==) a b = binAsrt s (a ~== b) where- s = ">>>>>>>>>>>>>> The value\n"+ s = "\n>>>>>>>>>>>>>> The value\n" ++ show a ++ "\n>>>>>>>>>>>>>> should be almost equal to\n" ++ show b+ -- | Right value is almost equal to left+(~==?) :: (AEq a, Show a) => a -> a -> Result (~==?) = flip (?~==)
quickcheck-assertions.cabal view
@@ -2,7 +2,7 @@ -- further documentation, see http://haskell.org/cabal/users-guide/ name: quickcheck-assertions-version: 0.1.0+version: 0.1.1 synopsis: HUnit like assertions for QuickCheck description: Library with convenient assertions for QuickCheck properties like in HUnit license: LGPL-3