on master help sign in
A better test for gh-99
2b13adaBryan O'Sullivan
tests/Tests/Properties.hs+1−2
@@ -741,8 +741,7 @@ tb_decimal :: (Integral a, Show a) => a -> Bool
741tb_decimal = (TB.toLazyText . TB.decimal) `eq` (TL.pack . show)
741tb_decimal = (TB.toLazyText . TB.decimal) `eq` (TL.pack . show)
742
742
743tb_decimal_integer (a::Integer) = tb_decimal a
743tb_decimal_integer (a::Integer) = tb_decimal a
744−tb_decimal_integer_big = forAll big tb_decimal
744+tb_decimal_integer_big (Big a) = tb_decimal a
745− where big = choose (20::Int,200) >>= \e -> choose (10^(e-1),10^e::Integer)
746tb_decimal_int (a::Int) = tb_decimal a
745tb_decimal_int (a::Int) = tb_decimal a
747tb_decimal_int8 (a::Int8) = tb_decimal a
746tb_decimal_int8 (a::Int8) = tb_decimal a
748tb_decimal_int16 (a::Int16) = tb_decimal a
747tb_decimal_int16 (a::Int16) = tb_decimal a
tests/Tests/QuickCheckUtils.hs+10
@@ -18,6 +18,7 @@ module Tests.QuickCheckUtils
18 , unsquare
18 , unsquare
19 , smallArbitrary
19 , smallArbitrary
20
20
21+ , BigInt(..)
21 , NotEmpty (..)
22 , NotEmpty (..)
22
23
23 , Small (..)
24 , Small (..)
@@ -37,6 +38,7 @@ module Tests.QuickCheckUtils
37 , write_read
38 , write_read
38 ) where
39 ) where
39
40
41+import Control.Applicative ((<$>))
40import Control.Arrow (first, (***))
42import Control.Arrow (first, (***))
41import Control.DeepSeq (NFData (..), deepseq)
43import Control.DeepSeq (NFData (..), deepseq)
42import Control.Exception (bracket)
44import Control.Exception (bracket)
@@ -160,6 +162,14 @@ instance Arbitrary TL.Text where
160 arbitrary = (TL.fromChunks . map notEmpty) `fmap` smallArbitrary
162 arbitrary = (TL.fromChunks . map notEmpty) `fmap` smallArbitrary
161 shrink = map TL.pack . shrink . TL.unpack
163 shrink = map TL.pack . shrink . TL.unpack
162
164
165+newtype BigInt = Big Integer
166+ deriving (Eq, Show)
167+
168+instance Arbitrary BigInt where
169+ arbitrary = choose (20::Int,200) >>= \e -> Big <$> choose (10^(e-1),10^e)
170+ shrink (Big a) = [Big (a `div` 2^(l-e)) | e <- shrink l]
171+ where l = truncate (log (fromIntegral a) / log 2 :: Double) :: Integer
172+
163newtype NotEmpty a = NotEmpty { notEmpty :: a }
173newtype NotEmpty a = NotEmpty { notEmpty :: a }
164 deriving (Eq, Ord)
174 deriving (Eq, Ord)
165
175