genvalidity-unordered-containers (empty) → 0.0.0.0
raw patch · 8 files changed
+156/−0 lines, 8 filesdep +QuickCheckdep +basedep +genvaliditysetup-changed
Dependencies added: QuickCheck, base, genvalidity, genvalidity-hspec, genvalidity-unordered-containers, hashable, hspec, unordered-containers, validity, validity-unordered-containers
Files
- LICENSE +21/−0
- Setup.hs +3/−0
- genvalidity-unordered-containers.cabal +50/−0
- src/Data/GenValidity/HashMap.hs +36/−0
- src/Data/GenValidity/HashSet.hs +22/−0
- src/Data/GenValidity/UnorderedContainers.hs +6/−0
- test/Spec.hs +1/−0
- test/Test/Validity/UnorderedContainersSpec.hs +17/−0
+ LICENSE view
@@ -0,0 +1,21 @@+The 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.
+ Setup.hs view
@@ -0,0 +1,3 @@+import Distribution.Simple++main = defaultMain
+ genvalidity-unordered-containers.cabal view
@@ -0,0 +1,50 @@+name: genvalidity-unordered-containers+version: 0.0.0.0+cabal-version: >=1.10+build-type: Simple+license: MIT+license-file: LICENSE+copyright: Copyright: (c) 2017 Tom Sydney Kerckhove+maintainer: syd.kerckhove@gmail.com+homepage: https://github.com/NorfairKing/validity#readme+synopsis: GenValidity support for unordered-containers+description:+ Please see README.md+category: Testing+author: Tom Sydney Kerckhove++source-repository head+ type: git+ location: https://github.com/NorfairKing/validity++library+ exposed-modules:+ Data.GenValidity.UnorderedContainers+ Data.GenValidity.HashMap+ Data.GenValidity.HashSet+ build-depends:+ base <5,+ QuickCheck -any,+ genvalidity >=0.3 && <0.4,+ hashable -any,+ unordered-containers -any,+ validity >=0.3 && <0.4,+ validity-unordered-containers >=0.0 && <0.1+ default-language: Haskell2010+ hs-source-dirs: src++test-suite genvalidity-unordered-containers-test+ type: exitcode-stdio-1.0+ main-is: Spec.hs+ build-depends:+ base >=4.9 && <=5,+ unordered-containers -any,+ genvalidity -any,+ genvalidity-hspec -any,+ genvalidity-unordered-containers -any,+ hspec >=2.2 && <2.5+ default-language: Haskell2010+ hs-source-dirs: test/+ other-modules:+ Test.Validity.UnorderedContainersSpec+ ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall
+ src/Data/GenValidity/HashMap.hs view
@@ -0,0 +1,36 @@+{-# OPTIONS_GHC -fno-warn-orphans #-}+{-# LANGUAGE CPP #-}++module Data.GenValidity.HashMap where+#if !MIN_VERSION_base(4,8,0)+import Control.Applicative (pure)+import Data.Functor ((<$>))+#endif+import Data.GenValidity+import Data.Validity.HashMap ()+import Test.QuickCheck++import Data.HashMap.Strict (HashMap)+import qualified Data.HashMap.Strict as HM+import Data.Hashable (Hashable)++instance (Hashable k, Eq k, GenUnchecked k, GenUnchecked v) =>+ GenUnchecked (HashMap k v) where+ genUnchecked = HM.fromList <$> genUnchecked++instance (Hashable k, Eq k, GenValid k, GenValid v) => GenValid (HashMap k v) where+ genValid = HM.fromList <$> genValid++instance (Hashable k, Eq k,GenInvalid k, GenInvalid v) =>+ GenInvalid (HashMap k v) where+ genInvalid =+ sized $ \n -> do+ (k, v, m) <- genSplit3 n+ let go g1 g2 = do+ key <- resize k g1+ val <- resize v g2+ rest <- resize m genUnchecked+ pure $ HM.insert key val rest+ oneof $ [go genInvalid genUnchecked, go genUnchecked genInvalid]+ -- Note: HM.fromList <$> genInvalid does not work because of this line in the Data.HashMap documentation:+ -- 'If the list contains duplicate mappings, the later mappings take precedence.'
+ src/Data/GenValidity/HashSet.hs view
@@ -0,0 +1,22 @@+{-# OPTIONS_GHC -fno-warn-orphans #-}+{-# LANGUAGE CPP #-}++module Data.GenValidity.HashSet where+#if !MIN_VERSION_base(4,8,0)+import Data.Functor ((<$>))+#endif+import Data.GenValidity+import Data.Validity.HashSet ()++import Data.HashSet (HashSet)+import qualified Data.HashSet as HS+import Data.Hashable (Hashable)++instance (Hashable v, Eq v, GenUnchecked v) => GenUnchecked (HashSet v) where+ genUnchecked = HS.fromList <$> genUnchecked++instance (Hashable v, Eq v, GenValid v) => GenValid (HashSet v) where+ genValid = HS.fromList <$> genValid++instance (Hashable v,Eq v, GenInvalid v) => GenInvalid (HashSet v) where+ genInvalid = HS.fromList <$> genInvalid
+ src/Data/GenValidity/UnorderedContainers.hs view
@@ -0,0 +1,6 @@+module Data.GenValidity.UnorderedContainers+ ( module UnorderedContainers+ ) where++import Data.GenValidity.HashMap as UnorderedContainers ()+import Data.GenValidity.HashSet as UnorderedContainers ()
+ test/Spec.hs view
@@ -0,0 +1,1 @@+{-# OPTIONS_GHC -F -pgmF hspec-discover #-}
+ test/Test/Validity/UnorderedContainersSpec.hs view
@@ -0,0 +1,17 @@+{-# LANGUAGE TypeApplications #-}++module Test.Validity.UnorderedContainersSpec where++import Test.Hspec++import Data.GenValidity.UnorderedContainers ()+import Data.HashMap.Strict (HashMap)+import Data.HashSet (HashSet)+import Test.Validity.GenValidity++spec :: Spec+spec = do+ genValidSpec @(HashSet Int)+ genValiditySpec @(HashSet Double)+ genValidSpec @(HashMap Int Double)+ genValiditySpec @(HashMap Double Double)