def test_remove(self): items = ['A', 'B', 'C'] hs = HashSet(items) for item in items: # For each item, make sure can only remove once hs.remove(item) with self.assertRaises(KeyError): hs.remove(item) assert hs.size == 0
def test_size(self): hs = HashSet() assert hs.size == 0 hs.add('A') assert hs.size == 1 hs.add('B') assert hs.size == 2 hs.remove('A') assert hs.size == 1 hs.remove('B') assert hs.size == 0
def test_remove(self): new_set = HashSet(['red', 'brown', 'gray']) assert new_set.__length__() == 3 new_set.remove('brown') assert new_set.__length__() == 2 assert new_set.contains('brown') == False assert new_set.contains('red') == True assert new_set.contains('gray') == True new_set.remove('gray') assert new_set.__length__() == 1 assert new_set.contains('red') == True assert new_set.contains('gray') == False