def test_cbf_union_invalid_msg(self): """ check invalid type in a union message cbf """ msg = "The parameter second must be of type BloomFilter or " "a BloomFilterOnDisk" filename = "tmp.blm" blm = BloomFilterOnDisk(filename, 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) os.remove(filename)
def test_cbf_union_invalid_msg(self): ''' check invalid type in a union message cbf ''' msg = ('The parameter second must be of type BloomFilter or ' 'a BloomFilterOnDisk') filename = 'tmp.blm' blm = BloomFilterOnDisk(filename, 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) os.remove(filename)
def test_bfod_union_invalid_msg(self): """check invalid type in a union message cbf""" msg = "The parameter second must be of type BloomFilter or a BloomFilterOnDisk" with NamedTemporaryFile(dir=os.getcwd(), suffix=".blm", delete=DELETE_TEMP_FILES) as fobj: blm = BloomFilterOnDisk(fobj.name, 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_bfod_union_diff(self): ''' make sure checking for different bloom filters on disk works union ''' filename = 'tmp.blm' blm = BloomFilterOnDisk(filename, 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) os.remove(filename)
def test_bfod_union_diff(self): """make sure checking for different bloom filters on disk works union""" filename = "tmp.blm" blm = BloomFilterOnDisk(filename, 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) os.remove(filename)
def test_bfod_union_diff(self): """make sure checking for different bloom filters on disk works union""" with NamedTemporaryFile(dir=os.getcwd(), suffix=".blm", delete=DELETE_TEMP_FILES) as fobj: blm = BloomFilterOnDisk(fobj.name, 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_bfod_union(self): """ test the union of two bloom filters on disk """ filename = "tmp.blm" blm = BloomFilterOnDisk(filename, 10, 0.05) blm.add("this is a test") blm.add("this is another test") blm2 = BloomFilter(10, 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) blm.close() os.remove(filename)
def test_bfod_union(self): ''' test the union of two bloom filters on disk ''' filename = 'tmp.blm' blm = BloomFilterOnDisk(filename, 10, 0.05) blm.add('this is a test') blm.add('this is another test') blm2 = BloomFilter(10, 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) blm.close() os.remove(filename)
def test_bfod_union(self): """test the union of two bloom filters on disk""" with NamedTemporaryFile(dir=os.getcwd(), suffix=".blm", delete=DELETE_TEMP_FILES) as fobj: blm = BloomFilterOnDisk(fobj.name, 20, 0.05) blm.add("this is a test") blm.add("this is another test") blm2 = BloomFilter(20, 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) blm.close()