Beispiel #1
0
def test_no_false_negatives():
    bf = BloomFilter(size=100, hash_funcs=2)
    for ii in range(0, 1000, 20):
        bf.add(ii)

    for ii in range(0, 1000, 20):
        assert ii in bf
Beispiel #2
0
def test_bloom_pickle():
    bf = BloomFilter(size=100, hash_funcs=2)
    for ii in range(0, 1000, 20):
        bf.add(ii)
    data = pickle.dumps(bf)
    bf2 = pickle.loads(data)
    for ii in range(0, 1000, 20):
        assert ii in bf2
Beispiel #3
0
def test_to_from_bytes():
    bf = BloomFilter(size=100, hash_funcs=2)
    for ii in range(0, 1000, 20):
        bf.add(ii)
    data = bf.to_bytes()
    bf2 = BloomFilter()
    for ii in range(0, 1000, 20):
        assert ii not in bf2
    bf2.from_bytes(data)
    for ii in range(0, 1000, 20):
        assert ii in bf2
    assert bf2.to_bytes() == data
Beispiel #4
0
def test_contains():
    bf = BloomFilter()
    assert 23 not in bf
    bf.add(23)
    assert 23 in bf

    bf.add(5)
    bf.add(42)
    bf.add(1002)
    assert 5 in bf
    assert 42 in bf
    assert 1002 in bf