Beispiel #1
0
class BloomFilterTestCase(unittest.TestCase):

    def setUp(self):
        self.bloom_filter = BloomFilter(247, 5)
        self.words = ['hola', 'como', 'estan', 'holis']
        self.bloom_filter.insert_list(self.words)

    def test_initial_conditions(self):
        for word in self.words:
            self.assertEqual(self.bloom_filter.check(word), 1)
    
    def test_word_i_know_not_in(self):
        self.assertEqual(self.bloom_filter.check("xd"), 0)
Beispiel #2
0
    def test_add_item_multiple_items(self):
        '''
        Tests that multiple items can be added to the Bloom Filter.
        '''
        bf = BloomFilter(4, 0.05)
        bf.add('christian')
        bf.add('daniel')
        bf.add('debra')
        bf.add('charles-adrian')

        self.assertTrue(bf.check('christian'))
        self.assertTrue(bf.check('daniel'))
        self.assertTrue(bf.check('debra'))
        self.assertTrue(bf.check('charles-adrian'))
Beispiel #3
0
    def test_check_gives_response_regardless_of_key(self):
        '''
        Tests that the Bloom Filter will give a response
        no matter the key. We cannot test any further, as we don't
        know with certainty whether we'll get a false positive.
        '''
        bf = BloomFilter(1, 0.05)
        bf.add('christian')

        self.assertTrue(bf.check('christian'))

        r1 = bf.check('daniel') in (True, False)
        r2 = bf.check('charles') in (True, False)

        self.assertTrue(r1)
        self.assertTrue(r2)
Beispiel #4
0
    def test_add_item_one_item(self):
        '''
        Tests that an item can be added to the Bloom Filter.
        '''
        bf = BloomFilter(1, 0.05)
        bf.add('christian')

        self.assertTrue(bf.check('christian'))
Beispiel #5
0
    def test_add_item_different_probability_one_item(self):
        '''
        Tests that an item can be added to the Bloom Filter with
        different false positive probabilities.
        '''
        bf = BloomFilter(1, 0.10)
        bf.add('christian')

        self.assertTrue(bf.check('christian'))

        bf = BloomFilter(1, 0.5)
        bf.add('christian')

        self.assertTrue(bf.check('christian'))

        bf = BloomFilter(1, 0.9)
        bf.add('christian')

        self.assertTrue(bf.check('christian'))
 for i in range(ITER):
     bloom_filter = BloomFilter(m, k)
     initial_size_bf.append(get_deep_size(bloom_filter))
     bloom_filter, L_file, universe_file = generate_files_and_insert_to_bloom_filter(
         bloom_filter, big_n, small_n)
     size_after_insertion_bf.append(get_deep_size(bloom_filter))
     current_time_bf = []
     current_time_fl = []
     with open('experimentos/files/universe_file.txt',
               'r') as universe_file:
         total_usernames_list = [
             w.strip('\n') for w in universe_file.readlines()
         ]
         for username_query in total_usernames_list:
             ti_bf = time.time()
             username_might_be_in_file = bloom_filter.check(
                 username_query)
             tf_bf = time.time()
             dt_bf = tf_bf - ti_bf
             current_time_bf.append(dt_bf)
             if username_might_be_in_file == 1:
                 disk_access[i] += 1
                 ti_fl = time.time()
                 username_in_file = search_username_in_file(
                     username_query, 'experimentos/files/L_file.txt')
                 tf_fl = time.time()
                 dt_fl = (tf_fl - ti_fl) * 19
                 current_time_fl.append(dt_fl)
                 if username_in_file is None:
                     false_positives[i] += 1
     universe_file.close()
     search_times_fl.append(
Beispiel #7
0
    def test_add_item_different_probability_multiple_items(self):
        '''
        Tests that multiple items can be added to the Bloom Filter with
        different false positive probabilities.
        '''
        bf = BloomFilter(4, 0.10)
        bf.add('christian')
        bf.add('daniel')
        bf.add('debra')
        bf.add('charles-adrian')

        self.assertTrue(bf.check('christian'))
        self.assertTrue(bf.check('daniel'))
        self.assertTrue(bf.check('debra'))
        self.assertTrue(bf.check('charles-adrian'))

        bf = BloomFilter(4, 0.50)
        bf.add('christian')
        bf.add('daniel')
        bf.add('debra')
        bf.add('charles-adrian')

        self.assertTrue(bf.check('christian'))
        self.assertTrue(bf.check('daniel'))
        self.assertTrue(bf.check('debra'))
        self.assertTrue(bf.check('charles-adrian'))

        bf = BloomFilter(4, 0.9)
        bf.add('christian')
        bf.add('daniel')
        bf.add('debra')
        bf.add('charles-adrian')

        self.assertTrue(bf.check('christian'))
        self.assertTrue(bf.check('daniel'))
        self.assertTrue(bf.check('debra'))
        self.assertTrue(bf.check('charles-adrian'))