genvalidity-containers (empty) → 0.1.0.0
raw patch · 5 files changed
+91/−0 lines, 5 filesdep +QuickCheckdep +basedep +containerssetup-changed
Dependencies added: QuickCheck, base, containers, genvalidity, validity
Files
- LICENSE +21/−0
- Setup.hs +2/−0
- genvalidity-containers.cabal +29/−0
- src/Data/GenValidity/Containers.hs +6/−0
- src/Data/GenValidity/Tree.hs +33/−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,2 @@+import Distribution.Simple+main = defaultMain
+ genvalidity-containers.cabal view
@@ -0,0 +1,29 @@+name: genvalidity-containers+version: 0.1.0.0+synopsis: GenValidity support for containers+description: Please see README.md+homepage: https://github.com/NorfairKing/validity#readme+license: MIT+license-file: LICENSE+author: Tom Sydney Kerckhove+maintainer: syd.kerckhove@gmail.com+copyright: Copyright: (c) 2016 Tom Sydney Kerckhove+category: Testing+build-type: Simple+-- extra-source-files:+cabal-version: >=1.10++library+ hs-source-dirs: src+ exposed-modules: Data.GenValidity.Tree+ , Data.GenValidity.Containers+ build-depends: base < 5+ , validity + , genvalidity+ , containers + , QuickCheck + default-language: Haskell2010++source-repository head+ type: git+ location: https://github.com/NorfairKing/validity
+ src/Data/GenValidity/Containers.hs view
@@ -0,0 +1,6 @@+module Data.GenValidity.Containers+ ( module Containers+ ) where++import Data.GenValidity.Tree as Containers+
+ src/Data/GenValidity/Tree.hs view
@@ -0,0 +1,33 @@+module Data.GenValidity.Tree where++import Data.GenValidity++import Test.QuickCheck++import Data.Tree++instance GenValidity a => GenValidity (Tree a) where+ genUnchecked = genTreeOf genUnchecked++ genValid = genTreeOf genValid++ -- | There should be at least one invalid element, either it's here or it's+ -- further down the tree.+ genInvalid = oneof+ [ Node <$> genInvalid <*> genUnchecked+ , Node <$> genUnchecked <*> genInvalid+ ]++-- | 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 -> -- Sized is the size of the trees.+ case n of+ 0 -> Node <$> func <*> pure []+ 1 -> Node <$> func <*> pure []+ m -> do+ value <- func+ forest <- resize (m - 1) $ genListOf $ genTreeOf func+ return $ Node value forest+