def test_add(self): set = HashSet() set.add('After the darkness') assert set.size == 1 # added one element set.add('Dertogada') assert set.size == 2 # added a second element set.add('Ramatohara') assert set.size == 3 # added a thrid element set.add('Ramatohara') assert set.size == 3 # element already exist, no size change
def test_add(self): elements = ['J', 'K'] set = HashSet(elements) set.add('P') set.add('E') with self.assertRaises(KeyError): set.add('K') # Element already exists with self.assertRaises(KeyError): set.add('E') # Element already exists assert set.size is 4 assert set.contains('P') is True assert set.contains('E') is True
def test_remove(self): h = HashSet() h.add("Egg") h.add("Tuna") h.remove("Egg") assert h.size == 1
def test_contains(self): h = HashSet() h.add("Mondale") assert h.contains("Mondale") == True assert h.contains("Alfred") == False
def test_add(self): h = HashSet() assert h.size == 0 h.add("Mondale") assert h.size == 1