Example #1
0
def test_LinkedList_str():
    ll = LinkedList()
    ll.insert("a")
    ll.insert("b")
    actual = str(ll)
    expected = "{ b } -> { a } -> NULL"
    assert actual == expected
Example #2
0
def test_LinkedList_kth_from_end_same_length():
    ll = LinkedList()
    ll.insert(2)
    ll.insert(8)
    actual = ll.kth_from_end(2)
    expected = 8
    assert actual == expected
Example #3
0
def test_LinkedList_kth_from_end_resubmission_0():
    ll = LinkedList()
    ll.insert(5)
    ll.insert(4)
    ll.insert(3)
    ll.insert(2)
    ll.insert(1)
    actual = ll.kth_from_end(0)
    expected = 5
    assert actual == expected
Example #4
0
def test_LinkedList_kth_from_end_ValueError_Exception():
    ll = LinkedList()
    ll.insert(2)
    ll.insert(8)
    ll.insert(3)
    ll.insert(1)
    with pytest.raises(ValueError):
        ll.kth_from_end(-6)
Example #5
0
def test_LinkedList_kth_from_end_0():
    ll = LinkedList()
    ll.insert(2)
    ll.insert(8)
    ll.insert(3)
    ll.insert(1)
    actual = ll.kth_from_end(0)
    expected = 2
    assert actual == expected
Example #6
0
def ll_list():
    """Sets up a linked list instance along with adds a few nodes for testing"""
    ll = LinkedList()
    ll.insert("a")
    ll.insert("b")
    ll.insert("c")
    return ll
Example #7
0
def test_LinkedList_instance():
    assert LinkedList()
Example #8
0
def test_LinkedList_insert():
    ll = LinkedList()
    ll.insert("a")
    ll.insert("b")
    assert ll.head.value == "b"
    assert ll.head.next.value == "a"
Example #9
0
def test_LinkedList_head():
    ll = LinkedList()
    actual = ll.head
    expected = None
    assert actual == expected
Example #10
0
def test_LinkedList_repr():
    ll = LinkedList()
    actual = repr(ll)
    expect = "LinkedList: None"
    assert actual == expect