def test_c_cuckoo_filter_load(self): """test loading a saved counting cuckoo filter""" md5sum = "6a98c2df1ec9fbb4f75f8e6392696b9b" with NamedTemporaryFile(dir=os.getcwd(), suffix=".cck", delete=DELETE_TEMP_FILES) as fobj: cko = CountingCuckooFilter(capacity=1000, bucket_size=2, auto_expand=False) for i in range(100): cko.add(str(i)) cko.export(fobj.name) md5_out = calc_file_md5(fobj.name) self.assertEqual(md5sum, md5_out) ckf = CountingCuckooFilter(filepath=fobj.name) for i in range(100): self.assertEqual(ckf.check(str(i)), 1) self.assertEqual(1000, ckf.capacity) self.assertEqual(2, ckf.bucket_size) self.assertEqual(500, ckf.max_swaps) self.assertEqual(0.05, ckf.load_factor())
def test_c_cuckoo_filter_load(self): ''' test loading a saved counting cuckoo filter ''' filename = './test.cck' md5sum = '60e7072e44947b9b6e5d7bd08a64d8a3' cko = CountingCuckooFilter(capacity=1000, bucket_size=2, auto_expand=False) for i in range(100): cko.add(str(i)) cko.export(filename) md5_out = calc_file_md5(filename) self.assertEqual(md5sum, md5_out) ckf = CountingCuckooFilter(filepath=filename) for i in range(100): self.assertEqual(ckf.check(str(i)), 1) self.assertEqual(1000, ckf.capacity) self.assertEqual(2, ckf.bucket_size) self.assertEqual(500, ckf.max_swaps) self.assertEqual(0.05, ckf.load_factor()) os.remove(filename)
def test_c_cuckoo_filter_load(self): """ test loading a saved counting cuckoo filter """ filename = "./test.cck" md5sum = "60e7072e44947b9b6e5d7bd08a64d8a3" cko = CountingCuckooFilter(capacity=1000, bucket_size=2, auto_expand=False) for i in range(100): cko.add(str(i)) cko.export(filename) md5_out = calc_file_md5(filename) self.assertEqual(md5sum, md5_out) ckf = CountingCuckooFilter(filepath=filename) for i in range(100): self.assertEqual(ckf.check(str(i)), 1) self.assertEqual(1000, ckf.capacity) self.assertEqual(2, ckf.bucket_size) self.assertEqual(500, ckf.max_swaps) self.assertEqual(0.05, ckf.load_factor()) os.remove(filename)
def test_c_cuckoo_filter_l_fact(self): """ test the load factor of the counting cuckoo filter """ cko = CountingCuckooFilter(capacity=100, bucket_size=2, max_swaps=10) self.assertEqual(cko.load_factor(), 0.0) for i in range(50): cko.add(str(i)) self.assertEqual(cko.load_factor(), 0.25) for i in range(50): cko.add(str(i + 50)) if cko.capacity == 200: # self expanded self.assertEqual(cko.load_factor(), 0.25) else: self.assertEqual(cko.load_factor(), 0.50) for i in range(100): cko.add(str(i)) if cko.capacity == 200: # self expanded self.assertEqual(cko.load_factor(), 0.25) else: self.assertEqual(cko.load_factor(), 0.50)
def test_c_cuckoo_filter_l_fact(self): ''' test the load factor of the counting cuckoo filter ''' cko = CountingCuckooFilter(capacity=100, bucket_size=2, max_swaps=10) self.assertEqual(cko.load_factor(), 0.0) for i in range(50): cko.add(str(i)) self.assertEqual(cko.load_factor(), 0.25) for i in range(50): cko.add(str(i + 50)) if cko.capacity == 200: # self expanded self.assertEqual(cko.load_factor(), 0.25) else: self.assertEqual(cko.load_factor(), 0.50) for i in range(100): cko.add(str(i)) if cko.capacity == 200: # self expanded self.assertEqual(cko.load_factor(), 0.25) else: self.assertEqual(cko.load_factor(), 0.50)