packages feed

validity 0.9.0.2 → 0.9.0.3

raw patch · 4 files changed

+29/−19 lines, 4 filesdep ~basePVP ok

version bump matches the API change (PVP)

Dependency ranges changed: base

API changes (from Hackage documentation)

Files

LICENSE view
@@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2016 Tom Sydney Kerckhove+Copyright (c) 2016-2020 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
src/Data/Validity.hs view
@@ -95,7 +95,7 @@ import Data.Ratio #endif import Data.Bits ((.&.))-import Data.Char (Char, ord)+import Data.Char (ord) import Data.Int (Int16, Int32, Int64, Int8) #if MIN_VERSION_base(4,8,0) import Data.Word (Word16, Word32, Word64, Word8)@@ -106,7 +106,7 @@ #if MIN_VERSION_base(4,8,0) import GHC.Natural #endif-import GHC.Real (Ratio(..), reduce)+import GHC.Real (Ratio(..))  -- | A class of types that have additional invariants defined upon them @@ -474,7 +474,15 @@     _ -> True  validateRatioNormalised :: Integral a => Ratio a -> Validation-validateRatioNormalised r@(n :% d) = declare "The Ratio is normalised." $ reduce n d == r+validateRatioNormalised (n :% d) = declare "The Ratio is normalised." $+  case d of+    0 -> False+    _ ->+      let g = gcd n d+          gcdOverflows = g < 0+          n' :% d' = (n `quot` g) :% (d `quot` g)+          valueIsNormalised = n' :% d' == n :% d+      in not gcdOverflows && valueIsNormalised  -- | Trivially valid --@@ -496,18 +504,12 @@ -- | Valid if the contained numbers are valid and the denominator is -- strictly positive. instance (Validity a, Ord a, Num a, Integral a) => Validity (Ratio a) where-    validate (n :% d) =+    validate r@(n :% d) =         mconcat             [ annotate n "The numerator"             , annotate d "The denominator"             , declare "The denominator is strictly positive." $ d > 0-            , declare "The ratio is normalised" $-                case d of-                  0 -> False-                  _ ->-                    let g = gcd n d-                        n' :% d' = (n `quot` g) :% (d `quot` g)-                    in n' :% d' == n :% d+            , validateRatioNormalised r             ]  -- | Valid according to the contained 'Integer'.
test/Data/ValiditySpec.hs view
@@ -56,6 +56,15 @@         prettyValidation (validateCharNotUtf16SurrogateCodePoint 'a') `shouldSatisfy` isNothing       it "Says that \\55810 is an invalid char" $         prettyValidation (validateCharNotUtf16SurrogateCodePoint '\55810') `shouldSatisfy` isJust+  describe "Ratio" $ do+    it "says that 0 is valid" $ NormalisedRatio (0 :% 1 :: Ratio Int) `shouldSatisfy` isValid+    it "says that 1 is valid" $ NormalisedRatio (1 :% 1 :: Ratio Int) `shouldSatisfy` isValid+    it "says that minBound is valid" $ NormalisedRatio (minBound :% 1 :: Ratio Int) `shouldSatisfy` isValid+    it "says that maxBound is valid" $ NormalisedRatio (maxBound :% 1 :: Ratio Int) `shouldSatisfy` isValid+    it "says that maxBound / minBound is invalid" $ NormalisedRatio (maxBound :% minBound :: Ratio Int) `shouldSatisfy` (not . isValid)+    it "says that minBound / maxBound is invalid" $ NormalisedRatio (minBound :% maxBound :: Ratio Int) `shouldSatisfy` (not . isValid)++    it "says that minBound / 2957808295740799111 is valid" $ NormalisedRatio (minBound :% (2957808295740799111) :: Ratio Int) `shouldSatisfy` isValid   describe "NormalisedRatio" $ do     it "says that NaN is invalid" $ NormalisedRatio notANumber `shouldSatisfy` (not . isValid)     it "says that +Inf is invalid" $ NormalisedRatio infinity `shouldSatisfy` (not . isValid)
validity.cabal view
@@ -1,13 +1,13 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.31.2.+-- This file has been generated from package.yaml by hpack version 0.33.0. -- -- see: https://github.com/sol/hpack ----- hash: c5fd8a29bca818acb5b12b926b6d1143f48fcf0d4dbe5ab886a92c7d0492ab08+-- hash: d006c09ce2c1b3a5b9614851314390ed87a2dd35f3304de883115ca80df6a853  name:           validity-version:        0.9.0.2+version:        0.9.0.3 synopsis:       Validity typeclass description:    For more info, see <https://github.com/NorfairKing/validity the readme>.                 .@@ -36,9 +36,8 @@ 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+maintainer:     syd@cs-syd.eu+copyright:      Copyright: (c) 2016-2020 Tom Sydney Kerckhove license:        MIT license-file:   LICENSE build-type:     Simple@@ -71,7 +70,7 @@       test   ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall   build-depends:-      base+      base >=4.7 && <5     , hspec     , validity   default-language: Haskell2010