def test_check_int(self): """ Tests checking for an int in a set. This should fail. """ bf = cBloom.for_capacity(1000, 1e-4) with pytest.raises(TypeError): 1234 in bf
def test_check_none(self): """ Tests checking None in a set. This should fail. """ bf = cBloom.for_capacity(1000, 1e-4) with pytest.raises(TypeError): None in bf
def test_add_int(self): """ Tests adding an int to a set. This should fail. """ bf = cBloom.for_capacity(1000, 1e-4) with pytest.raises(TypeError): bf.add(1234)
def test_add_none(self): """ Tests adding None to a set. This should fail. """ bf = cBloom.for_capacity(1000, 1e-4) with pytest.raises(TypeError): bf.add(None)
def test_length(self): """ Tests that length works """ bf = cBloom.for_capacity(1000, 1e-4) assert len(bf) == 0 [bf.add("test%d" % x) for x in xrange(1000)] assert len(bf) == 1000
def test_prob(self): """ Tests that the bloom filter is only wrong within a certain threshold. """ # Only wrong once per hundred bf = cBloom.for_capacity(1000, 0.01) res = [bf.add("test%d" % x, True) for x in xrange(1000)] num_wrong = len([x for x in res if x is False]) # Should get about 10 wrong assert num_wrong >= 5 assert num_wrong <= 15
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 = cBloom.for_capacity(1e6, 1e-4) # Check the bitmap size assert (len(bf.bitmap) / 8) - cBloom.extra_buffer() == round(19170117 / 8.0) # Check the k num assert bf.k_num == 14 # Parameters uses the ceiling instead of rounding
def test_add_without_check(self): """ Tests that adding to a bloom filter while checking for existing entries works """ bf = cBloom.for_capacity(1000, 1e-4) # Assert all adds work assert all([bf.add("test%d" % x, False) for x in xrange(1000)]) assert all([bf.__contains__("test%d" % x) for x in xrange(1000)]) assert len(bf) == 1000 # Assert all adds work assert all([bf.add("test%d" % x, False) for x in xrange(1000)]) assert len(bf) == 2000