Пример #1
0
 def test_ebf_add_lots_without_force(self):
     ''' testing adding "lots" but force them to be inserted multiple times'''
     blm = ExpandingBloomFilter(est_elements=10, false_positive_rate=0.05)
     # simulate false positives... notice it didn't grow a few...
     for i in range(120):
         blm.add("{}".format(i))
     self.assertEqual(blm.expansions, 9)
     self.assertEqual(blm.elements_added, 120)
Пример #2
0
 def test_ebf_add_lots_without_force(self):
     ''' testing adding "lots" but force them to be inserted multiple times'''
     blm = ExpandingBloomFilter(est_elements=10, false_positive_rate=0.05)
     # simulate false positives... notice it didn't grow a few...
     for i in range(120):
         blm.add("{}".format(i))
     self.assertEqual(blm.expansions, 9)
     self.assertEqual(blm.elements_added, 120)
Пример #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)))
Пример #4
0
    def test_ebf_import_non_empty(self):
        """test expanding Bloom Filter import when non-empty"""
        with NamedTemporaryFile(dir=os.getcwd(), suffix=".ebf", delete=DELETE_TEMP_FILES) as fobj:
            blm = ExpandingBloomFilter(est_elements=25, false_positive_rate=0.05)
            for i in range(15):
                blm.add("{}".format(i))
                blm.push()

            blm.export(fobj.name)

            blm2 = ExpandingBloomFilter(filepath=fobj.name)
            self.assertEqual(blm2.expansions, 15)
            for i in range(15):
                self.assertEqual("{}".format(i) in blm2, True)

            # check for things that are not there!
            for i in range(99, 125):
                self.assertEqual("{}".format(i) in blm2, False)
Пример #5
0
    def test_ebf_import_non_empty(self):
        ''' test expanding Bloom Filter import when non-empty '''
        blm = ExpandingBloomFilter(est_elements=25, false_positive_rate=0.05)
        for i in range(15):
            blm.add('{}'.format(i))
            blm.push()

        blm.export('test.ebf')

        blm2 = ExpandingBloomFilter(filepath='test.ebf')
        self.assertEqual(blm2.expansions, 15)
        for i in range(15):
            self.assertEqual('{}'.format(i) in blm2, True)

        # check for things that are not there!
        for i in range(99, 125):
            self.assertEqual('{}'.format(i) in blm2, False)

        os.remove('test.ebf')
Пример #6
0
    def test_ebf_import_non_empty(self):
        ''' test expanding Bloom Filter import when non-empty '''
        blm = ExpandingBloomFilter(est_elements=25, false_positive_rate=0.05)
        for i in range(15):
            blm.add('{}'.format(i))
            blm.push()

        blm.export('test.ebf')

        blm2 = ExpandingBloomFilter(filepath='test.ebf')
        self.assertEqual(blm2.expansions, 15)
        for i in range(15):
            self.assertEqual('{}'.format(i) in blm2, True)

        # check for things that are not there!
        for i in range(99, 125):
            self.assertEqual('{}'.format(i) in blm2, False)

        os.remove('test.ebf')
Пример #7
0
 def test_ebf_contains(self):
     ''' ensure that "in" functionality for 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('this is a test' in blm, True)
     self.assertEqual('this is another test' in blm, True)
     self.assertEqual('this is yet another test' in blm, False)
     self.assertEqual('this is not another test' in blm, False)
Пример #8
0
 def test_ebf_contains(self):
     ''' ensure that "in" functionality for 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('this is a test' in blm, True)
     self.assertEqual('this is another test' in blm, True)
     self.assertEqual('this is yet another test' in blm, False)
     self.assertEqual('this is not another test' in blm, False)
Пример #9
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)
Пример #10
0
 def test_ebf_add_lots(self):
     ''' test adding "lots" of elements to force the expansion '''
     blm = ExpandingBloomFilter(est_elements=10, false_positive_rate=0.05)
     for i in range(100):
         blm.add("{}".format(i), True)
     self.assertEqual(blm.expansions, 9)
Пример #11
0
 def test_ebf_add_lots(self):
     ''' test adding "lots" of elements to force the expansion '''
     blm = ExpandingBloomFilter(est_elements=10, false_positive_rate=0.05)
     for i in range(100):
         blm.add("{}".format(i), True)
     self.assertEqual(blm.expansions, 9)