Exemplo n.º 1
0
def test_single_node():
    my_linked_list = LinkedList()
    my_linked_list.append_node(0)
    assert my_linked_list.get_node_count() == 1
    assert my_linked_list.get_head_node().value == 0
    assert my_linked_list.get_value_at_position(0) == 0
    assert my_linked_list.get_value_at_position(1) is None
    assert my_linked_list.get_value_at_position(1) is None
Exemplo n.º 2
0
def test_remove_all_nodes_with_value_length1():
    my_linked_list = LinkedList()
    my_linked_list.append_node(0)
    my_linked_list.remove_all_nodes_with_value(1)
    assert my_linked_list.get_node_count() == 1
    assert my_linked_list.get_head_node().value == 0
    assert my_linked_list.get_value_at_position(0) == 0
    my_linked_list.remove_all_nodes_with_value(0)
    assert my_linked_list.get_node_count() == 0
    assert my_linked_list.get_head_node() is None
    assert my_linked_list.get_value_at_position(0) is None
Exemplo n.º 3
0
def test_remove_duplicate_values_length2():
    my_linked_list = LinkedList()
    my_linked_list.append_nodes([0, 0])
    my_linked_list.remove_duplicate_values()
    assert my_linked_list.get_node_count() == 1
    assert my_linked_list.get_head_node().value == 0
    assert my_linked_list.get_value_at_position(0) == 0
    my_linked_list.append_node(1)
    my_linked_list.remove_duplicate_values()
    assert my_linked_list.get_node_count() == 2
    assert my_linked_list.get_value_at_position(0) == 0
    assert my_linked_list.get_value_at_position(1) == 1
Exemplo n.º 4
0
def test_remove_all_nodes_with_value_empty():
    my_linked_list = LinkedList()
    my_linked_list.remove_all_nodes_with_value(0)
    assert my_linked_list.get_node_count() == 0
    assert my_linked_list.get_head_node() is None
    assert my_linked_list.get_value_at_position(0) is None
    assert my_linked_list.get_value_at_position(1) is None
Exemplo n.º 5
0
def test_remove_head_node_length3():
    my_linked_list = LinkedList()
    my_linked_list.append_nodes([0, 1, 2])
    my_linked_list.remove_head_node()
    assert my_linked_list.get_node_count() == 2
    assert my_linked_list.get_head_node().value == 1 
    assert my_linked_list.get_value_at_position(1) == 2   
Exemplo n.º 6
0
def test_empty_list():
    my_linked_list = LinkedList()
    assert my_linked_list.get_node_count() == 0
    assert my_linked_list.get_head_node() is None
    assert my_linked_list.get_value_at_position(0) is None
    assert my_linked_list.get_value_at_position(1) is None
Exemplo n.º 7
0
def test_remove_duplicate_values_empty():
    my_linked_list = LinkedList()
    my_linked_list.remove_duplicate_values()
    assert my_linked_list.get_node_count() == 0
    assert my_linked_list.get_head_node() is None
    assert my_linked_list.get_value_at_position(0) is None