Beispiel #1
0
def test_add_remove_mixed(filled_set):
    assert 0 == filled_set.remove(1)
    assert filled_set[0] == 2
    assert filled_set == OrderedSet(2, 3, 4, 5, 6)
    assert 4 == filled_set.remove(6)
    assert filled_set == OrderedSet(2, 3, 4, 5)
    assert 4 == filled_set.add(7)
    assert filled_set == OrderedSet(2, 3, 4, 5, 7)
Beispiel #2
0
def test_equality():
    s, s2 = OrderedSet(), OrderedSet()

    s.update(1, 2, 3, 4, 5, 6, 7)
    s2.update(1, 2, 3, 4, 5, 6, 7)

    assert s == s2
    s2.remove(1)
    s2.add(1)
    assert not s == s2
Beispiel #3
0
def test_len(filled_set):
    s = OrderedSet()
    s.add(1)
    s.add(1)
    s.add(1)
    s.add(2)
    s.add(3)
    s.remove(1)
    assert len(s) == 2
    assert len(filled_set) == 6
Beispiel #4
0
def test_remove(filled_set):
    filled_set.update(1, 2, 3, 4, 5, "str")
    filled_set.remove_all(4, 6)
    print(filled_set)
    assert filled_set == OrderedSet(1, 2, 3, 5, "str")
    with pytest.raises(ValueError):
        filled_set.remove(-1)
Beispiel #5
0
def test_add_unhashable():
    with pytest.raises(TypeError):
        OrderedSet().add([])
Beispiel #6
0
def test_uniqueness(filled_set):
    filled_set.update(1, 2, 3, 4, 5, 6, 1, 1, 1, 55)
    filled_set.remove(6)
    assert filled_set == OrderedSet(1, 2, 3, 4, 5, 55)
Beispiel #7
0
def test_index_access():
    s = OrderedSet()
    s.update(1, 2, 3, 4, 5, 6, 7)
    assert s[4] == s[-3] == 5
Beispiel #8
0
def test_len2():
    s = OrderedSet()
    s.update(1, 2, 1, 1, 1, 1, 3)
    assert len(s) == 3
Beispiel #9
0
def test_len(filled_set):
    s = OrderedSet(1, 3)
    assert len(s) == 2
    assert len(filled_set) == 6
Beispiel #10
0
def test_remove_first(filled_set):
    assert 0 == filled_set.remove(1)
    assert filled_set[0] == 2
    assert filled_set == OrderedSet(2, 3, 4, 5, 6)
Beispiel #11
0
def filled_set():
    return OrderedSet(1, 2, 3, 4, 5, 6)
Beispiel #12
0
def test_drain_reversed(filled_set):
    e = OrderedSet()
    for item in filled_set.drain(reverse=True):
        e.add(item)
    assert filled_set.is_empty()
    assert str(e) == "OrderedSet(6, 5, 4, 3, 2, 1)"
Beispiel #13
0
def test_drain2(filled_set):
    e = OrderedSet()
    for item in filled_set.drain():
        e.add(item)
    assert filled_set.is_empty()
    assert str(e) == "OrderedSet(1, 2, 3, 4, 5, 6)"