def test_c_cuckoo_filter_check(self): """ test checking if element in counting cuckoo filter """ cko = CountingCuckooFilter() cko.add("this is a test") cko.add("this is another test") cko.add("this is yet another test") self.assertEqual(cko.check("this is a test"), True) self.assertEqual(cko.check("this is another test"), True) self.assertEqual(cko.check("this is yet another test"), True) self.assertEqual(cko.check("this is not another test"), False) self.assertEqual(cko.check("this is not a test"), False)
def test_c_cuckoo_filter_check(self): ''' test checking if element in counting cuckoo filter ''' cko = CountingCuckooFilter() cko.add('this is a test') cko.add('this is another test') cko.add('this is yet another test') self.assertEqual(cko.check('this is a test'), True) self.assertEqual(cko.check('this is another test'), True) self.assertEqual(cko.check('this is yet another test'), True) self.assertEqual(cko.check('this is not another test'), False) self.assertEqual(cko.check('this is not a test'), False)
def test_c_cuckoo_filter_rmv_miss(self): """ test removing from the counting cuckoo filter when not present """ cko = CountingCuckooFilter() cko.add("this is a test") self.assertEqual(cko.elements_added, 1) cko.add("this is another test") self.assertEqual(cko.elements_added, 2) cko.add("this is yet another test") self.assertEqual(cko.elements_added, 3) res = cko.remove("this is still a test") self.assertFalse(res) self.assertEqual(cko.elements_added, 3) self.assertTrue(cko.check("this is a test")) self.assertTrue(cko.check("this is another test")) self.assertTrue(cko.check("this is yet another test"))
def test_c_cuckoo_filter_rmv_miss(self): ''' test removing from the counting cuckoo filter when not present ''' cko = CountingCuckooFilter() cko.add('this is a test') self.assertEqual(cko.elements_added, 1) cko.add('this is another test') self.assertEqual(cko.elements_added, 2) cko.add('this is yet another test') self.assertEqual(cko.elements_added, 3) res = cko.remove('this is still a test') self.assertFalse(res) self.assertEqual(cko.elements_added, 3) self.assertTrue(cko.check('this is a test')) self.assertTrue(cko.check('this is another test')) self.assertTrue(cko.check('this is yet another test'))
def test_c_cuckoo_filter_auto_exp(self): """ test inserting until counting cuckoo filter is full """ cko = CountingCuckooFilter(capacity=100, bucket_size=2, max_swaps=100) for i in range(375): # this would fail if it doesn't expand cko.add(str(i)) self.assertEqual(400, cko.capacity) self.assertEqual(375, cko.elements_added) for i in range(375): self.assertGreater(cko.check(str(i)), 0)
def test_c_cuckoo_filter_expand_els(self): """ test out the expansion of the counting cuckoo filter """ cko = CountingCuckooFilter() for i in range(200): cko.add(str(i)) cko.expand() for i in range(200): self.assertGreater(cko.check(str(i)), 0) self.assertEqual(20000, cko.capacity)
def test_c_cuckoo_filter_auto_exp(self): ''' test inserting until counting cuckoo filter is full ''' cko = CountingCuckooFilter(capacity=100, bucket_size=2, max_swaps=100) for i in range(375): # this would fail if it doesn't expand cko.add(str(i)) self.assertEqual(400, cko.capacity) self.assertEqual(375, cko.elements_added) for i in range(375): self.assertGreater(cko.check(str(i)), 0)
def test_c_cuckoo_filter_expand_els(self): ''' test out the expansion of the counting cuckoo filter ''' cko = CountingCuckooFilter() for i in range(200): cko.add(str(i)) cko.expand() for i in range(200): self.assertGreater(cko.check(str(i)), 0) self.assertEqual(20000, cko.capacity)
def test_c_cuckoo_filter_remove(self): """ test removing from the counting cuckoo filter """ cko = CountingCuckooFilter() cko.add("this is a test") self.assertEqual(cko.elements_added, 1) cko.add("this is another test") self.assertEqual(cko.elements_added, 2) cko.add("this is yet another test") self.assertEqual(cko.elements_added, 3) self.assertEqual(cko.unique_elements, 3) cko.add("this is a test") cko.add("this is a test") cko.add("this is a test") self.assertEqual(cko.elements_added, 6) self.assertEqual(cko.unique_elements, 3) res = cko.remove("this is another test") self.assertTrue(res) self.assertEqual(cko.elements_added, 5) self.assertEqual(cko.unique_elements, 2) self.assertTrue(cko.check("this is a test")) self.assertFalse(cko.check("this is another test")) self.assertTrue(cko.check("this is yet another test"))
def test_c_cuckoo_filter_remove(self): ''' test removing from the counting cuckoo filter ''' cko = CountingCuckooFilter() cko.add('this is a test') self.assertEqual(cko.elements_added, 1) cko.add('this is another test') self.assertEqual(cko.elements_added, 2) cko.add('this is yet another test') self.assertEqual(cko.elements_added, 3) self.assertEqual(cko.unique_elements, 3) cko.add('this is a test') cko.add('this is a test') cko.add('this is a test') self.assertEqual(cko.elements_added, 6) self.assertEqual(cko.unique_elements, 3) res = cko.remove('this is another test') self.assertTrue(res) self.assertEqual(cko.elements_added, 5) self.assertEqual(cko.unique_elements, 2) self.assertTrue(cko.check('this is a test')) self.assertFalse(cko.check('this is another test')) self.assertTrue(cko.check('this is yet another test'))
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)
from probables import (CuckooFilter) from probables import (CountingCuckooFilter) cko = CuckooFilter(capacity=100, max_swaps=10) cko.add('google.com') cko.check('facebook.com') # should return False cko.check('google.com') # should return True cck = CountingCuckooFilter(capacity=100, max_swaps=10) cck.add("google") cck.add("google") cck.add("google") print(cck.check("google")) cck.remove("google") print(cck.check("google"))