Esempio n. 1
0
def test_remove_duplicate_values_length1():
    my_linked_list = LinkedList()
    my_linked_list.append_node(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
Esempio n. 2
0
def test_remove_duplicate_values_multiple():
    my_linked_list = LinkedList()
    input_values = [0, 0, 1, 1, 2, 2, 3, 0, 1, 2, 3, 4, 5, 6, 5, 7, 8, 9, 1, 0, 0, 0]
    my_linked_list.append_nodes(input_values)
    my_linked_list.remove_duplicate_values()
    expected_output_values = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    actual_output_values = linked_list_values_to_array(my_linked_list)
    assert expected_output_values == actual_output_values
Esempio n. 3
0
def main():
    sets_of_duplicates = 4
    max_value = 10000
    big_array = initialize_array_with_duplicates(max_value, sets_of_duplicates)

    linked_list_0_non_opt = LinkedList()
    ta = datetime.now()
    linked_list_0_non_opt.append_nodes(big_array)
    tb = datetime.now()
    append_time = tb - ta
    print("Time to prepare list non-optimized:", append_time)
    print("List size:", linked_list_0_non_opt.get_node_count())

    linked_list_1 = LinkedList()
    t0 = datetime.now()
    linked_list_1.append_nodes_optimized(big_array)
    t1 = datetime.now()
    append_time = t1 - t0
    print("Time to prepare list optimized:", append_time)
    print("List size:", linked_list_1.get_node_count())

    t2 = datetime.now()
    linked_list_1.remove_duplicate_values()
    t3 = datetime.now()
    dedup_time_list = t3 - t2
    print("Time to de-dup using built-in list as additional data structure:", dedup_time_list)
    print("Size of de-duped list:", linked_list_1.get_node_count())

    linked_list_2 = LinkedList()
    t4 = datetime.now()
    linked_list_2.append_nodes_optimized(big_array)
    t5 = datetime.now()
    append_time = t5 - t4
    print("Time to prepare list optimized:", append_time)
    print("List size:", linked_list_2.get_node_count())

    t6 = datetime.now()
    linked_list_2.remove_duplicate_values_use_hashtable()
    t7 = datetime.now()
    dedup_time_dict = t7 - t6
    print("Time to de-dup using dictionary as additional data structure:", dedup_time_dict)
    print("Size of de-duped list:", linked_list_2.get_node_count())
Esempio n. 4
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