def test_small_bitmap(self): """ Tests initializing with a bitmap that is too small (e.g. less than or equal to the extra_buffer() size) """ with pytest.raises(ValueError): pyBloom(Bitmap(pyBloom.extra_buffer()), 3)
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 = pyBloom.params_for_capacity(1e6, 1e-4) assert bytes - pyBloom.extra_buffer() == round(19170117 / 8.0) assert k == 14 # Parameters uses the ceiling instead of rounding
def test_for_capacity(self): """ Tests that the for_capacity method makes a sane bloom filter using 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 bf = pyBloom.for_capacity(1e6, 1e-4) # Check the bitmap size assert (len(bf.bitmap) / 8) - pyBloom.extra_buffer() == round(19170117 / 8.0) # Check the k num assert bf.k_num == 14 # Parameters uses the ceiling instead of rounding