def test_remove_node_inexisting(): ll = LinkedList() ll.add_node(3) ll.add_node('hello') ll.add_node(5) # list: 3 'hello' 5 nodes_before = count_nodes(ll) ll.remove_node(4) nodes_after = count_nodes(ll) assert nodes_before == nodes_after
def test_remove_node_duplicate(): ll = LinkedList() ll.add_node(3) ll.add_node('hello') ll.add_node(5) ll.add_node(5) # list: 3 'hello' 5 5 nodes_before = count_nodes(ll) ll.remove_node(5) nodes_after = count_nodes(ll) assert nodes_after == nodes_before - 1
def test_remove_node_first(): ll = LinkedList() ll.add_node(3) ll.add_node('hello') ll.add_node(5) # list: 3 'hello' 5 nodes_before = count_nodes(ll) ll.remove_node(3) nodes_after = count_nodes(ll) assert nodes_after == nodes_before - 1 p = ll.base.next_node assert p.value == 'hello' p = p.next_node assert p.value == 5 assert p.next_node is None
def test_remove_node_last(): ll = LinkedList() ll.add_node(3) ll.add_node('hello') ll.add_node(4) ll.add_node(5) ll.add_node(6) # list: 3 'hello' 4 5 6 nodes_before = count_nodes(ll) ll.remove_node(6) nodes_after = count_nodes(ll) assert nodes_after == nodes_before - 1 last = ll.base while last.next_node is not None: last = last.next_node assert last.value == 5