def test_id_dict_generate_id():
    d = IdDict()
    d.add("a")
    assert len(d) == 1
    assert "a" in d.values()

    d.add("a")
    assert len(d) == 2
def test_id_dict_behave_like_normal_dict():
    d = IdDict()
    d[10] = None
    assert d[10] is None
    assert d.pop(10) is None
    assert_raises(KeyError, lambda: d.pop(10))
    assert d.pop(10, None) is None
    assert len(d) == 0
    d[1] = "a"
    d[1] = "b"
    assert d.popitem() == (1, "b")
    d[2] = 1
    assert 10 not in d
    assert 2 in d
    assert d.get(10, "a") == "a"
    assert d.get(2, None) == 1
    assert len(d) == 1
    assert tuple(d.keys()) == (2,)
    assert tuple(d.values()) == (1,)
    assert tuple(d.items()) == ((2, 1),)

    tmp = {1: 2, 3: "c"}
    d = IdDict(tmp)
    assert len(d) == 2

    # TODO update not implemented
    # d[1] = 3
    # tmp[5] = 'd'
    # d.update(tmp)
    # assert len(d) == 3
    # assert d[1] == 2

    d.clear()
    assert len(d) == 0

    d = IdDict(tmp)
    del d[1]
    assert 1 not in d

    d.setdefault(10, []).append(10)
    assert 10 in d[10]

    d[23] = [1, 2]
    dd = d.copy()
    assert id(dd) != id(d)
    assert tuple(dd.items()) == tuple(d.items())
    d[23][0] = 10
    assert dd[23][0] == 10

    dd = deepcopy(d)
    assert id(dd) != id(d)
    assert tuple(dd.items()) == tuple(d.items())
    d[23][0] = 100
    assert dd[23][0] != 100