genvalidity-containers-1.0.0.2/bench/0000755000000000000000000000000014552240067015604 5ustar0000000000000000genvalidity-containers-1.0.0.2/src/0000755000000000000000000000000014552240067015314 5ustar0000000000000000genvalidity-containers-1.0.0.2/src/Data/0000755000000000000000000000000014552240067016165 5ustar0000000000000000genvalidity-containers-1.0.0.2/src/Data/GenValidity/0000755000000000000000000000000014672623527020415 5ustar0000000000000000genvalidity-containers-1.0.0.2/test/0000755000000000000000000000000014552240067015504 5ustar0000000000000000genvalidity-containers-1.0.0.2/test/Data/0000755000000000000000000000000014552240067016355 5ustar0000000000000000genvalidity-containers-1.0.0.2/test/Data/GenValidity/0000755000000000000000000000000014552240067020574 5ustar0000000000000000genvalidity-containers-1.0.0.2/test/Data/GenValidity/Containers/0000755000000000000000000000000014672623572022712 5ustar0000000000000000genvalidity-containers-1.0.0.2/src/Data/GenValidity/Containers.hs0000644000000000000000000000044014672575317023057 0ustar0000000000000000module Data.GenValidity.Containers ( module Containers, ) where import Data.GenValidity.IntMap as Containers 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-1.0.0.2/src/Data/GenValidity/IntMap.hs0000644000000000000000000000115614672623527022144 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-orphans #-} module Data.GenValidity.IntMap ( genIntMapOf, shrinkIntMapOf, ) where import Data.GenValidity import Data.IntMap (IntMap) import qualified Data.IntMap as M import Data.Validity.IntMap () import Test.QuickCheck instance (GenValid v) => GenValid (IntMap v) where genValid = genIntMapOf genValid shrinkValid = shrinkIntMapOf shrinkValid genIntMapOf :: Gen (Int, v) -> Gen (IntMap v) genIntMapOf g = M.fromList <$> genListOf g shrinkIntMapOf :: ((Int, v) -> [(Int, v)]) -> IntMap v -> [IntMap v] shrinkIntMapOf shrinker = fmap M.fromList . shrinkList shrinker . M.toList genvalidity-containers-1.0.0.2/src/Data/GenValidity/Map.hs0000644000000000000000000000115614625706051021461 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-orphans #-} module Data.GenValidity.Map ( genMapOf, shrinkMapOf, ) where import Data.GenValidity import Data.Map (Map) import qualified Data.Map as M import Data.Validity.Map () import Test.QuickCheck instance (Show k, Ord k, GenValid k, GenValid v) => GenValid (Map k v) where genValid = genMapOf genValid shrinkValid = shrinkMapOf shrinkValid genMapOf :: (Ord k) => Gen (k, v) -> Gen (Map k v) genMapOf g = M.fromList <$> genListOf g shrinkMapOf :: (Ord k) => ((k, v) -> [(k, v)]) -> Map k v -> [Map k v] shrinkMapOf shrinker = fmap M.fromList . shrinkList shrinker . M.toList genvalidity-containers-1.0.0.2/src/Data/GenValidity/Sequence.hs0000644000000000000000000000112614625706051022511 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-orphans #-} module Data.GenValidity.Sequence ( genSeqOf, shrinkSeqOf, ) where import Data.Foldable (toList) import Data.GenValidity import Data.Sequence (Seq) import qualified Data.Sequence as S import Data.Validity.Sequence () import Test.QuickCheck instance (GenValid v) => GenValid (Seq v) where genValid = genSeqOf genValid shrinkValid = shrinkSeqOf shrinkValid genSeqOf :: Gen v -> Gen (Seq v) genSeqOf g = S.fromList <$> genListOf g shrinkSeqOf :: (v -> [v]) -> Seq v -> [Seq v] shrinkSeqOf shrinker = fmap S.fromList . shrinkList shrinker . toList genvalidity-containers-1.0.0.2/src/Data/GenValidity/Set.hs0000644000000000000000000000302614625706051021475 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-orphans #-} module Data.GenValidity.Set ( genSetOf, shrinkSetOf, genSeperate, genSeperateFor, genSeperateForNE, genValidSeperateFor, genValidSeperateForNE, ) where import Data.Containers.ListUtils import Data.GenValidity import Data.List.NonEmpty (NonEmpty (..)) import qualified Data.List.NonEmpty as NE import Data.Set (Set) import qualified Data.Set as S import Data.Validity.Set () import Test.QuickCheck instance (Ord v, GenValid v) => GenValid (Set v) where genValid = genSetOf genValid shrinkValid = shrinkSetOf shrinkValid genSetOf :: (Ord v) => Gen v -> Gen (Set v) genSetOf g = S.fromList <$> genListOf g shrinkSetOf :: (Ord v) => (v -> [v]) -> Set v -> [Set v] shrinkSetOf shrinker = fmap S.fromList . shrinkList shrinker . S.toList genValidSeperateFor :: (GenValid b, Eq b) => [a] -> Gen [(b, a)] genValidSeperateFor = genSeperateFor genValid genValidSeperateForNE :: (GenValid b, Eq b) => NonEmpty a -> Gen (NonEmpty (b, a)) genValidSeperateForNE = genSeperateForNE genValid genSeperate :: (Ord a) => Gen a -> Gen [a] genSeperate g = nubOrd <$> genListOf g -- TODO these two can likely be optimised genSeperateFor :: (Eq b) => Gen b -> [a] -> Gen [(b, a)] genSeperateFor _ [] = pure [] genSeperateFor g (a : as) = NE.toList <$> genSeperateForNE g (a :| as) genSeperateForNE :: (Eq b) => Gen b -> NonEmpty a -> Gen (NonEmpty (b, a)) genSeperateForNE g (a :| as) = do restTups <- genSeperateFor g as b <- g `suchThat` (`notElem` map fst restTups) pure ((b, a) :| restTups) genvalidity-containers-1.0.0.2/src/Data/GenValidity/Tree.hs0000644000000000000000000000271014625706051021640 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-orphans #-} module Data.GenValidity.Tree (genTreeOf, shrinkTreeOf) where import Data.GenValidity import Data.List.NonEmpty (NonEmpty (..)) import qualified Data.List.NonEmpty as NE import Data.Tree import Data.Validity.Tree () import Test.QuickCheck instance (GenValid a) => GenValid (Tree a) where genValid = genTreeOf genValid shrinkValid = shrinkTreeOf shrinkValid shrinkTreeOf :: (a -> [a]) -> Tree a -> [Tree a] shrinkTreeOf shrinker (Node v ts) = [Node v' ts' | (v', ts') <- shrinkTuple shrinker (shrinkList (shrinkTreeOf shrinker)) (v, 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-1.0.0.2/test/Spec.hs0000644000000000000000000000005414552240067016731 0ustar0000000000000000{-# OPTIONS_GHC -F -pgmF hspec-discover #-} genvalidity-containers-1.0.0.2/test/Data/GenValidity/Containers/IntMapSpec.hs0000644000000000000000000000066514672623572025260 0ustar0000000000000000{-# LANGUAGE TypeApplications #-} module Data.GenValidity.Containers.IntMapSpec where import Data.GenValidity import Data.GenValidity.IntMap import Data.IntMap (IntMap) import Test.Hspec import Test.Validity.GenValidity spec :: Spec spec = do describe "genIntMapOf" $ it "produces valid maps" $ genGeneratesValid (genIntMapOf @Rational genValid) genValidSpec @(IntMap Rational) genValidSpec @(IntMap Rational) genvalidity-containers-1.0.0.2/test/Data/GenValidity/Containers/MapSpec.hs0000644000000000000000000000066414552240067024573 0ustar0000000000000000{-# LANGUAGE TypeApplications #-} module Data.GenValidity.Containers.MapSpec where import Data.GenValidity import Data.GenValidity.Map import Data.Map (Map) import Test.Hspec import Test.Validity.GenValidity spec :: Spec spec = do describe "genMapOf" $ it "produces valid maps" $ genGeneratesValid (genMapOf @Rational @Rational genValid) genValidSpec @(Map Int Rational) genValidSpec @(Map Rational Rational) genvalidity-containers-1.0.0.2/test/Data/GenValidity/Containers/SeqSpec.hs0000644000000000000000000000043014552240067024575 0ustar0000000000000000{-# LANGUAGE TypeApplications #-} module Data.GenValidity.Containers.SeqSpec where import Data.GenValidity.Sequence () import Data.Sequence (Seq) import Test.Hspec import Test.Validity.GenValidity spec :: Spec spec = do genValidSpec @(Seq Int) genValidSpec @(Seq Rational) genvalidity-containers-1.0.0.2/test/Data/GenValidity/Containers/SetSpec.hs0000644000000000000000000000244214552240067024605 0ustar0000000000000000{-# LANGUAGE TypeApplications #-} module Data.GenValidity.Containers.SetSpec where import Data.GenValidity import Data.GenValidity.Set import Data.Set (Set) import Data.Validity.Containers import Test.Hspec import Test.QuickCheck import Test.Validity spec :: Spec spec = do describe "genSetOf" $ it "produces valid sets" $ genGeneratesValid (genSetOf @Rational genValid) genValidSpec @(Set Int) genValidSpec @(Set Rational) describe "genSeperate" $ do it "generates values that are seperate" $ forAll (genSeperate genValid) $ \ls -> distinctOrd (ls :: [Int]) it "generates values that are seperate" $ forAll (genSeperate genValid) $ \ls -> distinctOrd (ls :: [Int]) describe "genSeperateFor" $ do it "generates values that are seperate" $ forAllValid $ \ls -> forAll (genSeperateFor genValid ls) $ \tups -> distinctOrd (map fst (tups :: [(Int, Int)])) it "generates values that are seperate" $ forAllValid $ \ls -> forAll (genSeperateFor genValid ls) $ \tups -> distinctOrd (map fst (tups :: [(Int, Int)])) describe "genValidSeperateFor" $ it "generates values that are seperate" $ forAllValid $ \ls -> forAll (genValidSeperateFor ls) $ \tups -> distinctOrd (map fst (tups :: [(Int, Int)])) genvalidity-containers-1.0.0.2/test/Data/GenValidity/Containers/TreeSpec.hs0000644000000000000000000000041014552240067024742 0ustar0000000000000000{-# LANGUAGE TypeApplications #-} module Data.GenValidity.Containers.TreeSpec where import Data.GenValidity.Tree () import Data.Tree (Tree) import Test.Hspec import Test.Validity spec :: Spec spec = do genValidSpec @(Tree Int) genValidSpec @(Tree Rational) genvalidity-containers-1.0.0.2/bench/Main.hs0000644000000000000000000000276314552240067017034 0ustar0000000000000000{-# LANGUAGE AllowAmbiguousTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-} module Main where import Criterion.Main as Criterion import Data.GenValidity import Data.GenValidity.Containers import Data.GenValidity.Criterion import Data.Map (Map) import Data.Sequence (Seq) import Data.Set (Set) import Data.Tree (Forest, Tree) import Test.QuickCheck main :: IO () main = Criterion.defaultMain [ bgroup "generators" [ genValidBench @(Set Int), genValidBench @(Seq Int), genValidBench @(Tree Int), genValidBench @(Forest Int), genValidBench @(Map Int Int), genBench "genSeqOf" $ genSeqOf (genValid :: Gen Int), genBench "genSetOf" $ genSetOf (genValid :: Gen Int), genBench "genMapOf" $ genMapOf (genValid :: Gen (Int, Int)), genBench "genTreeOf" $ genTreeOf (genValid :: Gen (Int, Int)) ], bgroup "shrinkers" [ shrinkValidBench @(Set Int), shrinkValidBench @(Seq Int), shrinkValidBench @(Tree Int), shrinkValidBench @(Forest Int), shrinkValidBench @(Map Int Int), shrinkBench "shrinkSeqOf" $ shrinkSeqOf (shrinkValid :: Int -> [Int]), shrinkBench "shrinkSetOf" $ shrinkSetOf (shrinkValid :: Int -> [Int]), shrinkBench "shrinkMapOf" $ shrinkMapOf (shrinkValid :: (Int, Int) -> [(Int, Int)]), shrinkBench "shrinkTreeOf" $ shrinkTreeOf (shrinkValid :: Int -> [Int]) ] ] genvalidity-containers-1.0.0.2/LICENSE0000644000000000000000000000210414552240067015527 0ustar0000000000000000The MIT License (MIT) Copyright (c) 2016-2021 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-1.0.0.2/CHANGELOG.md0000644000000000000000000000300014672767071016343 0ustar0000000000000000# Changelog ## [1.0.0.2] - 2022-08-30 ### Added * `GenValid a => GenValid (IntMap a)` ## [1.0.0.1] - 2022-08-30 ### Added * `shrinkSetOf`, `shrinkSeqOf`, `shrinkMapOf`, and `shrinkTreeOf` ## [1.0.0.0] - 2021-11-20 ### Changed * Compatibility with `genvalidity >= 1.0.0.0` ### Removed * `genStructurallyValidMapOf` * `genStructurallyValidMapOfInvalidValues` * `genStructurallyInvalidMap` * `genStructurallyValidSetOf` * `genStructurallyValidSetOfInvalidValues` * `genStructurallyInvalidSet` ## [0.9.0.0] - 2020-06-14 ### Added * `genMapOf` * `genSeqOf` * `genSetOf` ### Changed * Improved the generation of Set, Seq and Map to generate more appropriately (bigger) sized collections ## [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` genvalidity-containers-1.0.0.2/genvalidity-containers.cabal0000644000000000000000000000441314672767071022211 0ustar0000000000000000cabal-version: 1.12 -- This file has been generated from package.yaml by hpack version 0.36.0. -- -- see: https://github.com/sol/hpack name: genvalidity-containers version: 1.0.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-2022 Tom Sydney Kerckhove license: MIT license-file: LICENSE build-type: Simple extra-source-files: LICENSE CHANGELOG.md source-repository head type: git location: https://github.com/NorfairKing/validity library exposed-modules: Data.GenValidity.Containers Data.GenValidity.IntMap 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 >=0.6.0.1 , genvalidity >=1.0 , 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: Data.GenValidity.Containers.IntMapSpec Data.GenValidity.Containers.MapSpec Data.GenValidity.Containers.SeqSpec Data.GenValidity.Containers.SetSpec Data.GenValidity.Containers.TreeSpec Paths_genvalidity_containers hs-source-dirs: test/ ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall build-depends: QuickCheck , base >=4.9 && <=5 , containers , genvalidity , genvalidity-containers , genvalidity-hspec , genvalidity-property , hspec , validity >=0.9 , validity-containers 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 , genvalidity-containers , genvalidity-criterion >=1.1.0.0 default-language: Haskell2010