packages feed

genvalidity 0.5.0.1 → 0.5.0.2

raw patch · 3 files changed

+50/−10 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

genvalidity.cabal view
@@ -2,10 +2,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 6b2dfb29109026a30275df0b6424310c9d43d7f09a648f4c701c0e366fa2de9c+-- hash: c6cb01330e02c5f3e8738720c2d535d8fcc73f8113e88257d09f05b265c3cb09  name:           genvalidity-version:        0.5.0.1+version:        0.5.0.2 synopsis:       Testing utilities for the validity library description:    Note: There are companion instance packages for this library:                 .
src/Data/GenValidity.hs view
@@ -68,6 +68,7 @@ #endif import Data.Word (Word, Word8, Word16, Word32, Word64) import Data.Int (Int, Int8, Int16, Int32, Int64)+import Data.Ratio ((%)) import GHC.Generics import GHC.Real (Ratio(..)) @@ -507,13 +508,18 @@         pure $ n :% d     shrinkUnchecked (n :% d) = [n' :% d' | (n', d') <- shrinkUnchecked (n, d)] -instance (Integral a, Num a, Ord a, GenValid a) => GenValid (Ratio a)+instance (Integral a, Num a, Ord a, GenValid a) => GenValid (Ratio a) where+    genValid = do+      n <- genValid+      d <- genValid `suchThat` (> 0)+      pure $ n % d+    shrinkValid (n :% d) = [n' % d' | (n', d') <- shrinkValid (n, d), d' > 0]  instance (Integral a, Num a, Ord a, GenValid a) => GenInvalid (Ratio a)  instance HasResolution a => GenUnchecked (Fixed a) where     genUnchecked = MkFixed <$> genUnchecked-    shrinkUnchecked = shrink+    shrinkUnchecked (MkFixed i) = MkFixed <$> shrinkUnchecked i  instance HasResolution a => GenValid (Fixed a) 
test/Data/InstanceSpec.hs view
@@ -10,6 +10,7 @@ #if MIN_VERSION_base(4,9,0) import Data.List.NonEmpty (NonEmpty) #endif+import Data.Fixed import Data.Ratio import Data.Word @@ -44,11 +45,19 @@     threeTests (Proxy :: Proxy (Double, Double))     threeTests (Proxy :: Proxy (Double, Double, Double))     threeTests (Proxy :: Proxy (Double, Double, Double, Double))+    threeTests (Proxy :: Proxy (Double, Double, Double, Double, Double))     threeTests (Proxy :: Proxy (Either Double Double))     threeTests (Proxy :: Proxy (Maybe Double))     threeTests (Proxy :: Proxy [Double])     threeTests (Proxy :: Proxy (Ratio Integer))     threeTests (Proxy :: Proxy (Ratio Int))+    twoTests (Proxy :: Proxy Uni)+    twoTests (Proxy :: Proxy Deci)+    twoTests (Proxy :: Proxy Centi)+    twoTests (Proxy :: Proxy Milli)+    twoTests (Proxy :: Proxy Micro)+    twoTests (Proxy :: Proxy Nano)+    twoTests (Proxy :: Proxy Pico) #if MIN_VERSION_base(4,9,0)     threeTests (Proxy :: Proxy (NonEmpty Double)) #endif@@ -80,7 +89,7 @@             ["genUnchecked of", nameOf proxy, "does not crash while validating"]) $         forAll genUnchecked $ \a ->             case prettyValidation (a :: a) of-                Right _ -> True+                Right v -> seq v True                 Left err -> seq err True     it (unwords             [ "shrinkUnchecked of"@@ -90,7 +99,7 @@         forAll genUnchecked $ \a ->             forM_ (shrinkUnchecked a) $ \v ->                 case prettyValidation (v :: a) of-                    Right _ -> pure () :: IO ()+                    Right v_ -> seq v_ $ pure () :: IO ()                     Left err -> seq err $ pure ()  genValidTest ::@@ -101,7 +110,7 @@     it (unwords ["genValid of", nameOf proxy, "generates only valid values"]) $         forAll genValid $ \a ->             case prettyValidation (a :: a) of-                Right _ -> pure ()+                Right v -> seq v $ pure ()                 Left err ->                     expectationFailure $                     unlines@@ -114,7 +123,7 @@         forAll genValid $ \a ->             forM_ (shrinkValid a) $ \v ->                 case prettyValidation (v :: a) of-                    Right _ -> pure ()+                    Right v_ -> seq v_ $ pure ()                     Left err ->                         expectationFailure $                         unlines@@ -123,6 +132,16 @@                             , err                             , ""                             ]+    it (unwords+            [ "shrinkValid of"+            , nameOf proxy+            , "only produces values that do not crash while validating"+            ]) $+        forAll genValid $ \a ->+            forM_ (shrinkValid a) $ \v ->+                case prettyValidation (v :: a) of+                    Right v_ -> seq v_ $ pure () :: IO ()+                    Left err -> seq err $ pure ()  genInvalidTest ::        forall a. (Show a, Typeable a, GenInvalid a)@@ -136,7 +155,7 @@                     expectationFailure $                     unlines                         ["'validate' reported this value to be valid: ", show a]-                Left _ -> pure ()+                Left e -> seq e $ pure ()     it (unwords             ["shrinkInvalid of", nameOf proxy, "shrinks to only invalid values"]) $         forAll genInvalid $ \a ->@@ -148,7 +167,22 @@                             [ "'validate' reported this value to be valid: "                             , show v                             ]-                    Left _ -> pure ()+                    Left e -> seq e $ pure ()+    it (unwords+            [ "shrinkInvalid of"+            , nameOf proxy+            , "only produces values that do not crash while validating"+            ]) $+        forAll genInvalid $ \a ->+            forM_ (shrinkInvalid a) $ \v ->+                case prettyValidation (v :: a) of+                    Right _ ->+                        expectationFailure $+                        unlines+                            [ "'validate' reported this value to be valid: "+                            , show v+                            ]+                    Left e -> seq e $ pure ()  nameOf ::        forall a. Typeable a