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
def test_remove_duplicate_values_with_hash_table_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_use_hashtable() 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
def test_remove_all_nodes_with_value_not_in_list(): my_linked_list = LinkedList() input_values = [1, 2, 3, 4, 5, 6, 7, 8, 9] my_linked_list.append_nodes(input_values) my_linked_list.remove_all_nodes_with_value(0) expected_output_values = [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
def test_remove_all_nodes_with_value_multiple_at_start_and_end(): my_linked_list = LinkedList() input_values = [0, 0, 0, 0, 0, 1, 0, 2, 3, 0, 4, 5, 6, 0, 7, 8, 9, 0, 0, 0] expected_output_values = [1, 2, 3, 4, 5, 6, 7, 8, 9] my_linked_list.append_nodes(input_values) my_linked_list.remove_all_nodes_with_value(0) actual_output_values = linked_list_values_to_array(my_linked_list) assert expected_output_values == actual_output_values
def test_compare_lists_multiple(): linked_list_1 = LinkedList() linked_list_1.append_nodes([0, 1, 2, 3, 4, 5, 6]) linked_list_2 = LinkedList() linked_list_2.append_nodes([0, 1, 2, 3, 4, 5, 6]) assert linked_list_1.compare_to(linked_list_2) linked_list_2.set_value_at_position(10, 0) assert not linked_list_1.compare_to(linked_list_2) linked_list_2.remove_head_node() assert not linked_list_1.compare_to(linked_list_2)
def test_remove_all_nodes_with_value_length2(): my_linked_list = LinkedList() my_linked_list.append_nodes([0, 1]) 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 my_linked_list.append_node(1) my_linked_list.remove_all_nodes_with_value(0) assert my_linked_list.get_node_count() == 1 assert my_linked_list.get_head_node().value == 1 assert my_linked_list.get_value_at_position(2) is None
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
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())
def test_get_value_at_position(): my_linked_list = LinkedList() input_values = [0, 1, 2, 3, 4, 5] my_linked_list.append_nodes(input_values) output_values = linked_list_values_to_array(my_linked_list) assert input_values == output_values