genvalidity-containers-0.5.1.1/src/0000755000000000000000000000000013325040557015317 5ustar0000000000000000genvalidity-containers-0.5.1.1/src/Data/0000755000000000000000000000000013325040557016170 5ustar0000000000000000genvalidity-containers-0.5.1.1/src/Data/GenValidity/0000755000000000000000000000000013356605410020406 5ustar0000000000000000genvalidity-containers-0.5.1.1/test/0000755000000000000000000000000013325040557015507 5ustar0000000000000000genvalidity-containers-0.5.1.1/test/Test/0000755000000000000000000000000013325040557016426 5ustar0000000000000000genvalidity-containers-0.5.1.1/test/Test/Validity/0000755000000000000000000000000013325040557020213 5ustar0000000000000000genvalidity-containers-0.5.1.1/test/Test/Validity/Containers/0000755000000000000000000000000013370523751022322 5ustar0000000000000000genvalidity-containers-0.5.1.1/src/Data/GenValidity/Containers.hs0000644000000000000000000000037713325040557023057 0ustar0000000000000000module Data.GenValidity.Containers ( module Containers ) where import Data.GenValidity.Map as Containers () import Data.GenValidity.Sequence as Containers () import Data.GenValidity.Set as Containers () import Data.GenValidity.Tree as Containers genvalidity-containers-0.5.1.1/src/Data/GenValidity/Map.hs0000644000000000000000000000667213356605410021472 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-orphans #-} {-# LANGUAGE CPP #-} module Data.GenValidity.Map ( genStructurallyValidMapOf , genStructurallyValidMapOfInvalidValues #if MIN_VERSION_containers(0,5,9) , genStructurallyInvalidMap #endif ) where #if !MIN_VERSION_base(4,8,0) import Control.Applicative (pure, (<$>), (<*>)) #endif import Data.GenValidity import Data.Validity.Map () import Test.QuickCheck import Data.Map (Map) import qualified Data.Map as M #if MIN_VERSION_containers(0,5,9) import qualified Data.Map.Internal as Internal #endif #if MIN_VERSION_containers(0,5,9) instance (Ord k, GenUnchecked k, GenUnchecked v) => GenUnchecked (Map k v) where genUnchecked = sized $ \n -> case n of 0 -> pure Internal.Tip _ -> do (a, b, c, d, e) <- genSplit5 n Internal.Bin <$> resize a genUnchecked <*> resize b genUnchecked <*> resize c genUnchecked <*> resize d genUnchecked <*> resize e genUnchecked shrinkUnchecked Internal.Tip = [] shrinkUnchecked (Internal.Bin s k a m1 m2) = Internal.Tip : [m1, m2] ++ [ Internal.Bin s' k' a' m1' m2' | (s', k', a', m1', m2') <- shrinkUnchecked (s, k, a, m1, m2) ] #else instance (Ord k, GenUnchecked k, GenUnchecked v) => GenUnchecked (Map k v) where genUnchecked = M.fromList <$> genUnchecked shrinkUnchecked = fmap M.fromList . shrinkUnchecked . M.toList #endif instance (Ord k, GenValid k, GenValid v) => GenValid (Map k v) where genValid = M.fromList <$> genValid shrinkValid = fmap M.fromList . shrinkValid . M.toList #if MIN_VERSION_containers(0,5,9) instance (Ord k, GenInvalid k, GenInvalid v) => GenInvalid (Map k v) where genInvalid = oneof [genStructurallyValidMapOfInvalidValues, genStructurallyInvalidMap] #else instance (Ord k, GenInvalid k, GenInvalid v) => GenInvalid (Map k v) where genInvalid = genStructurallyValidMapOfInvalidValues #endif genStructurallyValidMapOf :: Ord k => Gen (k, v) -> Gen (Map k v) genStructurallyValidMapOf g = sized $ \n -> case n of 0 -> pure M.empty _ -> do (kv, m) <- genSplit n (key, val) <- resize kv g rest <- resize m $ genStructurallyValidMapOf g pure $ M.insert key val rest -- Note: M.fromList <$> genInvalid does not work because of this line in the Data.Map documentation: -- ' If the list contains more than one value for the same key, the last value for the key is retained.' genStructurallyValidMapOfInvalidValues :: (Ord k, GenInvalid k, GenInvalid v) => Gen (Map k v) genStructurallyValidMapOfInvalidValues = sized $ \n -> do (k, v, m) <- genSplit3 n let go g1 g2 = do key <- resize k g1 val <- resize v g2 rest <- resize m $ genStructurallyValidMapOf $ (,) <$> genUnchecked <*> genUnchecked pure $ M.insert key val rest oneof [go genInvalid genUnchecked, go genUnchecked genInvalid] #if MIN_VERSION_containers(0,5,9) genStructurallyInvalidMap :: (Ord k, GenUnchecked k, GenUnchecked v) => Gen (Map k v) genStructurallyInvalidMap = do v <- genUnchecked if M.valid v then scale (+ 1) genStructurallyInvalidMap else pure v #endif genvalidity-containers-0.5.1.1/src/Data/GenValidity/Sequence.hs0000644000000000000000000000122513325040557022513 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-orphans #-} {-# LANGUAGE CPP #-} module Data.GenValidity.Sequence where #if !MIN_VERSION_base(4,8,0) import Data.Functor ((<$>)) #endif import Data.Foldable (toList) import Data.GenValidity import Data.Validity.Sequence () import Data.Sequence (Seq) import qualified Data.Sequence as S instance GenUnchecked v => GenUnchecked (Seq v) where genUnchecked = S.fromList <$> genUnchecked shrinkUnchecked = fmap S.fromList . shrinkUnchecked . toList instance GenValid v => GenValid (Seq v) where genValid = S.fromList <$> genValid instance GenInvalid v => GenInvalid (Seq v) where genInvalid = S.fromList <$> genInvalid genvalidity-containers-0.5.1.1/src/Data/GenValidity/Set.hs0000644000000000000000000000565513325040557021511 0ustar0000000000000000{-# LANGUAGE CPP #-} {-# OPTIONS_GHC -fno-warn-orphans #-} module Data.GenValidity.Set ( genStructurallyValidSetOf , genStructurallyValidSetOfInvalidValues #if MIN_VERSION_containers(0,5,9) , genStructurallyInvalidSet #endif ) where #if !MIN_VERSION_base(4,8,0) import Control.Applicative ((<$>), pure) #endif import Data.GenValidity import Data.Validity.Set () import Test.QuickCheck import Data.Set (Set) import qualified Data.Set as S #if MIN_VERSION_containers(0,5,9) import qualified Data.Set.Internal as Internal #endif #if MIN_VERSION_containers(0,5,9) instance (Ord v, GenUnchecked v) => GenUnchecked (Set v) where genUnchecked = sized $ \n -> case n of 0 -> pure Internal.Tip _ -> do (a, b, c, d) <- genSplit4 n Internal.Bin <$> resize a genUnchecked <*> resize b genUnchecked <*> resize c genUnchecked <*> resize d genUnchecked shrinkUnchecked Internal.Tip = [] shrinkUnchecked (Internal.Bin s a s1 s2) = Internal.Tip : [s1, s2] ++ [ Internal.Bin s' a' s1' s2' | (s', a', s1', s2') <- shrinkUnchecked (s, a, s1, s2) ] #else instance (Ord v, GenUnchecked v) => GenUnchecked (Set v) where genUnchecked = S.fromList <$> genUnchecked shrinkUnchecked = fmap S.fromList . shrinkUnchecked . S.toList #endif instance (Ord v, GenValid v) => GenValid (Set v) where genValid = S.fromList <$> genValid #if MIN_VERSION_containers(0,5,9) instance (Ord v, GenInvalid v) => GenInvalid (Set v) where genInvalid = oneof [genStructurallyValidSetOfInvalidValues, genStructurallyInvalidSet] #else instance (Ord v, GenInvalid v) => GenInvalid (Set v) where genInvalid = genStructurallyValidSetOfInvalidValues #endif genStructurallyValidSetOf :: Ord v => Gen v -> Gen (Set v) genStructurallyValidSetOf g = sized $ \n -> case n of 0 -> pure S.empty _ -> do (v, m) <- genSplit n val <- resize v g rest <- resize m $ genStructurallyValidSetOf g pure $ S.insert val rest -- Note: M.fromList <$> genInvalid does not work because of this line in the Data.Set documentation: -- ' If the list contains more than one value for the same key, the last value for the key is retained.' genStructurallyValidSetOfInvalidValues :: (Ord v, GenInvalid v) => Gen (Set v) genStructurallyValidSetOfInvalidValues = sized $ \n -> do (v, m) <- genSplit n val <- resize v genInvalid rest <- resize m $ genStructurallyValidSetOf genUnchecked pure $ S.insert val rest #if MIN_VERSION_containers(0,5,9) genStructurallyInvalidSet :: (Ord v, GenUnchecked v) => Gen (Set v) genStructurallyInvalidSet = do v <- genUnchecked if S.valid v then scale (+ 1) genStructurallyInvalidSet else pure v #endif genvalidity-containers-0.5.1.1/src/Data/GenValidity/Tree.hs0000644000000000000000000000317713356605410021651 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-orphans #-} {-# LANGUAGE CPP #-} module Data.GenValidity.Tree where #if !MIN_VERSION_base(4,8,0) import Control.Applicative ((<*>)) import Data.Functor ((<$>)) #endif import Data.GenValidity import Data.Validity.Tree () import Test.QuickCheck import Data.Tree instance GenUnchecked a => GenUnchecked (Tree a) where genUnchecked = genTreeOf genUnchecked shrinkUnchecked (Node v ts) = [Node v' ts' | (v', ts') <- shrinkUnchecked (v, ts)] instance GenValid a => GenValid (Tree a) where genValid = genTreeOf genValid shrinkValid (Node v ts) = [Node v' ts' | (v', ts') <- shrinkValid (v, ts)] -- | There should be at least one invalid element, either it's here or it's -- further down the tree. instance (GenUnchecked a, GenInvalid a) => GenInvalid (Tree a) where genInvalid = sized $ \n -> do size <- upTo n (a, b) <- genSplit size oneof [ Node <$> resize a genInvalid <*> resize b genUnchecked , Node <$> resize a genUnchecked <*> resize b genInvalid ] shrinkInvalid (Node v ts) = if isInvalid v then Node <$> shrinkInvalid v <*> shrinkUnchecked ts else Node <$> shrinkUnchecked v <*> shrinkInvalid ts -- | Generate a tree of values that are generated as specified. -- -- This takes the size parameter much better into account genTreeOf :: Gen a -> Gen (Tree a) genTreeOf func = sized $ \n -> do size <- upTo n (a, b) <- genSplit size value <- resize a func forest <- resize b $ genListOf $ genTreeOf func return $ Node value forest genvalidity-containers-0.5.1.1/test/Spec.hs0000644000000000000000000000005413325040557016734 0ustar0000000000000000{-# OPTIONS_GHC -F -pgmF hspec-discover #-} genvalidity-containers-0.5.1.1/test/Test/Validity/Containers/MapSpec.hs0000644000000000000000000000172213370523751024210 0ustar0000000000000000{-# LANGUAGE CPP #-} {-# LANGUAGE TypeApplications #-} module Test.Validity.Containers.MapSpec where import Test.Hspec import Data.GenValidity import Data.GenValidity.Map import Data.Map (Map) import Test.Validity.GenValidity spec :: Spec spec = do describe "genStructurallyValidMapOf" $ it "produces valid maps" $ genGeneratesValid (genStructurallyValidMapOf @Rational @Rational genValid) (const []) describe "genStructurallyValidMapOfInvalidValues" $ it "produces valid maps" $ genGeneratesInvalid (genStructurallyValidMapOfInvalidValues @Rational @Rational) (const []) #if MIN_VERSION_containers(0,5,9) describe "genStructurallyInvalidMap" $ it "produces invalid maps" $ genGeneratesInvalid (genStructurallyInvalidMap @Rational @Rational) (const []) #endif genValidSpec @(Map Int Rational) genValiditySpec @(Map Rational Rational) genvalidity-containers-0.5.1.1/test/Test/Validity/Containers/SeqSpec.hs0000644000000000000000000000043513370523751024223 0ustar0000000000000000{-# LANGUAGE TypeApplications #-} module Test.Validity.Containers.SeqSpec where import Test.Hspec import Data.GenValidity.Sequence () import Data.Sequence (Seq) import Test.Validity.GenValidity spec :: Spec spec = do genValidSpec @(Seq Int) genValiditySpec @(Seq Rational) genvalidity-containers-0.5.1.1/test/Test/Validity/Containers/SetSpec.hs0000644000000000000000000000161213370523751024224 0ustar0000000000000000{-# LANGUAGE CPP #-} {-# LANGUAGE TypeApplications #-} module Test.Validity.Containers.SetSpec where import Test.Hspec import Data.GenValidity import Data.GenValidity.Set import Data.Set (Set) import Test.Validity.GenValidity spec :: Spec spec = do describe "genStructurallyValidSetOf" $ it "produces valid sets" $ genGeneratesValid (genStructurallyValidSetOf @Rational genValid) (const []) describe "genStructurallyValidSetOfInvalidValues" $ it "produces valid sets" $ genGeneratesInvalid (genStructurallyValidSetOfInvalidValues @Rational) (const []) #if MIN_VERSION_containers(0,5,9) describe "genStructurallyInvalidSet" $ it "produces invalid sets" $ genGeneratesInvalid (genStructurallyInvalidSet @Rational) (const []) #endif genValidSpec @(Set Int) genValiditySpec @(Set Rational) genvalidity-containers-0.5.1.1/test/Test/Validity/Containers/TreeSpec.hs0000644000000000000000000000052513370523751024372 0ustar0000000000000000{-# LANGUAGE TypeApplications #-} module Test.Validity.Containers.TreeSpec where import Test.Hspec import Data.GenValidity.Tree () import Data.Tree (Tree) import Test.Validity spec :: Spec spec = do genValidSpec @(Tree Int) genValiditySpec @(Tree Rational) shrinkValidSpec @(Tree Int) shrinkValiditySpec @(Tree Rational) genvalidity-containers-0.5.1.1/LICENSE0000644000000000000000000000207713325040557015543 0ustar0000000000000000The 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. genvalidity-containers-0.5.1.1/Setup.hs0000644000000000000000000000005713325040557016166 0ustar0000000000000000import Distribution.Simple main = defaultMain genvalidity-containers-0.5.1.1/genvalidity-containers.cabal0000644000000000000000000000352213370533227022201 0ustar0000000000000000-- This file has been generated from package.yaml by hpack version 0.28.2. -- -- see: https://github.com/sol/hpack -- -- hash: 2351a699b51cc37b65fdb421731fa9392ccdcd8dc374a95a0b5536110d10b2b9 name: genvalidity-containers version: 0.5.1.1 synopsis: GenValidity support for containers description: Please see README.md category: Testing 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 license: MIT license-file: LICENSE build-type: Simple cabal-version: >= 1.10 source-repository head type: git location: https://github.com/NorfairKing/validity library exposed-modules: Data.GenValidity.Containers Data.GenValidity.Map Data.GenValidity.Sequence Data.GenValidity.Set Data.GenValidity.Tree other-modules: Paths_genvalidity_containers hs-source-dirs: src build-depends: QuickCheck , base <5 , containers , genvalidity >=0.5 , validity >=0.5 , validity-containers >=0.3 default-language: Haskell2010 test-suite genvalidity-containers-test type: exitcode-stdio-1.0 main-is: Spec.hs other-modules: Test.Validity.Containers.MapSpec Test.Validity.Containers.SeqSpec Test.Validity.Containers.SetSpec Test.Validity.Containers.TreeSpec Paths_genvalidity_containers hs-source-dirs: test/ ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall build-depends: base >=4.9 && <=5 , containers , genvalidity >=0.7 , genvalidity-containers , genvalidity-hspec , hspec , validity >=0.9 default-language: Haskell2010