Beispiel #1
0
def test_erase_head():
    l = SingleLinkedList()
    l.push_front(1)
    assert l.head.data == 1

    l.erase(0)
    assert l.head == None
Beispiel #2
0
def test_front():
    l = SingleLinkedList()
    for i in range(10):
        l.push_back(i)
        assert 0 == l.front()

    l = SingleLinkedList()
    for i in range(10):
        l.push_front(i)
        assert i == l.front()
Beispiel #3
0
def test_reverse():
    l = SingleLinkedList()
    for i in range(5):
        l.push_front(i)

    l.reverse()

    assert l.head.data == 0
    assert l.tail.data == 4
    assert l.tail.next == None

    for i in range(5):
        assert l.pop_front() == i
Beispiel #4
0
def test_push_front():
    l = SingleLinkedList()
    l.push_front(1)
    assert l.head.data == 1
    assert l.tail.data == 1

    l.push_front(2)
    assert l.head.data == 2
    assert l.tail.data == 1
    assert l.head.next.data, l.tail.data

    l.push_front(3)
    assert l.head.data == 3
    assert l.head.next.data == 2