From c30ae1cb227b2581d10173bcc49d0e5a4dbe29a4 Mon Sep 17 00:00:00 2001 From: John Goerzen Date: Thu, 29 May 2008 01:18:11 -0500 Subject: [PATCH] Support Word8 in tests --- testsrc/TestInfrastructure.hs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/testsrc/TestInfrastructure.hs b/testsrc/TestInfrastructure.hs index 45d0f0a..83b0b84 100644 --- a/testsrc/TestInfrastructure.hs +++ b/testsrc/TestInfrastructure.hs @@ -23,6 +23,7 @@ import qualified Test.HUnit as HU import qualified Data.Map as Map import System.IO import Text.Printf +import System.Random (@=?) :: (Eq a, Show a) => a -> a -> Result expected @=? actual = @@ -45,6 +46,16 @@ instance (Arbitrary k, Arbitrary v, Eq k, Ord k) => Arbitrary (Map.Map k v) wher return $ Map.fromList items coarbitrary = coarbitrary . Map.keys +instance Arbitrary Word8 where + arbitrary = sized $ \n -> choose (0, min (fromIntegral n) maxBound) + coarbitrary n = variant (if n >= 0 then 2 * x else 2 * x + 1) + where x = abs . fromIntegral $ n + +instance Random Word8 where + randomR (a, b) g = (\(x, y) -> (fromInteger x, y)) $ + randomR (toInteger a, toInteger b) g + random g = randomR (minBound, maxBound) g + -- Modified from HUnit runVerbTestText :: HU.PutText st -> HU.Test -> IO (HU.Counts, st) runVerbTestText (HU.PutText put us) t = do -- 2.39.2