quickcheck-instances 0.3.11 → 0.3.12
raw patch · 3 files changed
+70/−7 lines, 3 filesdep +scientificdep +vectordep ~QuickCheckdep ~time
Dependencies added: scientific, vector
Dependency ranges changed: QuickCheck, time
Files
- CHANGES +10/−0
- quickcheck-instances.cabal +8/−5
- src/Test/QuickCheck/Instances.hs +52/−2
CHANGES view
@@ -1,3 +1,13 @@+0.3.12++Author: Oleg Grenrus <oleg.grenrus@iki.fi>++* Add vector and scientific instances++Author: RyanGlScott <ryan.gl.scott@gmail.com>++* Fix build with GHC 8.0.1, QuickCheck-2.8.2+ 0.3.11 Author: Timo von Holtz <tvh@anchor.com.au>
quickcheck-instances.cabal view
@@ -1,5 +1,5 @@ Name: quickcheck-instances-Version: 0.3.11+Version: 0.3.12 Synopsis: Common quickcheck instances Description: QuickCheck instances. .@@ -26,6 +26,7 @@ Build-type: Simple Extra-source-files: CHANGES Cabal-version: >=1.6+Tested-with: GHC >= 7.6 && < 8.1 Source-repository head type: git@@ -34,7 +35,7 @@ Library -- Modules exported by the library. Exposed-modules: Test.QuickCheck.Instances- Hs-Source-Dirs: src + Hs-Source-Dirs: src Build-depends: base < 5, array >= 0.3 && < 0.6,@@ -45,9 +46,11 @@ old-time >= 1.0 && < 1.2, QuickCheck >= 2.1 && < 2.9, text >= 0.7 && < 1.3,- time >= 1.1 && < 1.6+ time >= 1.1 && < 1.7,+ vector >= 0.9 && <0.12,+ scientific >=0.2 && <0.4 Ghc-options: -Wall Other-modules: Test.QuickCheck.Instances.LegacyNumeric- -- Build-tools: - + -- Build-tools:+
src/Test/QuickCheck/Instances.hs view
@@ -1,7 +1,7 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE FlexibleContexts #-} {-# OPTIONS_GHC -fno-warn-orphans #-}-{-| +{-| Instances are provided for the types in the packages: * array@@ -53,6 +53,11 @@ import qualified Data.Time as Time import qualified Data.Time.Clock.TAI as Time import qualified Data.Tree as Tree+import qualified Data.Scientific as Scientific+import qualified Data.Vector as Vector+import qualified Data.Vector.Storable as SVector+import qualified Data.Vector.Generic as GVector+import qualified Data.Vector.Unboxed as UVector import qualified System.Time as OldTime import Test.QuickCheck.Instances.LegacyNumeric()@@ -95,6 +100,49 @@ => a i e -> Gen c -> Gen c coarbitraryArray = coarbitrary . Array.assocs +-- vector+instance Arbitrary a => Arbitrary (Vector.Vector a) where+ arbitrary = arbitraryVector+ shrink = shrinkVector++instance CoArbitrary a => CoArbitrary (Vector.Vector a) where+ coarbitrary = coarbitraryVector++instance (SVector.Storable a, Arbitrary a) => Arbitrary (SVector.Vector a) where+ arbitrary = arbitraryVector+ shrink = shrinkVector++instance (SVector.Storable a, CoArbitrary a) => CoArbitrary (SVector.Vector a) where+ coarbitrary = coarbitraryVector++instance (UVector.Unbox a, Arbitrary a) => Arbitrary (UVector.Vector a) where+ arbitrary = arbitraryVector+ shrink = shrinkVector++instance (UVector.Unbox a, CoArbitrary a) => CoArbitrary (UVector.Vector a) where+ coarbitrary = coarbitraryVector++arbitraryVector :: (GVector.Vector v a, Arbitrary a) => Gen (v a)+arbitraryVector = GVector.fromList `fmap` arbitrary++shrinkVector :: (GVector.Vector v a, Arbitrary a) => v a -> [v a]+shrinkVector = fmap GVector.fromList . shrink . GVector.toList++coarbitraryVector :: (GVector.Vector v a, CoArbitrary a) => v a -> Gen b -> Gen b+coarbitraryVector = coarbitrary . GVector.toList++-- scientific+instance Arbitrary Scientific.Scientific where+ arbitrary = do+ c <- arbitrary+ e <- arbitrary+ return $ Scientific.scientific c e+ shrink s = map (uncurry Scientific.scientific) $+ shrink (Scientific.coefficient s, Scientific.base10Exponent s)++instance CoArbitrary Scientific.Scientific where+ coarbitrary s = coarbitrary (Scientific.coefficient s, Scientific.base10Exponent s)+ -- ByteString instance Arbitrary BS.ByteString where arbitrary = BS.pack <$> arbitrary@@ -132,6 +180,7 @@ function = functionMap TL.unpack TL.pack -- Containers+#if !(MIN_VERSION_QuickCheck(2,8,2)) instance Arbitrary a => Arbitrary (IntMap.IntMap a) where arbitrary = IntMap.fromList <$> arbitrary shrink m = IntMap.fromList <$> shrink (IntMap.toList m)@@ -169,6 +218,7 @@ instance (Ord a, Function a) => Function (Set.Set a) where function = functionMap Set.toList Set.fromList+#endif instance (Hashable a, Eq a, Arbitrary a) => Arbitrary (HS.HashSet a) where arbitrary = HS.fromList <$> arbitrary@@ -188,7 +238,7 @@ arbitrary = sized $ \n -> do val <- arbitrary let n' = n `div` 2- nodes <- + nodes <- if n' > 0 then do k <- choose (0,n')