Example #1
0
def test_popback_works_dll():
    s, o = setup(False)
    ll.pushback(s, o)
    node = ll.popback(s)
    assert s.nxt is None
    assert node == o
    assert node.data == 2 and node.prev is None
Example #2
0
def test_popback_works_ll():
    s, o = setup()
    ll.pushback(s, o)
    node = ll.popback(s)
    assert s.nxt is None
    assert node == o
    assert node.data == 2
Example #3
0
def test_delete_works_ll():
    s = ll.LL(data=0)
    nodes = [s]
    for i in xrange(1, 10):
        nodes.append(ll.LL(data=i))
        ll.pushback(s, nodes[-1])

    i = 7
    ll.delete(nodes[3], nodes[i])
    assert nodes[i].data is None and nodes[i].nxt is None
    assert nodes[i - 1].nxt == nodes[i + 1]
Example #4
0
def test_pushback_mixed_types_fail():
    s = ll.LL(data=1)
    o = ll.DLL(data=2)
    for a, b in ((s, o), (o, s)):
        with pytest.raises(AssertionError):
            ll.pushback(a, b)
Example #5
0
def test_pushback_works_dll():
    s, o = setup(False)
    node = ll.pushback(s, o)
    assert s.nxt == o
    assert o.prev == s
    assert node == o
Example #6
0
def test_doubly_to_list():
    head = ll.DLL(0)
    ll.pushback(head, ll.DLL(1))
    ll.pushback(head, ll.DLL(2))
    lst = ll.to_list(head)
    assert lst == range(3)
Example #7
0
def test_pushback_works_ll():
    s, o = setup()
    node = ll.pushback(s, o)
    assert s.nxt == o
    assert node == o