def test_constructor(self): s = KeyedSet() assert set(s) == set() assert s._dict == {} s2 = KeyedSet({1, 2, 3}, key=str) assert s2._dict == {"1": 1, "2": 2, "3": 3}
def test_dict_feature(self): s = KeyedSet({1, 2, 3}, key=str) assert list(s.keys()) == ["1", "2", "3"] assert s["1"] == 1 assert s[1] == 1 assert s.get("4") is None assert list(s.items()) == [("1", 1), ("2", 2), ("3", 3)]
def test_discard(self): s = KeyedSet({1, 2, 3}, key=str) s.discard(4) assert len(s) == 3 s.discard(2) assert set(s) == {1, 3} s.discard("1") assert set(s) == {3}
def test_repr(self): s = KeyedSet({1, 2, 3}, key=str) assert repr(s) == "KeyedSet({1, 2, 3})" s2 = KeyedSet[int, str]({1, 2, 3}, key=str) assert repr(s2) == "KeyedSet[int, str]({1, 2, 3})"
def test_equality(self): s = KeyedSet({1, 2, 3}, key=str) assert s == {1, 2, 3} assert s != KeyedSet({1, 2}, key=str) assert s == KeyedSet({1, 2, 3}, key=str) assert s != "hi"
def test_add(self): s = KeyedSet({1, 2, 3}, key=str) s.add(4) assert 4 in s
def test_len(self): assert len(KeyedSet({1, 2, 3}, key=str)) == 3
def test_iter(self): s = KeyedSet({1, 2, 3}, key=str) assert set(iter(s)) == {1, 2, 3}
def test_contains(self): s = KeyedSet({1, 2, 3}, key=str) assert 1 in s assert "1" in s assert 4 not in s assert "4" not in s