Ejemplo n.º 1
0
 def test_zero(self):
     #Тест проверяет связанный список с нулем элементов
     number = 1
     list_for_first_test = List_maker(number)
     self.Linked_List_for_zero_test = LL_mod.LinkedList()
     for i in range(0, len(list_for_first_test)):
         self.Linked_List_for_zero_test.add_in_tail(
             LL_mod.Node(list_for_first_test[i]))
     node_1 = self.Linked_List_for_zero_test.head
     for i in range(0, self.Linked_List_for_zero_test.len()):
         print(node_1.value)
         self.assertEqual(list_for_first_test[i], node_1.value)
         node_1 = node_1.next
Ejemplo n.º 2
0
 def test_one(self):
     #Тест для связанного списка из 1 эл-та
     number = 2
     index_for_delete = random.randint(0, number)
     value_for_insert = random_generation_number()
     position_for_insert = 1
     list_for_second_test = List_maker(number)
     self.Linked_List_for_second_test = LL_mod.LinkedList()
     #Добавление эл-та в конец
     for i in range(0, len(list_for_second_test)):
         self.Linked_List_for_second_test.add_in_tail(
             LL_mod.Node(list_for_second_test[i]))
     node_2 = self.Linked_List_for_second_test.head
     for i in range(0, self.Linked_List_for_second_test.len()):
         print(node_2.value)
         self.assertEqual(list_for_second_test[i], node_2.value)
         node_2 = node_2.next
     print(list_for_second_test)
     #Вставка элемента
     list_for_second_test.insert(position_for_insert, value_for_insert)
     self.Linked_List_for_second_test.insert(position_for_insert,
                                             value_for_insert)
     node_2 = self.Linked_List_for_second_test.head
     for i in range(0, self.Linked_List_for_second_test.len()):
         print(node_2.value)
         self.assertEqual(list_for_second_test[i], node_2.value)
         node_2 = node_2.next
     print(list_for_second_test)
     #Поиск элемента который вставили
     find_node = self.Linked_List_for_second_test.find(value_for_insert)
     self.assertEqual(find_node.value, value_for_insert)
     #Поиск элемента по значению
     index_for_find = random.randint(0, number)
     value_for_find = list_for_second_test[index_for_find]
     find_element = self.Linked_List_for_second_test.find(value_for_find)
     self.assertEqual(value_for_find, find_element.value)
     #Удаление элемента
     value_for_delete = list_for_second_test[index_for_delete]
     list_for_second_test.remove(value_for_delete)
     print(list_for_second_test)
     self.Linked_List_for_second_test.delete(value_for_delete)
     self.Linked_List_for_second_test.print_all_nodes()
     node_2 = self.Linked_List_for_second_test.head
     print(self.Linked_List_for_second_test.len())
     for i in range(0, self.Linked_List_for_second_test.len()):
         self.assertEqual(list_for_second_test[i], node_2.value)
         node_2 = node_2.next
Ejemplo n.º 3
0
 def test_insert_in_empty_list(self):
     # Проверка ф-ции insert при пустом списке
     LL_1 = LL_mod.LinkedList()
     i = random_number()
     Node = Node_create(i)
     if LL_1.len() == 0:
         LL_1.insert(None, Node)
     Node_LL_1 = LL_1.head
     self.assertEqual(LL_1.head.value, i)
     for j in range(0, LL_1.len()):
         self.assertEqual(Node_LL_1.value, i)
Ejemplo n.º 4
0
 def test_insert_with_one_element(self):
     #Проверка ф-ции insert для списка с 1 элементом. Вставка э-та после первого
     #э-та, далее вставка после предварительно вставленного эл-та.
     LL_1 = LL_mod.LinkedList()
     Q_ty = 3
     data = []
     for i in range(0, Q_ty):
         j = random_number()
         data.append(j)
     LL_1.add_in_tail(Node_create(data[0]))
     LL_1.insert(Node_create(data[0]), Node_create(data[1]))
     LL_1.insert(Node_create(data[1]), Node_create(data[2]))
     Node_LL_1 = LL_1.head
     for i in range(0, LL_1.len()):
         self.assertEqual(Node_LL_1.value, data[i])
         Node_LL_1 = Node_LL_1.next
Ejemplo n.º 5
0
 def test_insert_in_last_position(self):
     #Вставка в конец списка
     LL_1 = LL_mod.LinkedList()
     data = []
     for i in range(0, 10):
         data.append(random_number())
     for i in range(0, 10):
         RN = random_number()
         if i == 9:
             LL_1.insert(Node_create(data[i]), Node_create(RN))
             data.append(i)
         else:
             LL_1.add_in_tail(Node_create(data[i]))
     Node_LL_1 = LL_1.head
     for i in range(0, LL_1.len()):
         self.assertEqual(Node_LL_1.value, data[i])
         Node_LL_1 = Node_LL_1.next
Ejemplo n.º 6
0
 def test_insert_in_random_position(self):
     #Вставка в случайную позицию, случайного значения
     LL_1 = LL_mod.LinkedList()
     data = []
     random_len = random.randint(5, 10)
     random_number = random.randint(1, random_len - 1)
     insert_value = random.randint(1, 99)
     for i in range(0, random_len):
         data.append(random.randint(100, 10**8))
     for j in range(0, len(data)):
         Node = Node_create(data[j])
         if j == random_number:
             after_Node = Node
         LL_1.add_in_tail(Node)
     data.insert(random_number + 1, insert_value)
     new_Node = Node_create(insert_value)
     LL_1.insert(after_Node, new_Node)
     Node_LL_1 = LL_1.head
     for i in range(0, len(data)):
         self.assertEqual(Node_LL_1.value, data[i])
         Node_LL_1 = Node_LL_1.next
Ejemplo n.º 7
0
 def test_big_LL(self):
     #Тест для большого кол-ва элементов
     number = random.randint(10, 30)
     index_for_delete = random.randint(0, number)
     value_for_insert = random_generation_number()
     position_for_insert = random.randint(0, number)
     list_for_third_test = List_maker(number)
     self.Linked_List_for_third_test = LL_mod.LinkedList()
     #Добавление эл-та в конец
     for i in range(0, len(list_for_third_test)):
         self.Linked_List_for_third_test.add_in_tail(
             LL_mod.Node(list_for_third_test[i]))
     node_3 = self.Linked_List_for_third_test.head
     for i in range(0, self.Linked_List_for_third_test.len()):
         print(node_3.value)
         self.assertEqual(list_for_third_test[i], node_3.value)
         node_3 = node_3.next
     #Вставка элемента
     list_for_third_test.insert(position_for_insert, value_for_insert)
     self.Linked_List_for_third_test.insert(position_for_insert,
                                            value_for_insert)
     node_3 = self.Linked_List_for_third_test.head
     for i in range(0, self.Linked_List_for_third_test.len()):
         print(node_3.value)
         self.assertEqual(list_for_third_test[i], node_3.value)
         node_3 = node_3.next
     print(list_for_third_test)
     #Поиск элемента который вставили
     find_node = self.Linked_List_for_third_test.find(value_for_insert)
     print(find_node.value, value_for_insert)
     self.assertEqual(find_node.value, value_for_insert)
     #Поиск элемента по значению
     index_for_find = random.randint(0, number)
     value_for_find = list_for_third_test[index_for_find]
     find_element = self.Linked_List_for_third_test.find(value_for_find)
     self.assertEqual(value_for_find, find_element.value)
     #Удаление элемента
     value_for_delete = list_for_third_test[index_for_delete]
     list_for_third_test.remove(value_for_delete)
     print(list_for_third_test)
     self.Linked_List_for_third_test.delete(value_for_delete)
     self.Linked_List_for_third_test.print_all_nodes()
     node_3 = self.Linked_List_for_third_test.head
     print(self.Linked_List_for_third_test.len())
     for i in range(0, self.Linked_List_for_third_test.len()):
         self.assertEqual(list_for_third_test[i], node_3.value)
         node_3 = node_3.next
     #Сложение двух списков
     self.Linked_List_for_third_1_test = LL_mod.LinkedList()
     self.Linked_List_for_third_2_test = LL_mod.LinkedList()
     list_for_third_1_test = List_maker(number)
     list_for_third_2_test = List_maker(number)
     sum_list = []
     for i in range(0, len(list_for_third_1_test)):
         sum_list.append(list_for_third_1_test[i] +
                         list_for_third_2_test[i])
     for i in range(0, len(list_for_third_1_test)):
         self.Linked_List_for_third_1_test.add_in_tail(
             LL_mod.Node(list_for_third_1_test[i]))
     for i in range(0, len(list_for_third_2_test)):
         self.Linked_List_for_third_2_test.add_in_tail(
             LL_mod.Node(list_for_third_2_test[i]))
     Sum_LL = LL_mod.add_linked_lists(self.Linked_List_for_third_1_test,
                                      self.Linked_List_for_third_2_test)
     Sum_Node = Sum_LL.head
     for i in range(0, Sum_LL.len()):
         self.assertEqual(Sum_Node.value, sum_list[i])
         Sum_Node = Sum_Node.next
Ejemplo n.º 8
0
def data_for_tests_one(self, randomnumber):
    one = LL_mod.Node(randomnumber)
    s_list = LL_mod.LinkedList()
    s_list.add_in_tail(one)
    return s_list
Ejemplo n.º 9
0
def Node_create(i):
    Node = LL_mod.Node(i)
    return Node