ghcup-hs/3rdparty/zlib/test/Utils.hs
2020-05-10 13:12:39 +02:00

29 lines
800 B
Haskell

{-# OPTIONS_GHC -fno-warn-orphans #-}
module Utils where
import qualified Data.ByteString.Lazy as BL
import qualified Data.ByteString as BS
import Test.QuickCheck
-------------------
-- QuickCheck Utils
maxStrSize :: Double
maxStrSize = 500
-- convert a QC size parameter into one for generating long lists,
-- growing inverse exponentially up to maxStrSize
strSize :: Int -> Int
strSize n = floor (maxStrSize * (1 - 2 ** (-fromIntegral n/100)))
instance Arbitrary BL.ByteString where
arbitrary = sized $ \sz -> fmap BL.fromChunks $ listOf $ resize (sz `div` 2) arbitrary
shrink = map BL.pack . shrink . BL.unpack
instance Arbitrary BS.ByteString where
arbitrary = sized $ \sz -> resize (strSize sz) $ fmap BS.pack $ listOf $ arbitrary
shrink = map BS.pack . shrink . BS.unpack