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

    assert ll[0] == 5
    assert ll[1] == 3
    assert ll[2] == 1
예제 #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]
예제 #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)
예제 #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
예제 #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)
예제 #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
예제 #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
예제 #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
예제 #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
예제 #10
0
def test_prepend():
    ll = LinkedList()
    ll.append(5)
    ll.prepend(3)
    ll.prepend(1)

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

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

    assert repr(ll) == '{5, 3, 1, }'
예제 #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
예제 #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
예제 #15
0
def test_indexerror_setitem():
    ll = LinkedList()
    ll.dump(5, 3, 1)

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

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

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

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

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

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

    assert len(ll) == 3
예제 #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)
예제 #24
0
def test_dump():
    ll = LinkedList()
    ll.dump(5, 3, 1)

    assert repr(ll) == '{5, 3, 1, }'
예제 #25
0
def test_insert():
    ll = LinkedList()
    ll.dump(5, 3, 1)
    ll.insert(0, 0)
예제 #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)
예제 #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