[Haskell-beginners] QuickCheck help
Patrick LeBoutillier
patrick.leboutillier at gmail.com
Mon Jul 20 10:01:54 EDT 2009
Hi,
I'm writing a small library to manipulate IPv4 addresses and masks.
The core types are as such:
data IPv4Host = IPv4Host { hbytes :: Word32 }
deriving (Eq)
data IPv4Mask = IPv4Mask { mbytes :: Word32 }
deriving (Eq)
I'm trying to test my library using QuickCheck. My test script looks
like this so far:
import Test.QuickCheck.Batch
import Test.QuickCheck
import Net.IPv4
prop_host_read_show :: Int -> Bool
prop_host_read_show i =
let w = fromIntegral i
h = IPv4Host w
in read . show $ h == h
options = TestOptions { no_of_tests = 100 , length_of_tests = 0 ,
debug_tests = True }
main = do
runTests "IPv4Host" options
[ run prop_host_read_show
]
I'm generating arbitrary Ints that are then converted to Word32
values. The problem is that for 100 tests, all the generated Ints seem
to be
below +/- 100.
How do I get the Ints to be more evenly distributed over the entire 32
bit range? I tried making Word32 and instance if Arbitrary using
choose (0, 0xFFFFFFFF) but I got the same results...
Thanks,
Patrick
--
=====================
Patrick LeBoutillier
Rosemère, Québec, Canada
More information about the Beginners
mailing list