def test_nstar_union(self): bloom_one = BloomFilter(200, 0.001) bloom_two = BloomFilter(200, 0.001) chars = [chr(i) for i in range_fn(0, 200)] for char in chars[:int(len(chars)/2)]: bloom_one.add(char) for char in chars[int(len(chars)/2):]: bloom_two.add(char) new_bloom = bloom_one.union(bloom_two) self.assertTrue(bloom_one.nstar() > len(chars)/2-10 and bloom_one.nstar() < len(chars)/2+10) self.assertTrue(bloom_two.nstar() > len(chars)/2-10 and bloom_two.nstar() < len(chars)/2+10) self.assertTrue(new_bloom.nstar() > len(chars)-10 and new_bloom.nstar() < len(chars)+10)
def test_nstar_intersection_2(self): bloom_one = BloomFilter(200, 0.001) bloom_two = BloomFilter(200, 0.001) chars = [chr(i) for i in range_fn(0, 200)] for char in chars[int(len(chars)/2):]: bloom_one.add(char) for char in chars[:int(len(chars)/2)]: bloom_two.add(char) new_bloom = bloom_one.intersection(bloom_two) self.assertTrue(bloom_one.nstar() > len(chars)/2-10 and bloom_one.nstar() < len(chars)/2+10) self.assertTrue(bloom_two.nstar() > len(chars)/2-10 and bloom_two.nstar() < len(chars)/2+10) #The nstar operator will fail on the intersection of the filters.. self.assertTrue(new_bloom.nstar() > 10) self.assertTrue(bloom_one.nstar_intersection(bloom_two) < 10)
def test_nstar(self): bloom = BloomFilter(1000, 0.001) chars = [chr(i) for i in range_fn(0,200)] for char in chars: bloom.add(char) self.assertTrue(bloom.nstar() > len(chars)-10 and bloom.nstar() < len(chars)+10)