def test_rbf_push_pop(self): """test forcing push and pop""" blm = RotatingBloomFilter(est_elements=10, false_positive_rate=0.05, max_queue_size=5) self.assertEqual(blm.current_queue_size, 1) blm.add("test") blm.push() self.assertEqual(blm.current_queue_size, 2) self.assertEqual("test" in blm, True) blm.push() self.assertEqual(blm.current_queue_size, 3) self.assertEqual("test" in blm, True) blm.push() self.assertEqual(blm.current_queue_size, 4) self.assertEqual("test" in blm, True) blm.push() self.assertEqual(blm.current_queue_size, 5) self.assertEqual("test" in blm, True) blm.push() self.assertEqual(blm.current_queue_size, 5) self.assertEqual("test" in blm, False) # test popping blm.add("that") blm.pop() self.assertEqual(blm.current_queue_size, 4) self.assertEqual("that" in blm, True) blm.pop() self.assertEqual(blm.current_queue_size, 3) self.assertEqual("that" in blm, True) blm.pop() self.assertEqual(blm.current_queue_size, 2) self.assertEqual("that" in blm, True) blm.pop() self.assertEqual(blm.current_queue_size, 1) self.assertEqual("that" in blm, True)
def test_rbf_push_pop(self): blm = RotatingBloomFilter(est_elements=10, false_positive_rate=0.05, max_queue_size=5) self.assertEqual(blm.current_queue_size, 1) blm.add('test') blm.push() self.assertEqual(blm.current_queue_size, 2) self.assertEqual('test' in blm, True) blm.push() self.assertEqual(blm.current_queue_size, 3) self.assertEqual('test' in blm, True) blm.push() self.assertEqual(blm.current_queue_size, 4) self.assertEqual('test' in blm, True) blm.push() self.assertEqual(blm.current_queue_size, 5) self.assertEqual('test' in blm, True) blm.push() self.assertEqual(blm.current_queue_size, 5) self.assertEqual('test' in blm, False) # test popping blm.add("that") blm.pop() self.assertEqual(blm.current_queue_size, 4) self.assertEqual('that' in blm, True) blm.pop() self.assertEqual(blm.current_queue_size, 3) self.assertEqual('that' in blm, True) blm.pop() self.assertEqual(blm.current_queue_size, 2) self.assertEqual('that' in blm, True) blm.pop() self.assertEqual(blm.current_queue_size, 1) self.assertEqual('that' in blm, True)
def test_rbf_non_basic_import(self): ''' test that the imported rotating Bloom filter is correct ''' blm = RotatingBloomFilter(est_elements=25, false_positive_rate=0.05) for i in range(15): blm.add('{}'.format(i)) blm.push() blm.export('test.rbf') blm2 = RotatingBloomFilter(filepath='test.rbf') # test those that should be popped off... for i in range(5): self.assertEqual('{}'.format(i) in blm2, False) # test things that would not be popped for i in range(6, 15): self.assertEqual('{}'.format(i) in blm2, True) self.assertEqual(blm2.current_queue_size, 10) self.assertEqual(blm2.expansions, 9) os.remove('test.rbf')
def test_rbf_non_basic_import(self): """test that the imported rotating Bloom filter is correct""" with NamedTemporaryFile(dir=os.getcwd(), suffix=".rbf", delete=DELETE_TEMP_FILES) as fobj: blm = RotatingBloomFilter(est_elements=25, false_positive_rate=0.05) for i in range(15): blm.add("{}".format(i)) blm.push() blm.export(fobj.name) blm2 = RotatingBloomFilter(filepath=fobj.name) # test those that should be popped off... for i in range(5): self.assertEqual("{}".format(i) in blm2, False) # test things that would not be popped for i in range(6, 15): self.assertEqual("{}".format(i) in blm2, True) self.assertEqual(blm2.current_queue_size, 10) self.assertEqual(blm2.expansions, 9) self.assertEqual(blm2.elements_added, 15)