QuickCheck is missing Arbitrary instances for fixed-size integral types
John Millikin
jmillikin at gmail.com
Sat Jun 19 17:27:35 EDT 2010
The 'Data.Int' and 'Data.Word' modules in 'base' define several
fixed-size integral types (Int8-Int64, Word8-Word64). QuickCheck does
not define Arbitrary instances for these. It'd be pretty easy to
include them in QuickCheck, which would make client code less fragile
(since it won't have to define orphan instances).
There's a function already defined in 'Test.QuickCheck.Arbitrary'
which can be used -- just redefine 'arbitrarySizedBoundedInt' as:
arbitrarySizedBoundedIntegral :: (Bounded a, Integral a) => Gen a
arbitrarySizedBoundedIntegral =
# .. function body remains the same ..
and add the following instances:
import Data.Int
import Data.Word
instance Arbitrary Int8 where
arbitrary = arbitrarySizedBoundedIntegral
shrink = shrinkIntegral
instance Arbitrary Int16 where
arbitrary = arbitrarySizedBoundedIntegral
shrink = shrinkIntegral
instance Arbitrary Int32 where
arbitrary = arbitrarySizedBoundedIntegral
shrink = shrinkIntegral
instance Arbitrary Int64 where
arbitrary = arbitrarySizedBoundedIntegral
shrink = shrinkIntegral
instance Arbitrary Word where
arbitrary = arbitrarySizedBoundedIntegral
shrink = shrinkIntegral
instance Arbitrary Word8 where
arbitrary = arbitrarySizedBoundedIntegral
shrink = shrinkIntegral
instance Arbitrary Word16 where
arbitrary = arbitrarySizedBoundedIntegral
shrink = shrinkIntegral
instance Arbitrary Word32 where
arbitrary = arbitrarySizedBoundedIntegral
shrink = shrinkIntegral
instance Arbitrary Word64 where
arbitrary = arbitrarySizedBoundedIntegral
shrink = shrinkIntegral
Thanks!
More information about the QuickCheck
mailing list