Esempio n. 1
0
 def test_ebf_export(self):
     ''' basic expanding Bloom Filter export test '''
     blm = ExpandingBloomFilter(est_elements=25, false_positive_rate=0.05)
     blm.export('test.ebf')
     self.assertEqual(calc_file_md5('test.ebf'),
                      'eb5769ae9babdf7b37d6ce64d58812bc')
     os.remove('test.ebf')
Esempio n. 2
0
 def test_ebf_export(self):
     """ basic expanding Bloom Filter export test """
     blm = ExpandingBloomFilter(est_elements=25, false_positive_rate=0.05)
     blm.export("test.ebf")
     self.assertEqual(calc_file_md5("test.ebf"),
                      "eb5769ae9babdf7b37d6ce64d58812bc")
     os.remove("test.ebf")
Esempio n. 3
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)
Esempio n. 4
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)
Esempio n. 5
0
    def test_ebf_import_empty(self):
        """test that expanding Bloom Filter is correct on import"""
        with NamedTemporaryFile(dir=os.getcwd(), suffix=".ebf", delete=DELETE_TEMP_FILES) as fobj:
            blm = ExpandingBloomFilter(est_elements=25, false_positive_rate=0.05)
            blm.export(fobj.name)
            self.assertEqual(calc_file_md5(fobj.name), "eb5769ae9babdf7b37d6ce64d58812bc")

            blm2 = ExpandingBloomFilter(filepath=fobj.name)
            for bloom in blm2._blooms:
                self.assertEqual(bloom.elements_added, 0)
Esempio n. 6
0
    def test_ebf_import_empty(self):
        ''' test that expanding Bloom Filter is correct on import '''
        blm = ExpandingBloomFilter(est_elements=25, false_positive_rate=0.05)
        blm.export('test.ebf')
        self.assertEqual(calc_file_md5('test.ebf'), '1581beab91f83b7e5aaf0f059ee94eaf')

        blm2 = ExpandingBloomFilter(filepath='test.ebf')
        for bloom in blm2._blooms:
            self.assertEqual(bloom.elements_added, 0)

        os.remove('test.ebf')
Esempio n. 7
0
    def test_ebf_import_empty(self):
        ''' test that expanding Bloom Filter is correct on import '''
        blm = ExpandingBloomFilter(est_elements=25, false_positive_rate=0.05)
        blm.export('test.ebf')
        self.assertEqual(calc_file_md5('test.ebf'),
                         'eb5769ae9babdf7b37d6ce64d58812bc')

        blm2 = ExpandingBloomFilter(filepath='test.ebf')
        for bloom in blm2._blooms:
            self.assertEqual(bloom.elements_added, 0)

        os.remove('test.ebf')
Esempio n. 8
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)
Esempio n. 9
0
 def test_ebf_init(self):
     ''' test the initialization of an expanding bloom filter '''
     blm = ExpandingBloomFilter(est_elements=10, false_positive_rate=0.05)
     self.assertEqual(blm.expansions, 0)
     self.assertEqual(blm.false_positive_rate, 0.05)
     self.assertEqual(blm.estimated_elements, 10)
     self.assertEqual(blm.elements_added, 0)
Esempio n. 10
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)
Esempio n. 11
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)
Esempio n. 12
0
    def test_rbf_import_empty(self):
        """ test that rotating Bloom Filter is correct on import """
        blm = RotatingBloomFilter(est_elements=25, false_positive_rate=0.05)
        blm.export("test.rbf")
        self.assertEqual(calc_file_md5("test.rbf"),
                         "eb5769ae9babdf7b37d6ce64d58812bc")

        blm2 = ExpandingBloomFilter(filepath="test.rbf")
        for bloom in blm2._blooms:
            self.assertEqual(bloom.elements_added, 0)

        os.remove("test.rbf")
Esempio n. 13
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)
Esempio n. 14
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')
Esempio n. 15
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)
Esempio n. 16
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')
Esempio n. 17
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)))
Esempio n. 18
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)
Esempio n. 19
0
 def test_ebf_export(self):
     ''' basic expanding Bloom Filter export test '''
     blm = ExpandingBloomFilter(est_elements=25, false_positive_rate=0.05)
     blm.export('test.ebf')
     self.assertEqual(calc_file_md5('test.ebf'), '1581beab91f83b7e5aaf0f059ee94eaf')
     os.remove('test.ebf')
Esempio n. 20
0
 def test_ebf_bytes(self):
     """basic expanding Bloom Filter export bytes test"""
     blm = ExpandingBloomFilter(est_elements=25, false_positive_rate=0.05)
     self.assertEqual(hashlib.md5(bytes(blm)).hexdigest(), "eb5769ae9babdf7b37d6ce64d58812bc")
Esempio n. 21
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)
Esempio n. 22
0
 def test_ebf_export(self):
     """basic expanding Bloom Filter export test"""
     with NamedTemporaryFile(dir=os.getcwd(), suffix=".ebf", delete=DELETE_TEMP_FILES) as fobj:
         blm = ExpandingBloomFilter(est_elements=25, false_positive_rate=0.05)
         blm.export(fobj.name)
         self.assertEqual(calc_file_md5(fobj.name), "eb5769ae9babdf7b37d6ce64d58812bc")
Esempio n. 23
0
 def test_ebf_check(self):
     """ensure that checking the expanding bloom filter works"""
     blm = ExpandingBloomFilter(est_elements=30, 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)
     self.assertEqual(blm.elements_added, 102)