quickcheck-instances 0.3.13 → 0.3.14
raw patch · 4 files changed
+72/−12 lines, 4 filesdep +quickcheck-instancesdep +uuid-typesdep ~QuickCheckdep ~basedep ~containers
Dependencies added: quickcheck-instances, uuid-types
Dependency ranges changed: QuickCheck, base, containers, tagged
Files
- CHANGES +5/−0
- quickcheck-instances.cabal +17/−5
- src/Test/QuickCheck/Instances.hs +28/−7
- test/Tests.hs +22/−0
CHANGES view
@@ -1,3 +1,8 @@+0.3.14++* Fix `Tree` bug.+* Add `UUID` instances.+ 0.3.13 Author: Oleg Grenrus <oleg.grenrus@iki.fi>
quickcheck-instances.cabal view
@@ -1,5 +1,5 @@ Name: quickcheck-instances-Version: 0.3.13+Version: 0.3.14 Synopsis: Common quickcheck instances Description: QuickCheck instances. .@@ -25,7 +25,7 @@ Category: Testing Build-type: Simple Extra-source-files: CHANGES-Cabal-version: >=1.6+Cabal-version: >=1.8 Tested-With: GHC==7.4.2, GHC==7.6.3,@@ -49,16 +49,28 @@ case-insensitive >=1.2.0.4 && <1.3, containers >= 0.3 && < 0.6, hashable >= 1.1.2.3 && < 1.3,- unordered-containers >= 0.2.1 && < 0.3, old-time >= 1.0 && < 1.2, QuickCheck >= 2.1 && < 2.10,+ scientific >=0.2 && <0.4, tagged >= 0.8.5 && <0.9, text >= 0.7 && < 1.3, time >= 1.1 && < 1.9,- vector >= 0.9 && <0.13,- scientific >=0.2 && <0.4+ unordered-containers >= 0.2.1 && < 0.3,+ uuid-types >=1.0.3 && <1.1,+ vector >= 0.9 && <0.13 Ghc-options: -Wall Other-modules: Test.QuickCheck.Instances.LegacyNumeric -- Build-tools: +test-suite self-test+ type: exitcode-stdio-1.0+ main-is: Tests.hs+ hs-source-dirs: test+ build-depends:+ base,+ QuickCheck,+ quickcheck-instances,+ containers,+ tagged,+ uuid-types
src/Test/QuickCheck/Instances.hs view
@@ -38,6 +38,7 @@ import Data.Ratio import Test.QuickCheck import Test.QuickCheck.Function+import Data.Word (Word32) import qualified Data.Array.IArray as Array import qualified Data.Array.Unboxed as Array@@ -64,7 +65,10 @@ import qualified Data.Vector.Generic as GVector import qualified Data.Vector.Unboxed as UVector import qualified System.Time as OldTime+import qualified Data.UUID.Types as UUID +import Debug.Trace+ import Test.QuickCheck.Instances.LegacyNumeric() -- Array@@ -250,17 +254,18 @@ instance Arbitrary a => Arbitrary (Tree.Tree a) where arbitrary = sized $ \n -> do -- Sized is the size of the trees. value <- arbitrary- pars <- arbPartition (n - 1)+ pars <- arbPartition (n - 1) -- can go negative! forest <- forM pars $ \i -> resize i arbitrary return $ Tree.Node value forest where arbPartition :: Int -> Gen [Int]- arbPartition 0 = pure []- arbPartition 1 = pure [1]- arbPartition k = do- first <- elements [1..k]- rest <- arbPartition $ k - first- return $ first : rest+ arbPartition k = case compare k 1 of+ LT -> pure []+ EQ -> pure [1]+ GT -> do+ first <- elements [1..k]+ rest <- arbPartition $ k - first+ return $ first : rest shrink (Tree.Node val forest) = forest ++ [Tree.Node e fs | (e, fs) <- shrink (val, forest)]@@ -518,3 +523,19 @@ instance Function b => Function (Tagged.Tagged a b) where function = functionMap Tagged.unTagged Tagged.Tagged++-- uuid++uuidFromWords :: (Word32, Word32, Word32, Word32) -> UUID.UUID+uuidFromWords (a,b,c,d) = UUID.fromWords a b c d++-- | Uniform distribution.+instance Arbitrary UUID.UUID where+ arbitrary = uuidFromWords <$> arbitrary+ shrink = map uuidFromWords . shrink . UUID.toWords++instance CoArbitrary UUID.UUID where+ coarbitrary = coarbitrary . UUID.toWords++instance Function UUID.UUID where+ function = functionMap UUID.toWords uuidFromWords
+ test/Tests.hs view
@@ -0,0 +1,22 @@+module Main (main) where++import Data.Proxy (Proxy (..))+import Test.QuickCheck+import Test.QuickCheck.Instances ()++import qualified Data.Tree as Tree+import Data.UUID.Types (UUID)++-- | Example law: == (and thus ===) should be reflexive.+eqReflexive+ :: (Eq a, Show a)+ => Proxy a+ -> a+ -> Property+eqReflexive _ x = x === x++main :: IO ()+main = do+ quickCheck $ eqReflexive (Proxy :: Proxy Int)+ quickCheck $ eqReflexive (Proxy :: Proxy (Tree.Tree Int))+ quickCheck $ eqReflexive (Proxy :: Proxy UUID)