예제 #1
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)
예제 #2
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')
예제 #3
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')
예제 #4
0
 def test_ebf_push(self):
     ''' ensure that we are able to push new Bloom Filters '''
     blm = ExpandingBloomFilter(est_elements=25, false_positive_rate=0.05)
     self.assertEqual(blm.expansions, 0)
     blm.push()
     self.assertEqual(blm.expansions, 1)
     self.assertEqual(blm.elements_added, 0)
     blm.push()
     self.assertEqual(blm.expansions, 2)
     self.assertEqual(blm.elements_added, 0)
     blm.push()
     self.assertEqual(blm.expansions, 3)
     self.assertEqual(blm.elements_added, 0)
예제 #5
0
 def test_ebf_push(self):
     ''' ensure that we are able to push new Bloom Filters '''
     blm = ExpandingBloomFilter(est_elements=25, false_positive_rate=0.05)
     self.assertEqual(blm.expansions, 0)
     blm.push()
     self.assertEqual(blm.expansions, 1)
     self.assertEqual(blm.elements_added, 0)
     blm.push()
     self.assertEqual(blm.expansions, 2)
     self.assertEqual(blm.elements_added, 0)
     blm.push()
     self.assertEqual(blm.expansions, 3)
     self.assertEqual(blm.elements_added, 0)