def test_str(): # 8 ll = LinkedList() ll.append(True) ll.append('a') ll.append(0) ll.insert(74) ll.__str__() assert ll.__str__() == "{ 74 } -> { True } -> { a } -> { 0 } -> Null"
def test_collection(): ll = LinkedList() ll.insert(2) ll.insert(3) ll.insert(4) ll.insert(5) assert ll.__str__() == '{5} -> {4} -> {3} -> {2} -> None'
def test_multiple_insertion_at_end(): ll = LinkedList() ll.append(1) ll.append(2) ll.append(3) ll.append('banana') assert ll.__str__() == '{1} -> {2} -> {3} -> {banana} -> None'
def test_return_collection(): collection = LinkedList() collection.insert("c") collection.insert("b") collection.insert("a") expected = "{ a } -> { b } -> { c } -> NULL" assert expected == collection.__str__()
def test_insert_after_last_node(): new_instance = LinkedList() new_instance.insert('test-two') new_instance.insert('test-one') new_instance.insertAfter('test-two','new-test') actual = new_instance.__str__() expected = 'test-one -> test-two -> new-test -> ' assert actual == expected
def test_insert_before_first_node(): new_instance = LinkedList() new_instance.insert('test-two') new_instance.insert('test-one') new_instance.insertBefore('test-one','new-test') actual = new_instance.__str__() expected = 'new-test -> test-one -> test-two -> ' assert actual == expected
def test_insert_before_middle_index(): ll = LinkedList() ll.insert(1) ll.insert(2) ll.insert(4) ll.insert(5) ll.insert_before(3, 2) assert ll.__str__() == '{1} -> {2} -> {3} -> {4} -> {5} -> None'
def test_insert_after_end(): # insert a node after the last node of the linked list lst_four = LinkedList() lst_four.insert('apple') lst_four.append('banana') lst_four.insertAfter('banana', 'strobary') assert lst_four.head.next.next.value == 'strobary' assert '{apple}-> {banana}-> {strobary}-> ' == lst_four.__str__()
def test_str_of_llist_class(): finding_francis = LinkedList('goons') finding_francis.insert('meat-head') finding_francis.insert('brown-pants') finding_francis.insert('car-goon') actual = finding_francis.__str__() expected = '{ car-goon } -> { brown-pants } -> { meat-head } -> { goons } -> None ' assert actual == expected
def test_next_of_origin_node(): """tests next of the original head Node upon list instantiation """ finding_francis = LinkedList('goons') finding_francis.insert('meat-head') finding_francis.insert('brown-pants') actual = finding_francis.__str__() expected = '{ brown-pants } -> { meat-head } -> { goons } -> None ' assert actual == expected
def test_insert_after_middle(): # insert after a node in the middle of the linked list lst_four = LinkedList() lst_four.insert('apple') lst_four.append('banana') lst_four.insertAfter('banana', 'strobary') lst_four.insertAfter('strobary', 'watermelon') assert lst_four.head.next.next.next.value == 'watermelon' assert lst_four.head.next.next.value == 'strobary' assert '{apple}-> {banana}-> {strobary}-> {watermelon}-> ' == lst_four.__str__()
def test_insert_before_first(): finding_francis = LinkedList('goons') finding_francis.append('brown-pants') finding_francis.append('car-goon') finding_francis.insert_before('goons', 'meat-head') actual = finding_francis.__str__() expected = '{ meat-head } -> { goons } -> { brown-pants } -> { car-goon } -> None ' assert actual == expected
def test_append_multiple(): finding_francis = LinkedList('goons') finding_francis.append('meat-head') finding_francis.append('brown-pants') finding_francis.append('car-goon') actual = finding_francis.__str__() expected = '{ goons } -> { meat-head } -> { brown-pants } -> { car-goon } -> None ' assert actual == expected
def test_to_string_method(): lst_three = LinkedList() lst_three.insert(1) lst_three.append(2) lst_three.append(3) lst_three.append(4) lst_three.append(5) actual = lst_three.__str__() expected = '{1}-> {2}-> {3}-> {4}-> {5}-> ' assert actual == expected
def test_values_exist_in_the_linked_list(): node1 = Node(1) node2 = Node(2) node3 = Node(3) node4 = Node(4) linked_list = LinkedList() linked_list.head = node1 node1.next = node2 node2.next = node3 node3.next = node4 assert linked_list.__str__() == "1 -> 2 -> 3 -> 4 -> None"
def test_add__node_to_the_end_of_the_linked_list(): node1 = Node(1) node2 = Node(2) node3 = Node(3) node4 = Node(4) linked_list = LinkedList() linked_list.head = node1 node1.next = node2 node2.next = node3 node3.next = node4 linked_list.append(5) assert linked_list.__str__() == "1 -> 2 -> 3 -> 4 -> 5 -> None"
def test_insert_node_before_node_located_in_the_middle_of_linked_list(): node1 = Node(1) node2 = Node(2) node3 = Node(3) node4 = Node(4) linked_list = LinkedList() linked_list.head = node1 node1.next = node2 node2.next = node3 node3.next = node4 linked_list.insert_before(3, 5) assert linked_list.__str__() == "1 -> 2 -> 5 -> 3 -> 4 -> None"
def test_insert_node_after_the_last_node(): node1 = Node(1) node2 = Node(2) node3 = Node(3) node4 = Node(4) linked_list = LinkedList() linked_list.head = node1 node1.next = node2 node2.next = node3 node3.next = node4 linked_list.insert_after(4, 5) assert linked_list.__str__() == "1 -> 2 -> 3 -> 4 -> 5 -> None"
def test_insert_node_before_the_first_node(): node1 = Node(1) node2 = Node(2) node3 = Node(3) node4 = Node(4) linked_list = LinkedList() linked_list.head = node1 node1.next = node2 node2.next = node3 node3.next = node4 linked_list.insert_before(1, 5) assert linked_list.__str__() == "5 -> 1 -> 2 -> 3 -> 4 -> None"
def test_zip_lists_second_one_longer(): node1 = Node(1) node2 = Node(2) node3 = Node(3) node4 = Node(4) node1.next = node2 node2.next = node3 node3.next = node4 linked_list1 = LinkedList() linked_list1.head = node3 linked_list2 = LinkedList() linked_list2.head = node1 linked_list3 = LinkedList() linked_list3 = linked_list3.zip_lists(linked_list1, linked_list2) assert linked_list3.__str__() == "3 -> 1 -> 4 -> 2 -> 3 -> 4 -> None"
def test_insertion_at_end(): ll = LinkedList() ll.append(1) ll.append(2) ll.append(3) assert ll.__str__() == '{1} -> {2} -> {3} -> None'
def test_ten(): new_list = LinkedList(Node(1, Node(3, Node(2)))) new_list.insert_after(3, 5) actual = new_list.__str__() expected = "{1} ->{3} ->{5} ->{2} -> None " assert actual == expected
def test_dender_str(): ll = LinkedList() ll.append(5) ll.append(4) assert ll.__str__() == '<5>,<4>,'
def test_empty_linked_list_str(): empty_list = LinkedList() assert 'None' == empty_list.__str__()
def test_eight(): new_list = LinkedList(Node(1, Node(3, Node(2)))) new_list.append_to_end(5) actual = new_list.__str__() expected = "{1} ->{3} ->{2} ->{5} -> None " assert actual == expected