Ejemplo n.º 1
0
    def test_linked_list2_insert(self):
        temp_list = [12, 23, 34, 45, 56, 67, 78, 89]
        test_llist2 = ll.LinkedList2()
        for i in temp_list:
            test_llist2.add_in_tail(ll.Node(i))
        # test_llist2.print_all_nodes_both_row()

        # insert into end:
        item_insert = 10
        test_llist2.insert(None, ll.Node(item_insert))
        temp_list.append(item_insert)
        # test_llist2.print_all_nodes_both_row()
        self.common_tests(temp_list, test_llist2)
        self.assertEqual(temp_list[-1], test_llist2.tail.value)

        # insert into middle:
        item_insert = 39
        test_llist2.insert(test_llist2.find(34), ll.Node(item_insert))
        temp_list.insert(3, item_insert)
        # test_llist2.print_all_nodes_both_row()
        self.common_tests(temp_list, test_llist2)

        # insert into end:
        item_insert = 99
        test_llist2.insert(test_llist2.find(10), ll.Node(item_insert))
        temp_list.append(item_insert)
        self.common_tests(temp_list, test_llist2)
        self.assertEqual(temp_list[-1], test_llist2.tail.value)

        # insert into empty linked list:
        test_llist2.clean()
        test_llist2.insert(test_llist2.find(89), ll.Node(item_insert))
        self.assertEqual(item_insert, test_llist2.head.value)
        self.assertEqual(item_insert, test_llist2.tail.value)
Ejemplo n.º 2
0
 def test_linked_list2_del_single(self):
     test_llist = ll.LinkedList2()
     test_llist.add_in_tail(ll.Node(99))
     item_del = 99
     test_llist.delete(item_del, all=False)
     self.assertEqual(None, test_llist.head)
     self.assertEqual(None, test_llist.tail)
Ejemplo n.º 3
0
    def test_linked_list2_del_all(self):
        test_llist = ll.LinkedList2()
        self.assertEqual(None, test_llist.delete(1, all=True))

        temp_list = [
            11, 11, 11, 11, 12, 23, 11, 11, 34, 45, 56, 67, 11, 78, 11, 89, 11,
            11, 11
        ]
        for i in temp_list:
            test_llist.add_in_tail(ll.Node(i))
        del_item = 11
        test_llist.delete(del_item, all=True)
        # test_llist.print_all_nodes_both_row()
        temp_list = [i for i in temp_list if i != del_item]
        self.common_tests(temp_list, test_llist)

        # delete all same node:
        test_llist.clean()
        for i in range(10):
            test_llist.add_in_tail(ll.Node(del_item))
        test_llist.delete(del_item, all=True)
        self.assertEqual(None, test_llist.head)
        self.assertEqual(None, test_llist.tail)
        self.assertEqual(0, test_llist.len())
        self.assertEqual(0, test_llist.len_reverse())
Ejemplo n.º 4
0
 def test_linked_list2_add_in_head(self):
     temp_list = [12, 23, 34, 45, 56, 67, 78, 89]
     test_llist2 = ll.LinkedList2()
     for i in temp_list:
         test_llist2.add_in_tail(ll.Node(i))
     item_head = 10
     temp_list.insert(0, item_head)
     test_llist2.add_in_head(ll.Node(item_head))
     # test_llist2.print_all_nodes_both_row()
     self.common_tests(temp_list, test_llist2)
Ejemplo n.º 5
0
 def test_linked_list2_del_last(self):
     temp_list = [12, 23, 11, 11, 34, 45, 56, 67, 11, 78, 11, 89, 11, 99]
     test_llist = ll.LinkedList2()
     for i in temp_list:
         test_llist.add_in_tail(ll.Node(i))
     del_item = 99
     test_llist.delete(del_item, all=False)
     temp_list.remove(del_item)
     self.common_tests(temp_list, test_llist)
     self.assertEqual(temp_list[-1], test_llist.tail.value)
Ejemplo n.º 6
0
 def test_linked_list2_del_first(self):
     temp_list = [
         99, 11, 11, 12, 23, 11, 11, 34, 45, 56, 67, 11, 78, 11, 89, 11, 11,
         11
     ]
     test_llist = ll.LinkedList2()
     for i in temp_list:
         test_llist.add_in_tail(ll.Node(i))
     del_item = 99
     test_llist.delete(del_item, all=False)
     temp_list.remove(del_item)
     self.common_tests(temp_list, test_llist)
Ejemplo n.º 7
0
    def test_linked_list2_del_one(self):
        test_llist = ll.LinkedList2()
        self.assertEqual(None, test_llist.delete(1, all=False))

        temp_list = [
            11, 11, 11, 11, 12, 23, 11, 11, 34, 45, 56, 67, 11, 78, 11, 89, 11,
            11, 11
        ]
        for i in temp_list:
            test_llist.add_in_tail(ll.Node(i))
        del_item = 11
        test_llist.delete(del_item, all=False)
        temp_list.remove(del_item)
        # test_llist.print_all_nodes_both_row()
        self.common_tests(temp_list, test_llist)