Example #1
0
def test_one():
    drinks = LinkedList()
    drinks.append("Coffee")
    drinks.append("Ice_Tea")
    drinks.includes("Lemonade")
    expected = 'Coffee -> Ice_Tea -> Lemonade -> None'
    actual = drinks.__str__()
    assert expected == actual
Example #2
0
def test_two():
    drinks = LinkedList()
    drinks.append("Coffee")
    drinks.append("Ice_Tea")
    drinks.includes("Lemonade")
    expected = False
    actual = drinks.includes("Milk")
    assert expected == actual
Example #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"
Example #4
0
def test_LinkedList_insertBefore():
    test_LinkedList = LinkedList()
    test_LinkedList.insert(5)
    test_LinkedList.insert(35)
    test_LinkedList.insert(4)
    test_LinkedList.append(5555)
    test_LinkedList.insertBefore(35, 0)
    assert test_LinkedList.__str__(
    ) == "{ 4 } -> { 0 } -> { 35 } -> { 5 } -> { 5555 } -> NULL"
Example #5
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
Example #6
0
def test_deleteNode2():
    ll = LinkedList()
    ll.append("1")
    ll.append("3")
    ll.append("2")
    ll.deleteNode("1")
    assert ll.deleteNode("4") == "Node 4 does not exists in Linked List"
    assert ll.deleteNode("8") == "Node 8 does not exists in Linked List"
    assert ll.__str__() == "{3}->{2}->None"
Example #7
0
def test_kth_from_end_at_zero():
    test = LinkedList()
    test.append(0)
    test.append(1)
    test.append(2)
    test.append(3)
    expected = 3
    actual =test.kth_from_end(0)
    assert expected == actual
Example #8
0
def test_kth_not_positive_integer():
    test = LinkedList()
    test.append(0)
    test.append(1)
    test.append(2)
    test.append(3)
    expected = "ValueError:your value not found"
    actual =test.kth_from_end(-1)
    assert expected == actual
Example #9
0
def test_append_and_multiple_append():
    test = LinkedList()
    test.append(0)
    test.append(1)
    test.append(2)
    test.append(3)
    expected = "{ 0 } -> { 1 } -> { 2 } -> { 3 } -> { Null } -> "
    actual = test.__str__()
    assert expected == actual
Example #10
0
def test_kth_with_greater_length():
    test = LinkedList()
    test.append(0)
    test.append(1)
    test.append(2)
    test.append(3)
    expected = "ValueError:your value not found"
    actual =test.kth_from_end(4)
    assert expected == actual
Example #11
0
def test_kth_with_same_length():
    test = LinkedList()
    test.append(0)
    test.append(1)
    test.append(2)
    test.append(3)
    expected = 0
    actual =test.kth_from_end(3)
    assert expected == actual
Example #12
0
def test_deleteNode():
    ll = LinkedList()
    ll.append("1")
    ll.append("3")
    ll.append("2")
    ll.deleteNode("3")
    assert ll.deleteNode("5") == "Node 5 does not exists in Linked List"
    assert ll.deleteNode("10") == "Node 10 does not exists in Linked List"
    assert ll.__str__() == "{1}->{2}->None"
Example #13
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"
Example #14
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
Example #15
0
def test_insertBefore_at_middle():
    test = LinkedList()
    test.append(0)
    test.append(1)
    test.append(2)
    test.append(3)
    test.insertBefore(2,'at_middle')
    expected = "{ 0 } -> { 1 } -> { at_middle } -> { 2 } -> { 3 } -> { Null } -> "
    actual = test.__str__()
    assert expected == actual
Example #16
0
def test_kth_from_end_size_one():
    '''
     Where the linked list is of a size 1 

    '''
    ll = LinkedList()
    ll.append(1)
    expected = 1
    actual =ll.kth_from_end(0)
    assert expected == actual
Example #17
0
def test_insert_before_middle():
    """
      to check if Can successfully insert a node before a node located in the middle of a linked list
    """
    ll = LinkedList()
    ll.append('rania')
    ll.append('Moh')
    ll.append('aml')
    ll.insert_before('Moh', 33)
    assert ll.head.next.value == 33
Example #18
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
Example #19
0
def test_insert_after_middle():
    """
      to check if Can successfully insert after a node in the middle of the linked list
    """
    ll = LinkedList()
    ll.append('rania')
    ll.append('Moh')
    ll.append('aml')
    ll.insert_after('Moh', 33)
    assert ll.head.next.next.value == 33   
Example #20
0
def test_kth_from_end_0():
    '''
    Where k and the length of the list are the same

    '''
    ll = LinkedList()
    ll.append(1)
    ll.append(3)
    ll.append(8)
    expected = "The Value Not Exist"
    actual =ll.kth_from_end(3)
    assert expected == actual
Example #21
0
def test_fidnMiddleNodeValue():
    ll = LinkedList()
    assert ll.fidnMiddleNodeValue() == "Linked list is empty"
    ll.append("1")
    assert ll.fidnMiddleNodeValue() == "1"
    ll.append("3")
    assert ll.fidnMiddleNodeValue() == "1"
    ll.append("8")
    assert ll.fidnMiddleNodeValue() == "3"
    ll.append("2")
    assert ll.fidnMiddleNodeValue() == "3"
    ll.append("5")
    assert ll.fidnMiddleNodeValue() == "8"
Example #22
0
def test_kth_from_end_6():
    '''
     Where k is greater than the length of the linked list

    '''
    ll = LinkedList()
    ll.append(1)
    ll.append(3)
    ll.append(8)
    ll.append(2)
    expected = "The Value Not Exist"
    actual =ll.kth_from_end(6)
    assert expected == actual
Example #23
0
def test_kth_from_end_negative():
    '''
     Where k is not a positive intege

    ''' 
    ll = LinkedList()
    ll.append(1)
    ll.append(3)
    ll.append(8)
    ll.append(2)
    expected = "The Value Not Exist"
    actual =ll.kth_from_end(-2)
    assert expected == actual
Example #24
0
def test_kth_from_end_2():
    '''
     Happy Path” where k is not at the end, but somewhere in the middle of the linked list

    ''' 
    ll = LinkedList()
    ll.append(1)
    ll.append(3)
    ll.append(8)
    ll.append(2)
    expected = 3
    actual =ll.kth_from_end(2)
    assert expected == actual
Example #25
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 #26
0
def test_five():
    drinks = LinkedList()
    drinks.append('Coffee')
    drinks.append('Ice_Tea')
    drinks.append('Lemonade')
    drinks.append('Mocha')
    drinks.insertBefore('Mocha', 'milkcheck')
    expected = 'Coffee -> Ice_Tea -> Lemonade -> milkcheck -> Mocha -> None'
    actual = drinks.__str__()
    assert expected == actual
Example #27
0
def test_zip_lists():
    ll1 = LinkedList()
    ll1.append(3)
    ll1.append(2)
    ll1.append(1)
    ll2 = LinkedList()
    ll2.append(3)
    ll2.append(2)
    ll2.append(1)
    assert zip_lists(ll1, ll2).__str__(
    ) == "{ 3 } -> { 3 } -> { 2 } -> { 2 } -> { 1 } -> { 1 } -> NULL"
Example #28
0
def test_append1():
    ll = LinkedList()
    assert ll.__str__() == "None"
    ll.append("1")
    assert ll.__str__() == "{1}->None"
    ll.append("3")
    assert ll.__str__() == "{1}->{3}->None"
    ll.append("2")
    assert ll.__str__() == "{1}->{3}->{2}->None"
    ll.append("5")
    assert ll.__str__() == "{1}->{3}->{2}->{5}->None"
Example #29
0
def test_mergeLinkedListOne():
    ll1 = LinkedList()
    ll1.append("10")
    ll1.append("20")
    ll1.append("30")
    ll2 = LinkedList()
    ll2.append("5")
    ll2.append("15")
    ll2.append("25")
    ll = LinkedList()
    ll.head = mergeLists(ll1.head, ll2.head)
    assert ll.__str__() == "{10}->{5}->{20}->{15}->{30}->{25}->None"
Example #30
0
def test_mergeLinkedListTwo():
    ll1 = LinkedList()
    ll1.append("1")
    ll1.append("3")
    ll1.append("2")
    ll2 = LinkedList()
    ll2.append("5")
    ll2.append("9")
    ll2.append("4")
    ll = LinkedList()
    ll.head = mergeLists(ll1.head, ll2.head)
    assert ll.__str__() == "{1}->{5}->{3}->{9}->{2}->{4}->None"