def test_multiple_insert(): new_link.insert(Node('a')) new_link.insert(Node('b')) new_link.insert(Node('c')) actual = str(new_link) expected = "{'c'} -> {'b'} -> {'a'} -> Null" assert actual == expected
def test_append_for_three_values(): new_list = LinkedList() new_list.append(Node(3)) new_list.append(Node(1)) new_list.append(Node(5)) assert new_list.first_node.value == 3 assert new_list.first_node.next_node.value == 1 assert new_list.first_node.next_node.next_node.value == 5
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_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_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_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_llist_init_str_repr(llist): first_node = Node(1) second_node = Node('a') assert str(llist) == 'None' assert repr(llist) == 'LinkedList()' llist._head = first_node first_node.next = second_node llist._tail = second_node assert str(llist) == '1 -> a -> None' assert repr(llist) == 'LinkedList(1, a)' llist = LinkedList([2, 'b']) assert str(llist) == '2 -> b -> None' assert repr(llist) == 'LinkedList(2, b)'
def test_k_is_not_postive_integer(): 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 actual = linked_list.kth(-3) expected = "Input k is not a positive integer" assert actual == expected
def test_k_same_length_as_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 actual = linked_list.kth(4) expected = None assert actual == expected
def test_kth_greater_than_the_length_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 actual = linked_list.kth(10) expected = "Input is greater than the length of the linked list" assert actual == expected
def test_node_instance_value(): # !!! previously written in the syntax of # `assert lackey.value` received linter error in spite of test passing.??? lackey = Node('meat-head') actual = lackey.value expected = 'meat-head' assert actual == expected
def test_neg(): node = Node(0) link = LinkedList(node) link.kthFromEnd(10) actual = 'negative number given' expected = 'negative number given' assert actual == expected
def test_same_kth(): node = Node(0) link = LinkedList(node) link.kthFromEnd(10) actual = 4 expected = 4 assert actual == expected
def test_includes(): 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.includes(1) assert linked_list.includes(2) assert linked_list.includes(3) assert linked_list.includes(4) assert linked_list.includes(5) == False assert linked_list.includes(6) == False
def test_length(): node = Node(0) link = LinkedList(node) link.kthFromEnd(10) actual = 'number is greater than the length of list.' expected = 'number is greater than the length of list.' assert actual == expected
def test_linked_list_size_1(): node1 = Node(5) linked_list = LinkedList() linked_list.head = node1 actual = linked_list.kth(0) expected = 5 assert actual == expected
def test_append(): node = Node(0) link = LinkedList(node) link.insert(4) link.append(10) actual = str(link) expected = f'{{ 4 }} -> {{ 0 }} -> {{ 10 }} -> NONE' assert actual == expected
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_nth(): node = Node(0) link = LinkedList(node) link.insert(4) link.append(10) link.kthFromEnd(1) actual = 0 expected = 0 assert actual == expected
def test_before_first(): node = Node(0) link = LinkedList(node) link.insert_node(4) link.append(10) link.insert_node(5) actual = str(link) expected = f'{{ 5 }} -> {{ 4 }} -> {{ 0 }} -> {{ 10 }} -> NULL' assert actual == expected
def generate_new_list(): node = Node(0) new_list = LinkedList(node) list_length = 0 for value in range(1, 5): new_list.insert(value) list_length += 1 return new_list
def test_insert_multiple_nodes(): node1 = Node(1) linked_list = LinkedList() linked_list.head = node1 linked_list.insert(4) assert linked_list.head.value == 4 linked_list.insert(6) assert linked_list.head.value == 6 linked_list.insert(9) assert linked_list.head.value == 9
def test_after_last(): node = Node(0) link = LinkedList(node) link.insert_node(4) link.append(10) link.insert_after(10, 5) actual = str(link) expected = f'{{ 4 }} -> {{ 0 }} -> {{ 10 }} -> {{ 5 }} -> NULL' assert actual == expected # Code challenge 05 stuff # link = LinkedList() # def test_empty_list(): # actual = link.insert_node(None) # value = None # assert actual == value # def test_insert_list(): # actual = link.insert_node(4) # value = None # assert actual.value == value # def test_head_link(): # actual = str(link) # value = '{4} -> {None} -> Null' # assert actual == value # new_link = LinkedList() # def test_multiple_insert(): # new_link.insert_node(3) # new_link.insert_node(6) # new_link.insert_node(10) # actual = str(new_link) # value = '{10} -> {6} -> {3} -> Null' # assert actual == value # def test_find_value(): # actual = new_link.search_node(3) # value = True # assert actual == value # def test_false_search(): # actual = new_link.search_node(99) # value = False # assert actual == value # def test_collection_of_all(): # actual = str(new_link) # value = '{10} -> {6} -> {3} -> Null' # assert actual == value
def test_linked_list_02(): ll = LinkedList() ll.append(10) assert ll.head is not None assert ll.head.el == 10 assert ll.head.next is None assert ll == LinkedList([10]) ll.append(11) assert ll.head.next == Node(11) assert ll.head.next.el == 11 assert ll.end.el == 11
def test_import(): node = Node('apples, none') actual = node.value expected = 'apples' assert actual == expected assert node.next == None # assert LinkedList # def test_two_nodes(): # node2 = Node('orange', None) # node1 = Node('apples', node2) # actual = node1.next.value # expected = 'orange' # assert actual == expected # def test_empty_11(): # 11 = LinkedList() # assert 11
def test_node_next_value(): car= Node("Ferrari") assert car.next == None
def test_error_missing_arguments_nodes(): with pytest.raises(TypeError): Node()
def test_node_value(): car= Node("Ferrari") assert car.value == "Ferrari"
def test_error_node(): with pytest.raises(TypeError): Node("?", "?", "?")