Example #1
0
def test_nthNodeValueFromEnd():
    ll = LinkedList()
    ll.append("1")
    ll.append("3")
    ll.append("8")
    ll.append("2")
    assert ll.nthNodeValueFromEnd(0) == "2"
    assert ll.nthNodeValueFromEnd(1) == "8"
    assert ll.nthNodeValueFromEnd(2) == "3"
    assert ll.nthNodeValueFromEnd(3) == "1"
    assert ll.nthNodeValueFromEnd(4) == "Index is out of range"
    assert ll.nthNodeValueFromEnd(5) == "Index is out of range"
    assert ll.nthNodeValueFromEnd(
        -1) == "Negative index is not allowed to search"
    assert ll.nthNodeValueFromEnd(
        -99) == "Negative index is not allowed to search"
Example #2
0
def test_nthNodeValueFromEnd1():
    ll = LinkedList()
    assert ll.nthNodeValueFromEnd(0) == "Index is out of range"
    assert ll.nthNodeValueFromEnd(1) == "Index is out of range"
    ll.append("1")
    assert ll.nthNodeValueFromEnd(0) == "1"