Exemplo n.º 1
0
 def test_cbf_intersec_invalid_msg(self):
     """ check invalid type in a intersection message cbf """
     msg = "The parameter second must be of type BloomFilter or " "a BloomFilterOnDisk"
     filename = "tmp.blm"
     blm = BloomFilterOnDisk(filename,
                             est_elements=10,
                             false_positive_rate=0.05)
     blm.add("this is a test")
     try:
         blm.intersection(1)
     except TypeError as ex:
         self.assertEqual(str(ex), msg)
     os.remove(filename)
Exemplo n.º 2
0
 def test_cbf_intersec_invalid_msg(self):
     ''' check invalid type in a intersection message cbf '''
     msg = ('The parameter second must be of type BloomFilter or '
            'a BloomFilterOnDisk')
     filename = 'tmp.blm'
     blm = BloomFilterOnDisk(filename, est_elements=10,
                             false_positive_rate=0.05)
     blm.add('this is a test')
     try:
         blm.intersection(1)
     except TypeError as ex:
         self.assertEqual(str(ex), msg)
     os.remove(filename)
Exemplo n.º 3
0
 def test_cbf_intersec_invalid_msg(self):
     """check invalid type in a intersection message cbf"""
     msg = "The parameter second must be of type BloomFilter or a BloomFilterOnDisk"
     with NamedTemporaryFile(dir=os.getcwd(),
                             suffix=".blm",
                             delete=DELETE_TEMP_FILES) as fobj:
         blm = BloomFilterOnDisk(fobj.name,
                                 est_elements=10,
                                 false_positive_rate=0.05)
         blm.add("this is a test")
         try:
             blm.intersection(1)
         except TypeError as ex:
             self.assertEqual(str(ex), msg)
Exemplo n.º 4
0
 def test_cbf_intersec_invalid_msg(self):
     ''' check invalid type in a intersection message cbf '''
     msg = ('The parameter second must be of type BloomFilter or '
            'a BloomFilterOnDisk')
     filename = 'tmp.blm'
     blm = BloomFilterOnDisk(filename,
                             est_elements=10,
                             false_positive_rate=0.05)
     blm.add('this is a test')
     try:
         blm.intersection(1)
     except TypeError as ex:
         self.assertEqual(str(ex), msg)
     os.remove(filename)
Exemplo n.º 5
0
    def test_bfod_intersection_diff(self):
        ''' make sure checking for different bloom filters on disk works
            intersection
        '''
        filename = 'tmp.blm'
        blm = BloomFilterOnDisk(filename, est_elements=10,
                                false_positive_rate=0.05)
        blm.add('this is a test')
        blm2 = BloomFilter(est_elements=10, false_positive_rate=0.05,
                           hash_function=different_hash)

        blm3 = blm.intersection(blm2)
        self.assertEqual(blm3, None)
        os.remove(filename)
Exemplo n.º 6
0
    def test_bfod_intersection_diff(self):
        """make sure checking for different bloom filters on disk works intersection"""
        with NamedTemporaryFile(dir=os.getcwd(),
                                suffix=".blm",
                                delete=DELETE_TEMP_FILES) as fobj:
            blm = BloomFilterOnDisk(fobj.name,
                                    est_elements=10,
                                    false_positive_rate=0.05)
            blm.add("this is a test")
            blm2 = BloomFilter(est_elements=10,
                               false_positive_rate=0.05,
                               hash_function=different_hash)

            blm3 = blm.intersection(blm2)
            self.assertEqual(blm3, None)
Exemplo n.º 7
0
    def test_bfod_intersection_diff(self):
        """make sure checking for different bloom filters on disk works
        intersection
        """
        filename = "tmp.blm"
        blm = BloomFilterOnDisk(filename,
                                est_elements=10,
                                false_positive_rate=0.05)
        blm.add("this is a test")
        blm2 = BloomFilter(est_elements=10,
                           false_positive_rate=0.05,
                           hash_function=different_hash)

        blm3 = blm.intersection(blm2)
        self.assertEqual(blm3, None)
        os.remove(filename)
Exemplo n.º 8
0
    def test_bfod_intersection(self):
        """ test the intersection of two bloom filters on disk """
        filename = "tmp.blm"
        blm = BloomFilterOnDisk(filename, 10, 0.05)
        blm.add("this is a test")
        blm.add("this is another test")
        blm2 = BloomFilter(10, 0.05)
        blm2.add("this is another test")
        blm2.add("this is yet another test")

        blm3 = blm.intersection(blm2)
        self.assertEqual(blm3.estimate_elements(), 1)
        self.assertEqual(blm3.elements_added, 1)
        self.assertEqual(blm3.check("this is a test"), False)
        self.assertEqual(blm3.check("this is another test"), True)
        self.assertEqual(blm3.check("this is yet another test"), False)
        self.assertEqual(blm3.check("this is not another test"), False)
        blm.close()
        os.remove(filename)
Exemplo n.º 9
0
    def test_bfod_intersection(self):
        ''' test the intersection of two bloom filters on disk '''
        filename = 'tmp.blm'
        blm = BloomFilterOnDisk(filename, 10, 0.05)
        blm.add('this is a test')
        blm.add('this is another test')
        blm2 = BloomFilter(10, 0.05)
        blm2.add('this is another test')
        blm2.add('this is yet another test')

        blm3 = blm.intersection(blm2)
        self.assertEqual(blm3.estimate_elements(), 1)
        self.assertEqual(blm3.elements_added, 1)
        self.assertEqual(blm3.check('this is a test'), False)
        self.assertEqual(blm3.check('this is another test'), True)
        self.assertEqual(blm3.check('this is yet another test'), False)
        self.assertEqual(blm3.check('this is not another test'), False)
        blm.close()
        os.remove(filename)
Exemplo n.º 10
0
    def test_bfod_intersection(self):
        """test the intersection of two bloom filters on disk"""
        with NamedTemporaryFile(dir=os.getcwd(),
                                suffix=".blm",
                                delete=DELETE_TEMP_FILES) as fobj:
            blm = BloomFilterOnDisk(fobj.name, 10, 0.05)
            blm.add("this is a test")
            blm.add("this is another test")
            blm2 = BloomFilter(10, 0.05)
            blm2.add("this is another test")
            blm2.add("this is yet another test")

            blm3 = blm.intersection(blm2)
            self.assertEqual(blm3.estimate_elements(), 1)
            self.assertEqual(blm3.elements_added, 1)
            self.assertEqual(blm3.check("this is a test"), False)
            self.assertEqual(blm3.check("this is another test"), True)
            self.assertEqual(blm3.check("this is yet another test"), False)
            self.assertEqual(blm3.check("this is not another test"), False)
            blm.close()