Пример #1
0
 def test_ebf_check(self):
     ''' ensure that checking the expanding bloom filter works '''
     blm = ExpandingBloomFilter(est_elements=25, false_positive_rate=0.05)
     # expand it out some first!
     for i in range(100):
         blm.add("{}".format(i))
     blm.add('this is a test')
     blm.add('this is another test')
     self.assertGreater(blm.expansions, 1)
     self.assertEqual(blm.check('this is a test'), True)
     self.assertEqual(blm.check('this is another test'), True)
     self.assertEqual(blm.check('this is yet another test'), False)
     self.assertEqual(blm.check('this is not another test'), False)
Пример #2
0
 def test_ebf_check(self):
     ''' ensure that checking the expanding bloom filter works '''
     blm = ExpandingBloomFilter(est_elements=25, false_positive_rate=0.05)
     # expand it out some first!
     for i in range(100):
         blm.add("{}".format(i))
     blm.add('this is a test')
     blm.add('this is another test')
     self.assertGreater(blm.expansions, 1)
     self.assertEqual(blm.check('this is a test'), True)
     self.assertEqual(blm.check('this is another test'), True)
     self.assertEqual(blm.check('this is yet another test'), False)
     self.assertEqual(blm.check('this is not another test'), False)
Пример #3
0
    def test_ebf_frombytes(self):
        """expanding Bloom Filter load bytes test"""
        blm = ExpandingBloomFilter(est_elements=25, false_positive_rate=0.05)
        for i in range(105):
            blm.add(str(i))
        bytes_out = bytes(blm)

        blm2 = ExpandingBloomFilter.frombytes(bytes_out)
        self.assertEqual(blm2.expansions, 3)
        self.assertEqual(blm2.false_positive_rate, 0.05000000074505806)
        self.assertEqual(blm2.estimated_elements, 25)
        self.assertEqual(blm2.elements_added, 105)
        self.assertEqual(bytes(blm2), bytes(blm))

        for i in range(105):
            self.assertTrue(blm.check(str(i)))