Пример #1
0
def test_insertAfter3():
    ll = LinkedList()
    ll.append("1")
    ll.append("2")
    ll.append("2")
    ll.insertAfter("1", "5")
    assert ll.insertAfter("4", "5") == "Node 4 does not exists in Linked List"
    assert ll.insertAfter("8", "10") == "Node 8 does not exists in Linked List"
    assert ll.__str__() == "{1}->{5}->{2}->{2}->None"
Пример #2
0
def test_LinkedList_kthFromEnd():
    test_LinkedList = LinkedList()
    test_LinkedList.insert(5)
    test_LinkedList.insert(35)
    test_LinkedList.insert(4)
    test_LinkedList.append(5555)
    test_LinkedList.insertAfter(35, 1)
    assert test_LinkedList.ll_kth_from_end(0) == 5555
    assert test_LinkedList.ll_kth_from_end(1) == 5
Пример #3
0
def test_LinkedList_insertAfter():
    test_LinkedList = LinkedList()
    test_LinkedList.insert(5)
    test_LinkedList.insert(35)
    test_LinkedList.insert(4)
    test_LinkedList.append(5555)
    test_LinkedList.insertAfter(35, 1)
    assert test_LinkedList.__str__(
    ) == "{ 4 } -> { 35 } -> { 1 } -> { 5 } -> { 5555 } -> NULL"
Пример #4
0
def test_insertAfter_at_last():
    test = LinkedList()
    test.append(0)
    test.append(1)
    test.append(2)
    test.append(3)
    test.insertAfter(3,'at last')
    expected = "{ 0 } -> { 1 } -> { 2 } -> { 3 } -> { at last } -> { Null } -> "
    actual = test.__str__()
    assert expected == actual
Пример #5
0
def test_insertAfter_at_middle():
    test = LinkedList()
    test.append(0)
    test.append(1)
    test.append(2)
    test.append(3)
    test.insertAfter(1,'im middle')
    expected = "{ 0 } -> { 1 } -> { im middle } -> { 2 } -> { 3 } -> { Null } -> "
    actual = test.__str__()
    assert expected == actual
Пример #6
0
def test_six():
    drinks = LinkedList()
    drinks.append('Coffee')
    drinks.append('Ice_Tea')
    drinks.append('Lemonade')
    drinks.append('Mocha')
    drinks.insertBefore('Mocha', 'milkcheck')
    drinks.insertAfter('Ice_Tea', 'Cocktail')
    drinks.deleteNode('Mocha')
    expected = 'Coffee -> Ice_Tea -> Cocktail -> Lemonade -> milkcheck -> None'
    actual = drinks.__str__()
    assert expected == actual
Пример #7
0
def test_eight():
    drinks = LinkedList()
    drinks.append('Coffee')
    drinks.append('Ice_Tea')
    drinks.append('Lemonade')
    drinks.append('Mocha')
    drinks.insertBefore('Mocha', 'milkcheck')
    drinks.insertAfter('Ice_Tea', 'Cocktail')
    drinks.deleteNode('Mocha')
    drinks.get_kth_from_end_ll(6)
    expected = 'Location is greater than the length of LinkedList'
    actual = expected
    assert expected == actual
Пример #8
0
def test_seven():
    drinks = LinkedList()
    drinks.append('Coffee')
    drinks.append('Ice_Tea')
    drinks.append('Lemonade')
    drinks.append('Mocha')
    drinks.insertBefore('Mocha', 'milkcheck')
    drinks.insertAfter('Ice_Tea', 'Cocktail')
    drinks.deleteNode('Mocha')
    drinks.get_kth_from_end_ll(4)
    expected = 'Ice_Tea'
    actual = expected
    assert expected == actual