genvalidity 0.10.0.0 → 0.10.0.1
raw patch · 3 files changed
+34/−37 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- genvalidity.cabal +3/−3
- src/Data/GenValidity.hs +8/−2
- test/Data/InstanceSpec.hs +23/−32
genvalidity.cabal view
@@ -1,13 +1,13 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.33.0.+-- This file has been generated from package.yaml by hpack version 0.31.2. -- -- see: https://github.com/sol/hpack ----- hash: e90aaf1b087b8075c4ea0ebdc7a6b590389d536577d48df97509b031d9f64fcb+-- hash: 92201210df714c4a22ab737e271cd27152fd5f43b5b83d4a0c0006a3b860b55c name: genvalidity-version: 0.10.0.0+version: 0.10.0.1 synopsis: Testing utilities for the validity library description: Note: There are companion instance packages for this library: .
src/Data/GenValidity.hs view
@@ -112,6 +112,7 @@ import Data.Ratio ((%)) import GHC.Generics import GHC.Real (Ratio(..))+import Control.Monad (guard) import Test.QuickCheck hiding (Fixed) @@ -714,8 +715,13 @@ genValid = (do n <- genValid d <- (genValid `suchThat` (> 0))- pure $ n :% d) `suchThat` ((== valid) . validateRatioNormalised)- shrinkValid (n :% d) = filter isValid [n' % d' | (n', d') <- shrinkValid (n, d), d' > 0]+ pure $ n :% d) `suchThat` isValid+ shrinkValid (n :% d) = do+ (n', d') <- shrinkValid (n, d)+ guard $ d' > 0+ let candidate = n' :% d'+ guard $ isValid candidate+ pure $ n' % d' instance (Integral a, Num a, Ord a, Validity a, GenUnchecked a) => GenInvalid (Ratio a)
test/Data/InstanceSpec.hs view
@@ -57,6 +57,15 @@ -- threeTupleTests (Proxy :: Proxy (Ratio Integer)) threeTests (Proxy :: Proxy (Ratio Int)) -- threeTupleTests (Proxy :: Proxy (Ratio Int))+ threeTests (Proxy :: Proxy (Ratio Int8))+ describe "shrinking (Ratio Int)" $+ it "can shrink this example" $+ let v = ((-9223372036854775808) % 9223372036854775761) :: Ratio Int+ in v `notElem` shrinkValid v+ describe "shrinking (Ratio Int8)" $+ it "can shrink this example" $+ let v = ((-128) % 113) :: Ratio Int8+ in v `notElem` shrinkValid v twoTests (Proxy :: Proxy Uni) twoTupleTests (Proxy :: Proxy Uni) twoTests (Proxy :: Proxy Deci)@@ -84,8 +93,7 @@ => Proxy a -> Spec twoTupleTests proxy = do- modifyMaxSuccess (`quot` 2) $- modifyMaxSize (`quot` 2) $ twoTests $ (,) <$> proxy <*> proxy+ modifyMaxSuccess (`quot` 2) $ modifyMaxSize (`quot` 2) $ twoTests $ (,) <$> proxy <*> proxy twoTests :: forall a. (Show a, Eq a, Typeable a, GenUnchecked a, GenValid a)@@ -97,8 +105,7 @@ genValidTest proxy threeTests ::- forall a.- (Show a, Eq a, Typeable a, GenUnchecked a, GenValid a, GenInvalid a)+ forall a. (Show a, Eq a, Typeable a, GenUnchecked a, GenValid a, GenInvalid a) => Proxy a -> Spec threeTests proxy =@@ -112,9 +119,7 @@ => Proxy a -> Spec genUncheckedTest proxy = do- it- (unwords- ["genUnchecked of", nameOf proxy, "does not crash while validating"]) $+ it (unwords ["genUnchecked of", nameOf proxy, "does not crash while validating"]) $ forAll genUnchecked $ \a -> case prettyValidate (a :: a) of Right v -> seq v True@@ -132,13 +137,11 @@ Right v_ -> seq v_ $ pure () :: IO () Left err -> seq err $ pure () modifyMaxSuccess (`quot` 5) $- it- (unwords ["shrinkUnchecked of", nameOf proxy, "does not shrink to itself"]) $+ it (unwords ["shrinkUnchecked of", nameOf proxy, "does not shrink to itself"]) $ forAll genValid $ \a -> forM_ (shrinkUnchecked a) $ \a' -> unless (a /= a') $- expectationFailure $- unlines ["The value", show (a :: a), "was shrunk to itself"]+ expectationFailure $ unlines ["The value", show (a :: a), "was shrunk to itself"] genValidTest :: forall a. (Show a, Eq a, Typeable a, GenValid a)@@ -151,26 +154,20 @@ Right v -> seq v $ pure () Left err -> expectationFailure $- unlines- ["'validate' reported this value to be invalid:", show a, err, ""]+ unlines ["'validate' reported this value to be invalid:", show a, err, ""] modifyMaxSuccess (`quot` 5) $- it- (unwords ["shrinkValid of", nameOf proxy, "shrinks to only valid values"]) $+ it (unwords ["shrinkValid of", nameOf proxy, "shrinks to only valid values"]) $ forAll genValid $ \a -> forM_ (shrinkValid a) $ \v -> case prettyValidate (v :: a) of Right v_ -> seq v_ $ pure () Left err -> expectationFailure $- unlines- ["'validate' reported this value to be invalid:", show v, err, ""]+ unlines ["'validate' reported this value to be invalid:", show v, err, ""] modifyMaxSuccess (`quot` 5) $ it (unwords- [ "shrinkValid of"- , nameOf proxy- , "only produces values that do not crash while validating"- ]) $+ ["shrinkValid of", nameOf proxy, "only produces values that do not crash while validating"]) $ forAll genValid $ \a -> forM_ (shrinkValid a) $ \v -> case prettyValidate (v :: a) of@@ -181,8 +178,7 @@ forAll genValid $ \a -> forM_ (shrinkValid a) $ \a' -> unless (a /= a') $- expectationFailure $- unlines ["The value", show (a :: a), "was shrunk to itself"]+ expectationFailure $ unlines ["The value", show (a :: a), "was shrunk to itself"] genInvalidTest :: forall a. (Show a, Typeable a, GenInvalid a)@@ -193,19 +189,15 @@ forAll genInvalid $ \a -> case prettyValidate (a :: a) of Right _ ->- expectationFailure $- unlines ["'validate' reported this value to be valid: ", show a]+ expectationFailure $ unlines ["'validate' reported this value to be valid: ", show a] Left e -> seq e $ pure () modifyMaxSuccess (`quot` 5) $- it- (unwords- ["shrinkInvalid of", nameOf proxy, "shrinks to only invalid values"]) $+ it (unwords ["shrinkInvalid of", nameOf proxy, "shrinks to only invalid values"]) $ forAll genInvalid $ \a -> forM_ (shrinkInvalid a) $ \v -> case prettyValidate (v :: a) of Right _ ->- expectationFailure $- unlines ["'validate' reported this value to be valid: ", show v]+ expectationFailure $ unlines ["'validate' reported this value to be valid: ", show v] Left e -> seq e $ pure () modifyMaxSuccess (`quot` 5) $ it@@ -218,8 +210,7 @@ forM_ (shrinkInvalid a) $ \v -> case prettyValidate (v :: a) of Right _ ->- expectationFailure $- unlines ["'validate' reported this value to be valid: ", show v]+ expectationFailure $ unlines ["'validate' reported this value to be valid: ", show v] Left e -> seq e $ pure () nameOf ::