Example #1
0
def test_getitem():
    ll = LinkedList()
    ll.dump(5, 3, 1)

    assert ll[0] == 5
    assert ll[1] == 3
    assert ll[2] == 1
Example #2
0
def test_indexerror_getitem():
    ll = LinkedList()
    ll.dump(5, 3, 1)

    with pytest.raises(IndexError):
        ll[234]

    with pytest.raises(IndexError):
        ll[3]
Example #3
0
def test_remove():
    ll = LinkedList()
    ll.dump(5, 4, 3, 2, 1)
    ll.remove(1)
    ll.remove(5)

    ll2 = LinkedList()
    ll2.dump(4, 3, 2)

    assert repr(ll) == repr(ll2)
Example #4
0
def test_setitem():
    ll = LinkedList()
    ll.dump(5, 3, 1)
    ll[0] = 2
    ll[1] = 9
    ll[2] = 10

    assert ll[0] == 2
    assert ll[1] == 9
    assert ll[2] == 10
Example #5
0
def test_reverse():
    ll = LinkedList()
    ll.dump(5, 4, 3, 2, 1)

    ll2 = LinkedList()
    ll2.dump(1, 2, 3, 4, 5)

    assert repr(ll.reverse()) == repr(ll2)
Example #6
0
def test_delitem():
    ll = LinkedList()
    ll.dump(5, 3, 1, 0)
    ll2 = LinkedList()
    ll2.dump(3, 1, 0)

    del ll[0]
    assert ll == ll2
Example #7
0
def test_eq():
    ll = LinkedList()
    ll.dump(5, 4, 3, 2, 1)

    ll2 = LinkedList()
    ll2.dump(5, 4, 3, 2, 1)

    assert ll == ll2
Example #8
0
def test_iter():
    ll = LinkedList()
    ll.dump(5, 4, 3, 2, 1)

    ll2 = LinkedList()

    for l in ll:
        ll2.append(l)

    assert ll == ll2
Example #9
0
def test_index():
    ll = LinkedList()
    ll.dump(5, 4, 3, 2, 1)

    assert ll.index(5) == 1
    assert ll.index(3) == 3
    assert ll.index(1) == 5
Example #10
0
def test_prepend():
    ll = LinkedList()
    ll.append(5)
    ll.prepend(3)
    ll.prepend(1)

    assert repr(ll) == '{1, 3, 5, }'
Example #11
0
def test_append():
    ll = LinkedList()
    ll.append(5)
    ll.append(3)
    ll.append(1)

    assert repr(ll) == '(5, (3, (1, ())))'
Example #12
0
def test_append():
    ll = LinkedList()
    ll.append(5)
    ll.append(3)
    ll.append(1)

    assert repr(ll) == '{5, 3, 1, }'
Example #13
0
def test_pop():
    ll = LinkedList()
    ll.dump(5, 3, 1, 0)

    assert ll.pop(0) == 5
    assert ll.pop(2) == 0
    assert ll.pop() == 1
Example #14
0
def test_swap():
    ll = LinkedList()
    ll.dump(5, 4, 3, 2, 1)

    ll.swap(0, 4)
    ll.swap(1, 3)

    assert ll[0] == 1
    assert ll[4] == 5
    assert ll[1] == 2
    assert ll[3] == 4
Example #15
0
def test_indexerror_setitem():
    ll = LinkedList()
    ll.dump(5, 3, 1)

    with pytest.raises(IndexError):
        ll[430] = None
Example #16
0
def test_indexerror_insert():
    ll = LinkedList()
    ll.dump(5, 3, 1)

    with pytest.raises(IndexError):
        ll.insert(6, 2)
Example #17
0
def test_indexerror_delitem():
    ll = LinkedList()
    ll.dump(5, 3, 1, 0)

    with pytest.raises(IndexError):
        del ll[234]
Example #18
0
def test_valueerror_remove():
    ll = LinkedList()
    ll.dump(5, 4, 3, 2, 1)
    with pytest.raises(ValueError):
        ll.remove(8)
Example #19
0
def test_indexerror_pop():
    ll = LinkedList()
    ll.dump(5, 3, 1, 0)

    with pytest.raises(IndexError):
        ll.pop(234)
Example #20
0
def test_valueerror_index():
    ll = LinkedList()
    ll.dump(5, 4, 3, 2, 1)

    with pytest.raises(ValueError):
        ll.index(100)
Example #21
0
def test_lastitem():
    ll = LinkedList()
    ll.dump(5, 4, 3, 2, 1)

    assert ll.lastitem() == 1
    assert ll.lastitem(True) == 5
Example #22
0
def test_len():
    ll = LinkedList()
    ll.dump(5, 3, 1)

    assert len(ll) == 3
Example #23
0
def test_sort():
    ll = LinkedList()
    ll.dump(5, 2, 1, 4, 3)

    ll2 = LinkedList()
    ll2.dump(1, 2, 3, 4, 5)

    ll3 = LinkedList()
    ll3.dump(5, 2, 1, 4, 3)

    ll4 = LinkedList()
    ll4.dump(5, 4, 3, 2, 1)

    ll.sort()
    ll3.sort(reverse=True)

    assert repr(ll) == repr(ll2)
    assert repr(ll3) == repr(ll4)
Example #24
0
def test_dump():
    ll = LinkedList()
    ll.dump(5, 3, 1)

    assert repr(ll) == '{5, 3, 1, }'
Example #25
0
def test_insert():
    ll = LinkedList()
    ll.dump(5, 3, 1)
    ll.insert(0, 0)
Example #26
0
def test_add():
    ll = LinkedList()
    ll.dump(5, 4, 3, 2, 1)

    ll2 = LinkedList()
    ll2.dump(5, 4, 3, 2, 1)

    ll3 = LinkedList()
    ll3.dump(5, 4, 3, 2, 1, 5, 4, 3, 2, 1)

    assert repr(ll + ll2) == repr(ll3)
    assert repr(ll + ll) == repr(ll3)
Example #27
0
def test_count():
    ll = LinkedList()
    ll.dump(5, 4, 3, 2, 1, 5, 1, 2, 3, 4, 5)

    assert ll.count(1) == 2
    assert ll.count(5) == 3