File: QCSupport.hs

package info (click to toggle)
haskell-bloomfilter 2.0.1.2-3
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 200 kB
  • sloc: ansic: 852; haskell: 709; makefile: 13
file content (28 lines) | stat: -rw-r--r-- 857 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
{-# LANGUAGE CPP, GeneralizedNewtypeDeriving #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}

module QCSupport
    (
      P(..)
    ) where

import Data.Int (Int8, Int16, Int32, Int64)
import Data.Word (Word8, Word16, Word32, Word64)
import qualified Data.ByteString.Char8 as SB
import qualified Data.ByteString.Lazy.Char8 as LB
import System.Random (Random(..), RandomGen)
import Test.QuickCheck

newtype P = P { unP :: Double }
    deriving (Eq, Ord, Show, Fractional, Num, Random)

instance Arbitrary P where
    arbitrary = choose (epsilon, 1 - epsilon)
        where epsilon = 1e-6 :: P

instance Arbitrary LB.ByteString where
    arbitrary = sized $ \n -> resize (round (sqrt (toEnum n :: Double)))
                ((LB.fromChunks . filter (not . SB.null)) `fmap` arbitrary)

instance Arbitrary SB.ByteString where
    arbitrary = SB.pack `fmap` arbitrary