def test_add(self): hs = HashSet([1, 2, 3]) assert hs.items() == [1, 2, 3] # normal add hs.add(4) assert hs.items() == [1, 2, 3, 4] assert hs.size == 4 # try to add duplicate hs.add(4) assert hs.items() == [1, 2, 3, 4] assert hs.size == 4
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_items(self): hs = HashSet([1, 2, 3]) assert hs.items() == [1, 2, 3] hs.add(4) assert hs.items() == [1, 2, 3, 4]