class TestBloomMethods(unittest.TestCase): """Test the Bloom Filter.""" def setUp(self): """Set up the Bloom Filter table.""" self.size = 10 self.b = Bloom(self.size) def test_add(self): """Make sure that add properly activates bits in the table.""" self.b.add('Archimedes') self.assertEqual(self.b.table, [1, 0, 0, 1, 0, 0, 0, 0, 0, 0]) def test_check_element_in_table(self): """Ensure check method returns true if element was added.""" self.b.add('Copernicus') self.assertEqual(self.b.check('Copernicus'), True) def test_check_element_not_in_table(self): """Ensure check method returns false if elmt definitely not in set.""" self.assertEqual(self.b.check('Galileo'), False)
def main(): """Main function.""" bloom = Bloom(12) # Add some values to the set bloom.add("Curie") bloom.add("Laplace") # Now test some values person = "Pasteur" if (bloom.check(person)): print("%s is probably in the set." % person) else: print("%s is definitely not in the set." % person) # Test some more values person = "Curie" if (bloom.check(person)): print("%s is probably in the set." % person) else: print("%s is definitely not in the set." % person)