def test_rbf_pop_exception_msg(self): """rotating bloom filter error: check the resulting error message""" blm = RotatingBloomFilter(est_elements=10, false_positive_rate=0.05, max_queue_size=5) try: blm.pop() except RotatingBloomFilterError as ex: msg = "Popping a Bloom Filter will result in an unusable system!" self.assertEqual(str(ex), msg) except: self.assertEqual(True, False)
def test_rbf_pop_exception_msg(self): ''' rotating bloom filter error: check the resulting error message ''' blm = RotatingBloomFilter(est_elements=10, false_positive_rate=0.05, max_queue_size=5) try: blm.pop() except RotatingBloomFilterError as ex: msg = "Popping a Bloom Filter will result in an unusable system!" self.assertEqual(str(ex), msg) except: self.assertEqual(True, False)
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_pop_exception(self): ''' ensure the correct exception is thrown ''' blm = RotatingBloomFilter(est_elements=10, false_positive_rate=0.05, max_queue_size=5) self.assertRaises(RotatingBloomFilterError, lambda: blm.pop())