def test_bf_union_invalid_msg(self): """ check invalid type in a union message """ msg = "The parameter second must be of type BloomFilter or " "a BloomFilterOnDisk" blm = BloomFilter(est_elements=10, false_positive_rate=0.05) blm.add("this is a test") try: blm.union(1) except TypeError as ex: self.assertEqual(str(ex), msg) else: self.assertEqual(True, False)
def test_bf_union_invalid_msg(self): ''' check invalid type in a union message ''' msg = ('The parameter second must be of type BloomFilter or ' 'a BloomFilterOnDisk') blm = BloomFilter(est_elements=10, false_positive_rate=0.05) blm.add('this is a test') try: blm.union(1) except TypeError as ex: self.assertEqual(str(ex), msg) else: self.assertEqual(True, False)
def test_bf_union_diff(self): ''' make sure checking for different bloom filters works union ''' blm = BloomFilter(est_elements=10, false_positive_rate=0.05) blm.add('this is a test') blm2 = BloomFilter(est_elements=10, false_positive_rate=0.05, hash_function=different_hash) blm3 = blm.union(blm2) self.assertEqual(blm3, None)
def test_bf_union_diff(self): """ make sure checking for different bloom filters works union """ blm = BloomFilter(est_elements=10, false_positive_rate=0.05) blm.add("this is a test") blm2 = BloomFilter(est_elements=10, false_positive_rate=0.05, hash_function=different_hash) blm3 = blm.union(blm2) self.assertEqual(blm3, None)
def test_bf_union(self): """ test the union of two bloom filters """ blm = BloomFilter(est_elements=10, false_positive_rate=0.05) blm.add("this is a test") blm.add("this is another test") blm2 = BloomFilter(est_elements=10, false_positive_rate=0.05) blm2.add("this is yet another test") blm3 = blm.union(blm2) self.assertEqual(blm3.estimate_elements(), 3) self.assertEqual(blm3.elements_added, 3) self.assertEqual(blm3.check("this is a test"), True) self.assertEqual(blm3.check("this is another test"), True) self.assertEqual(blm3.check("this is yet another test"), True) self.assertEqual(blm3.check("this is not another test"), False)
def test_bf_union(self): ''' test the union of two bloom filters ''' blm = BloomFilter(est_elements=10, false_positive_rate=0.05) blm.add('this is a test') blm.add('this is another test') blm2 = BloomFilter(est_elements=10, false_positive_rate=0.05) blm2.add('this is yet another test') blm3 = blm.union(blm2) self.assertEqual(blm3.estimate_elements(), 3) self.assertEqual(blm3.elements_added, 3) self.assertEqual(blm3.check('this is a test'), True) self.assertEqual(blm3.check('this is another test'), True) self.assertEqual(blm3.check('this is yet another test'), True) self.assertEqual(blm3.check('this is not another test'), False)