def test_size(self): hs = HashSet([1, 2, 3]) assert hs.ht.size == 3 assert hs.size == 3 assert len(hs) == 3 hs.add(4) assert hs.ht.size == 4 assert hs.size == 4 assert len(hs) == 4 hs.remove(2) assert hs.ht.size == 3 assert hs.size == 3 assert len(hs) == 3
def test_remove(self): hs = HashSet([1, 2, 3]) assert hs.items() == [1, 2, 3] assert hs.contains(3) == True assert hs.size == 3 # remove item hs.remove(3) assert hs.items() == [1, 2] assert hs.contains(3) == False assert hs.size == 2 with self.assertRaises(KeyError): hs.remove(3)
def test_remove(self): s = HashSet() s.add('S') s.add('H') s.add('A') s.remove('A') assert s.size() == 2 s.remove('H') assert s.size() == 1 s.remove('S') assert s.size() == 0 with self.assertRaises(KeyError): s.remove('S')