genvalidity-containers-0.8.0.2/bench/0000755000000000000000000000000013612602711015605 5ustar0000000000000000genvalidity-containers-0.8.0.2/src/0000755000000000000000000000000013612602711015315 5ustar0000000000000000genvalidity-containers-0.8.0.2/src/Data/0000755000000000000000000000000013612602711016166 5ustar0000000000000000genvalidity-containers-0.8.0.2/src/Data/GenValidity/0000755000000000000000000000000013620324062020404 5ustar0000000000000000genvalidity-containers-0.8.0.2/test/0000755000000000000000000000000013612602711015505 5ustar0000000000000000genvalidity-containers-0.8.0.2/test/Test/0000755000000000000000000000000013612602711016424 5ustar0000000000000000genvalidity-containers-0.8.0.2/test/Test/Validity/0000755000000000000000000000000013612602711020211 5ustar0000000000000000genvalidity-containers-0.8.0.2/test/Test/Validity/Containers/0000755000000000000000000000000013620324062022315 5ustar0000000000000000genvalidity-containers-0.8.0.2/src/Data/GenValidity/Containers.hs0000644000000000000000000000037713612602711023055 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.8.0.2/src/Data/GenValidity/Map.hs0000644000000000000000000000707213620324062021463 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 (Show k, 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 (Show k, Ord k, GenUnchecked k, GenInvalid k, GenUnchecked v, GenInvalid v) => GenInvalid (Map k v) where genInvalid = oneof [genStructurallyValidMapOfInvalidValues, genStructurallyInvalidMap] #else instance (Show k, Ord k, GenUnchecked k, GenInvalid k, GenUnchecked v, 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, GenUnchecked k, GenInvalid k, GenUnchecked v, 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 :: (Show k, 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.8.0.2/src/Data/GenValidity/Sequence.hs0000644000000000000000000000143513612602711022514 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 shrinkValid = fmap S.fromList . shrinkValid . toList instance (GenUnchecked v, GenInvalid v) => GenInvalid (Seq v) where genInvalid = S.fromList <$> genInvalid shrinkInvalid = fmap S.fromList . shrinkInvalid . toList genvalidity-containers-0.8.0.2/src/Data/GenValidity/Set.hs0000644000000000000000000000603013612602711021473 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 shrinkValid = fmap S.fromList . shrinkValid . S.toList #if MIN_VERSION_containers(0,5,9) instance (Ord v, GenUnchecked v, GenInvalid v) => GenInvalid (Set v) where genInvalid = oneof [genStructurallyValidSetOfInvalidValues, genStructurallyInvalidSet] #else instance (Ord v, GenUnchecked 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, GenUnchecked 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.8.0.2/src/Data/GenValidity/Tree.hs0000644000000000000000000000426713612602711021651 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.List.NonEmpty (NonEmpty(..)) import qualified Data.List.NonEmpty as NE 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 = do ne <- genNonEmptyOf func turnIntoTree ne where turnIntoTree :: NonEmpty a -> Gen (Tree a) turnIntoTree (e :| es) = do groups <- turnIntoGroups es subtrees <- mapM turnIntoTree groups pure (Node e subtrees) turnIntoGroups :: [a] -> Gen [NonEmpty a] turnIntoGroups = go [] where go :: [a] -> [a] -> Gen [NonEmpty a] go acc [] = case NE.nonEmpty acc of Nothing -> pure [] Just ne -> pure [ne] go acc (e:es) = frequency [ ( 1 , do rest <- go [] es pure ((e :| acc) : rest)) , (4, go (e : acc) es) ] genvalidity-containers-0.8.0.2/test/Spec.hs0000644000000000000000000000005413612602711016732 0ustar0000000000000000{-# OPTIONS_GHC -F -pgmF hspec-discover #-} genvalidity-containers-0.8.0.2/test/Test/Validity/Containers/MapSpec.hs0000644000000000000000000000161513612602711024205 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) describe "genStructurallyValidMapOfInvalidValues" $ it "produces valid maps" $ genGeneratesInvalid (genStructurallyValidMapOfInvalidValues @Rational @Rational) #if MIN_VERSION_containers(0,5,9) describe "genStructurallyInvalidMap" $ it "produces invalid maps" $ genGeneratesInvalid (genStructurallyInvalidMap @Rational @Rational) #endif genValidSpec @(Map Int Rational) genValiditySpec @(Map Rational Rational) genvalidity-containers-0.8.0.2/test/Test/Validity/Containers/SeqSpec.hs0000644000000000000000000000043513612602711024217 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.8.0.2/test/Test/Validity/Containers/SetSpec.hs0000644000000000000000000000152113612602711024217 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) describe "genStructurallyValidSetOfInvalidValues" $ it "produces valid sets" $ genGeneratesInvalid (genStructurallyValidSetOfInvalidValues @Rational) #if MIN_VERSION_containers(0,5,9) describe "genStructurallyInvalidSet" $ it "produces invalid sets" $ genGeneratesInvalid (genStructurallyInvalidSet @Rational) #endif genValidSpec @(Set Int) genValiditySpec @(Set Rational) genvalidity-containers-0.8.0.2/test/Test/Validity/Containers/TreeSpec.hs0000644000000000000000000000041113620324062024357 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) genvalidity-containers-0.8.0.2/bench/Main.hs0000644000000000000000000000105413612602711017025 0ustar0000000000000000{-# LANGUAGE AllowAmbiguousTypes #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE ScopedTypeVariables #-} module Main where import Data.Map (Map) import Data.Sequence (Seq) import Data.Set (Set) import Data.Tree (Forest, Tree) import Criterion.Main as Criterion import Data.GenValidity.Containers () import Data.GenValidity.Criterion main :: IO () main = Criterion.defaultMain [ genValidBench @(Set Int) , genValidBench @(Seq Int) , genValidBench @(Tree Int) , genValidBench @(Forest Int) , genValidBench @(Map Int Int) ] genvalidity-containers-0.8.0.2/LICENSE0000644000000000000000000000210413620324062015527 0ustar0000000000000000The MIT License (MIT) 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 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.8.0.2/Setup.hs0000644000000000000000000000005713612602711016164 0ustar0000000000000000import Distribution.Simple main = defaultMain genvalidity-containers-0.8.0.2/genvalidity-containers.cabal0000644000000000000000000000426613620331574022211 0ustar0000000000000000cabal-version: 1.12 -- This file has been generated from package.yaml by hpack version 0.33.0. -- -- see: https://github.com/sol/hpack -- -- hash: cc5a5331fe04afda9869d3afa266c4dca21b717141d42d91d701385413187885 name: genvalidity-containers version: 0.8.0.2 synopsis: GenValidity support for containers category: Testing homepage: https://github.com/NorfairKing/validity#readme bug-reports: https://github.com/NorfairKing/validity/issues author: Tom Sydney Kerckhove maintainer: syd@cs-syd.eu copyright: Copyright: (c) 2016-2020 Tom Sydney Kerckhove license: MIT license-file: LICENSE build-type: Simple extra-source-files: CHANGELOG.md 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 >=4.9 && <=5 , containers , genvalidity >=0.8 , 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 >=0.5 , genvalidity-hspec , genvalidity-property >=0.5 , hspec , validity >=0.9 default-language: Haskell2010 benchmark genvalidity-containers-bench type: exitcode-stdio-1.0 main-is: Main.hs other-modules: Paths_genvalidity_containers hs-source-dirs: bench/ ghc-options: -Wall build-depends: QuickCheck , base >=4.9 && <=5 , containers , criterion , genvalidity-containers , genvalidity-criterion default-language: Haskell2010 genvalidity-containers-0.8.0.2/CHANGELOG.md0000644000000000000000000000154413620324542016345 0ustar0000000000000000# Changelog ## [Unreleased] ## [0.8.0.2] - 2020-02-10 ### Changed * Improved the cabal file * Removed the show constraint for keys on 'GenUnchecked (Map k v)' * Removed the shrinking tests for trees ## [0.8.0.1] - 2019-12-04 ### Changed * Changed the way trees are generated. They will no longer be as top-heavy or under-sized. ## [0.8.0.0] - 2019-09-23 ### Changed * No longer require a 'Show' instance of the map's key for `GenUnchecked` ## [0.7.0.0] - 2019-09-23 ### Changed * Compatibility with validity-containers >=0.5 * Test suite compatibility with genvalidity-property >=0.5 ## [0.6.0.0] - 2019-03-06 ### Changed * Fixed type signatures to be compatible with genvalidity >=0.8 ## [0.5.1.1] - 2018-11-07 ### Changed * Test suite compatibility with validity >=0.9 ## [0.5.1.0] - 2018-10-06 ### Changed * Sped up `shrinkValid` for `Tree`