Beispiel #1
0
def test_delete_works_dll():
    s = ll.DLL(data=0)
    nodes = [s]
    for i in xrange(1, 10):
        nodes.append(ll.DLL(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
            and nodes[i].prev is None)
    assert (nodes[i - 1].nxt == nodes[i + 1]
            and nodes[i + 1].prev == nodes[i - 1])
Beispiel #2
0
def test_inits_correctly():
    s = ll.DLL(data=1, prev=2, nxt=3)
    assert s.data == 1 and s.prev == 2 and s.nxt == 3
    s = ll.DLL(1, 2, 3)
    assert s.data == 1 and s.prev == 2 and s.nxt == 3
Beispiel #3
0
def test_deletes_correctly():
    s = ll.DLL(1, 2, 3)
    s.delete()
    assert s.data is None and s.nxt is None and s.prev is None
Beispiel #4
0
def test_popfront_works_with_one_element():
    s = ll.DLL(1)
    node = ll.popfront(s)
    assert node == s
Beispiel #5
0
def test_popback_works_with_one_element_dll():
    s = ll.DLL(1)
    node = ll.popback(s)
    assert node == s
Beispiel #6
0
def setup(linked_list=True):
    if linked_list:
        return ll.LL(data=1), ll.LL(data=2)
    else:
        return ll.DLL(data=1), ll.DLL(data=2)
Beispiel #7
0
def test_pushfront_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.pushfront(a, b)
Beispiel #8
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)
Beispiel #9
0
def test_delete_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.delete(a, b)
Beispiel #10
0
def test_str_works():
    head = ll.LL(0)
    assert str(head) == "0"
    head = ll.DLL(1)
    assert str(head) == "1"