3
import Control.Monad (forM_)
4
import Data.BloomFilter.Easy (easyList, elemB)
5
import Data.BloomFilter.Hash (Hashable(..), hash64)
6
import qualified Data.ByteString.Char8 as SB
7
import qualified Data.ByteString.Lazy.Char8 as LB
8
import Data.Int (Int8, Int16, Int32, Int64)
9
import Data.Word (Word8, Word16, Word32, Word64)
10
import Test.Framework.Providers.QuickCheck2 (testProperty)
11
import System.IO (BufferMode(..), hSetBuffering, stdout)
12
import Test.Framework (Test, defaultMain)
13
import Test.QuickCheck (Property, Testable, (==>), choose, forAll)
15
import QCSupport (P(..))
17
prop_pai :: (Hashable a) => a -> a -> P -> Bool
18
prop_pai _ xs (P q) = let bf = easyList q [xs] in xs `elemB` bf
22
testProperty "()" $ prop_pai ()
23
, testProperty "Bool" $ prop_pai (undefined :: Bool)
24
, testProperty "Ordering" $ prop_pai (undefined :: Ordering)
25
, testProperty "Char" $ prop_pai (undefined :: Char)
26
, testProperty "Int" $ prop_pai (undefined :: Int)
27
, testProperty "Float" $ prop_pai (undefined :: Float)
28
, testProperty "Double" $ prop_pai (undefined :: Double)
29
, testProperty "Int8" $ prop_pai (undefined :: Int8)
30
, testProperty "Int16" $ prop_pai (undefined :: Int16)
31
, testProperty "Int32" $ prop_pai (undefined :: Int32)
32
, testProperty "Int64" $ prop_pai (undefined :: Int64)
33
, testProperty "Word8" $ prop_pai (undefined :: Word8)
34
, testProperty "Word16" $ prop_pai (undefined :: Word16)
35
, testProperty "Word32" $ prop_pai (undefined :: Word32)
36
, testProperty "Word64" $ prop_pai (undefined :: Word64)
37
, testProperty "String" $ prop_pai (undefined :: String)
38
, testProperty "LB.ByteString" $ prop_pai (undefined :: LB.ByteString)
39
, testProperty "prop_rechunked_eq" prop_rechunked_eq
42
rechunk :: Int64 -> LB.ByteString -> LB.ByteString
43
rechunk k xs | k <= 0 = xs
44
| otherwise = LB.fromChunks (go xs)
45
where go s | LB.null s = []
46
| otherwise = let (pre,suf) = LB.splitAt k s
47
in repack pre : go suf
48
repack = SB.concat . LB.toChunks
50
-- Ensure that a property over a lazy ByteString holds if we change
51
-- the chunk boundaries.
52
prop_rechunked :: Eq a => (LB.ByteString -> a) -> LB.ByteString -> Property
55
in l > 0 ==> forAll (choose (1,l-1)) $ \k ->
57
in n > 0 ==> f s == f (rechunk n s)
59
prop_rechunked_eq :: LB.ByteString -> Property
60
prop_rechunked_eq = prop_rechunked hash64
63
main = defaultMain tests