Beispiel #1
0
def test_illegal_index():
    d = SortedDict()
    with pytest.raises(IndexError):
        d.index(0)

    with pytest.raises(TypeError):
        d.index('a')

    with pytest.raises(TypeError):
        d.index()
Beispiel #2
0
def test_index():
    s = SortedDict(ordering='DESC')
    s[1] = "a"
    s[3] = "b"
    s[2] = "c"

    assert s.index(0) == (3, "b")
    assert s.index(1) == (2, "c")
    assert s.index(2) == (1, "a")
    assert s.index(-1) == (1, 'a')
    assert s.index(-2) == (2, 'c')
    assert s.index(-3) == (3, 'b')

    with pytest.raises(IndexError):
        assert s.index(3) == (2, "c")

    with pytest.raises(IndexError):
        assert s.index(4) == (2, "c")