Skip to content

Commit 161fb64

Browse files
committed
fix(bloomfilter): add salt to tests
1 parent b9f0d7d commit 161fb64

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

bloomfilter/tests/bloomfilter-tests.hs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module Main (main) where
33
import qualified Data.BloomFilter.Blocked as Bloom.Blocked
44
import qualified Data.BloomFilter.Classic as B
55
import qualified Data.BloomFilter.Classic as Bloom.Classic
6-
import Data.BloomFilter.Hash (Hashable (..), hash64)
6+
import Data.BloomFilter.Hash (Hashable (..))
77

88
import Data.ByteString (ByteString)
99
import qualified Data.ByteString as BS
@@ -90,6 +90,9 @@ tests =
9090
, testProperty "prop_list_ex" $
9191
hash64 [[],[],[BS.empty]] =/= hash64 [[],[BS.empty],[]]
9292
]
93+
where
94+
hash64 :: (Hashable a) => a -> Word64
95+
hash64 = hashSalt64 0
9396

9497
proxyClassic :: Proxy Bloom.Classic.Bloom
9598
proxyClassic = Proxy
@@ -103,10 +106,10 @@ proxyBlocked = Proxy
103106

104107
prop_elem :: forall bloom a. (BloomFilter bloom, Hashable a)
105108
=> Proxy bloom -> Proxy a
106-
-> a -> [a] -> FPR -> Property
107-
prop_elem proxy _ x xs (FPR q) =
109+
-> B.Salt -> a -> [a] -> FPR -> Property
110+
prop_elem proxy _ salt x xs (FPR q) =
108111
let bf :: bloom a
109-
bf = fromList (policyForFPR proxy q) (x:xs)
112+
bf = fromList salt (policyForFPR proxy q) (x:xs)
110113
in elem x bf .&&. not (notElem x bf)
111114

112115
-------------------------------------------------------------------------------
@@ -245,7 +248,9 @@ prop_rechunked f s =
245248
in n > 0 ==> f s === f (rechunk n s)
246249

247250
prop_rechunked_eq :: LBS.ByteString -> Property
248-
prop_rechunked_eq = prop_rechunked hash64
251+
prop_rechunked_eq = prop_rechunked (hashSalt64 salt)
252+
where
253+
salt = 0
249254

250255
-------------------------------------------------------------------------------
251256
-- Bulk operations
@@ -256,12 +261,14 @@ prop_insertMany :: FPR -> [Word64] -> Property
256261
prop_insertMany (FPR fpr) keys =
257262
bloom_insert === bloom_insertMany
258263
where
264+
bloom_salt = 4
265+
259266
bloom_insert =
260-
Bloom.Blocked.create (Bloom.Blocked.sizeForFPR fpr n) $ \mb ->
267+
Bloom.Blocked.create bloom_salt (Bloom.Blocked.sizeForFPR fpr n) $ \mb ->
261268
mapM_ (Bloom.Blocked.insert mb) keys
262269

263270
bloom_insertMany =
264-
Bloom.Blocked.create (Bloom.Blocked.sizeForFPR fpr n) $ \mb ->
271+
Bloom.Blocked.create bloom_salt (Bloom.Blocked.sizeForFPR fpr n) $ \mb ->
265272
Bloom.Blocked.insertMany mb (\k -> pure $ keys !! k) n
266273

267274
!n = length keys
@@ -271,7 +278,7 @@ prop_insertMany (FPR fpr) keys =
271278
-------------------------------------------------------------------------------
272279

273280
class BloomFilter bloom where
274-
fromList :: Hashable a => B.BloomPolicy -> [a] -> bloom a
281+
fromList :: Hashable a => B.Salt -> B.BloomPolicy -> [a] -> bloom a
275282
elem :: Hashable a => a -> bloom a -> Bool
276283
notElem :: Hashable a => a -> bloom a -> Bool
277284

0 commit comments

Comments
 (0)