Example #1
0
class TestBloomFilter(unittest.TestCase):
    def setUp(self):
        self.bf = BloomFilter()

    def test_basic_add(self):
        self.bf.add_elem("example_elem")
        self.assertTrue(self.bf.check_membership("example_elem"))

    def test_basic_empty(self):
        self.assertFalse(self.bf.check_membership("bad"))

    def test_bad_membership_with_elements(self):
        self.assertFalse(self.bf.check_membership("test"))
        self.bf.add_elem("test")
        self.assertTrue(self.bf.check_membership("test"))

    def test_bad_with_one_element(self):
        self.bf.add_elem("test1")
        self.assertFalse(self.bf.check_membership("test2"))
Example #2
0
# Here are a set of very simple tests. Please make sure your code passes the provided tests -- this serves as a check that our grading script will work.
# You are encouraged to add additional tests of your own, but you do not need to submit this file.

from bloom_filter import BloomFilter

bfilter = BloomFilter()
bfilter.add_elem("example_elem")
if not bfilter.check_membership("example_elem"):
    print("bloom filter did not return True for added element ")
Example #3
0
# Here are a set of very simple tests. Please make sure your code passes the provided tests -- this serves as a check that our grading script will work.
# You are encouraged to add additional tests of your own, but you do not need to submit this file.

from bloom_filter import BloomFilter

bfilter = BloomFilter()
bfilter.add_elem("example_elem")
if not bfilter.check_membership("example_elem"):
    print("bloom filter did not return True for added element ")

bloom = BloomFilter(100)
animals = [
    'dog', 'cat', 'giraffe', 'fly', 'mosquito', 'horse', 'eagle', 'bird',
    'bison', 'boar', 'butterfly', 'ant', 'anaconda', 'bear', 'chicken',
    'dolphin', 'donkey', 'crow', 'crocodile'
]
# First insertion of animals into the bloom filter
for animal in animals:
    bloom.add_elem(animal)

    # Membership existence for already inserted animals
    # There should not be any false negatives
for animal in animals:
    if bloom.check_membership(animal):
        print('{} is in bloom filter as expected'.format(animal))
    else:
        print('Something is terribly went wrong for {}'.format(animal))
        print('FALSE NEGATIVE!')

        # Membership existence for not inserted animals
        # There could be false positives