def test_params_for_capacity(self): """ Tests that the parameters that are generated for a given capacity and probability are correct given known sane values. """ # From http://hur.st/bloomfilter?n=1e6&p=1e-4 bytes, k = cBloom.params_for_capacity(1e6, 1e-4) assert bytes - cBloom.extra_buffer() == round(19170117 / 8.0) assert k == 14 # Parameters uses the ceiling instead of rounding
def test_swap(self): """ Swaps the mmap files from one implementation to another, check that things work. Start with cBloom, then pyBloom. """ bytes, k = cBloom.params_for_capacity(2e4, 1e-3) bitmap = Bitmap(bytes, "testswap1.mmap") bf1 = cBloom(bitmap, k) [bf1.add("foo%d" % x) for x in xrange(20000)] bf1.close() # Make a new bitmap bitmap = Bitmap(bytes, "testswap1.mmap") bf2 = pyBloom(bitmap, 50) assert len(bf2) == 20000 # Should reload size and k assert bf2.k_num == k # Check all the entries assert all([bf2.__contains__("foo%d" % x) for x in xrange(20000)]) bf2.close()
def test_equality_2(self): """ Tests that the two implementation generate matching mmaps """ bytes, k = cBloom.params_for_capacity(2e4, 1e-3) bitmap = Bitmap(bytes, "testcompatc2.mmap") bf1 = cBloom(bitmap, k) [bf1.add("foo%d" % x) for x in xrange(20000)] # Make a new bitmap bitmap = Bitmap(bytes, "testcompatpy2.mmap") bf2 = pyBloom(bitmap, k) [bf2.add("foo%d" % x) for x in xrange(20000)] # Check the lengths assert len(bf1) == len(bf2) bf1.close() bf2.close() # Compare the mmap files self.compare_files("testcompatc2.mmap", "testcompatpy2.mmap")