~ubuntu-branches/ubuntu/vivid/haskell-bloomfilter/vivid-201411150845

« back to all changes in this revision

Viewing changes to tests/QC.hs

  • Committer: Package Import Robot
  • Author(s): Joachim Breitner
  • Date: 2013-05-24 12:49:59 UTC
  • mfrom: (2.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20130524124959-so07yc29flwwbqvj
Tags: 1.2.6.10-2
* Bump standards version to 3.9.4
* Use substvars for Haskell description blurbs

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
module Main where
 
2
 
 
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)
 
14
 
 
15
import QCSupport (P(..))
 
16
 
 
17
prop_pai :: (Hashable a) => a -> a -> P -> Bool
 
18
prop_pai _ xs (P q) = let bf = easyList q [xs] in xs `elemB` bf
 
19
 
 
20
tests :: [Test]
 
21
tests = [
 
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
 
40
 ]
 
41
 
 
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
 
49
 
 
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
 
53
prop_rechunked f s =
 
54
    let l = LB.length s
 
55
    in l > 0 ==> forAll (choose (1,l-1)) $ \k ->
 
56
        let n = k `mod` l
 
57
        in n > 0 ==> f s == f (rechunk n s)
 
58
 
 
59
prop_rechunked_eq :: LB.ByteString -> Property
 
60
prop_rechunked_eq = prop_rechunked hash64
 
61
 
 
62
main :: IO ()
 
63
main = defaultMain tests