def test_insert_with_None(self):
        s_list = LinkedList2()
        s_list.add_in_tail(Node(1))
        s_list.add_in_tail(Node(2))
        s_list.add_in_tail(Node(4))
        s_list.add_in_tail(Node(5))

        #with non empty list
        s_list.insert(None, Node(99))
        self.assertEqual(s_list.find(99).value, 99)
        self.assertEqual(s_list.find(99).next, None)
        self.assertEqual(s_list.find(99).prev.value, 5)
        self.assertEqual(s_list.head.value, 1)
        self.assertEqual(s_list.tail.value, 99)
        self.assertEqual(s_list.head.prev, None)
        self.assertEqual(s_list.head.next.value, 2)
        self.assertEqual(s_list.tail.prev.value, 5)
        self.assertEqual(s_list.tail.next, None)
        s_list.len()
        self.assertEqual(s_list.len(), 5)

        #with empty list
        s_list = LinkedList2()
        s_list.insert(None, Node(205))
        self.assertEqual(s_list.find(205).value, 205)
        self.assertEqual(s_list.head.value, 205)
        self.assertEqual(s_list.tail.value, 205)
        self.assertEqual(s_list.head.prev, None)
        self.assertEqual(s_list.head.next, None)
        s_list.len()
        self.assertEqual(s_list.len(), 1)
    def test_add_and_insert_in_tail_for_empty_list(self):
        #add in tail
        s_list = LinkedList2()
        s_list.add_in_tail(Node(11))
        #check head and tail
        self.assertEqual(s_list.head.value, 11)
        self.assertEqual(s_list.tail.value, 11)
        self.assertEqual(s_list.head.prev, None)
        self.assertEqual(s_list.tail.next, None)
        s_list.len()
        self.assertEqual(s_list.len(), 1)

        #insert in list
        s_list = LinkedList2()
        s_list.insert(None, Node(11))
        #check head and tail
        self.assertEqual(s_list.head.value, 11)
        self.assertEqual(s_list.tail.value, 11)
        self.assertEqual(s_list.head.prev, None)
        self.assertEqual(s_list.tail.next, None)
        self.assertEqual(s_list.len(), 1)

        #add in head
        s_list = LinkedList2()
        s_list.add_in_head(Node(11))
        #check head and tail
        self.assertEqual(s_list.head.value, 11)
        self.assertEqual(s_list.tail.value, 11)
        self.assertEqual(s_list.head.prev, None)
        self.assertEqual(s_list.tail.next, None)
        self.assertEqual(s_list.len(), 1)
    def test_delete_one_node(self):
        s_list = LinkedList2()
        s_list.add_in_tail(Node(1))
        s_list.add_in_tail(Node(2))
        s_list.add_in_tail(Node(4))
        s_list.add_in_tail(Node(5))

        #delete node from head
        s_list.delete(1)
        self.assertEqual(s_list.head.value, 2)
        self.assertEqual(s_list.head.prev, None)
        self.assertEqual(s_list.head.next.value, 4)
        s_list.len()
        self.assertEqual(s_list.len(), 3)

        #delete node from tail
        s_list.delete(5)
        self.assertEqual(s_list.tail.value, 4)
        self.assertEqual(s_list.tail.prev.value, 2)
        self.assertEqual(s_list.len(), 2)

        #delete node from center
        s_list = LinkedList2()
        s_list.add_in_tail(Node(1))
        s_list.add_in_tail(Node(2))
        s_list.add_in_tail(Node(4))
        s_list.add_in_tail(Node(5))
        s_list.delete(2)

        self.assertEqual(s_list.head.value, 1)
        self.assertEqual(s_list.head.next.value, 4)
        self.assertEqual(s_list.head.next.prev.value, 1)
        s_list.len()
        self.assertEqual(s_list.len(), 3)
Exemple #4
0
    def test_add_in_head(self):
        list3 = LinkedList2()
        n1 = Node(55)
        n2 = Node(12)
        n3 = Node(55)
        n4 = Node(10)
        n5 = Node(20)
        list3.add_in_tail(n1)
        list3.add_in_tail(n2)
        list3.add_in_tail(n3)

        list3.add_in_head(n4)
        self.assertEqual(list3.get_all(), [10, 55, 12, 55])
        self.assertEqual(list3.get_head().prev, None)
        self.assertEqual(list3.get_tail().next, None)
        self.assertEqual(list3.get_head(), n4)
        self.assertEqual(n4.next, n1)
        self.assertEqual(n1.prev, n4)

        list3.add_in_head(n5)
        self.assertEqual(list3.get_all(), [20, 10, 55, 12, 55])
        self.assertEqual(list3.get_head(), n5)
        self.assertEqual(n5.next, n4)
        self.assertEqual(n4.prev, n5)

        list3.add_in_head(None)
        self.assertEqual(list3.get_all(), [20, 10, 55, 12, 55])
        self.assertEqual(list3.get_head(), n5)
        self.assertEqual(n5.next, n4)
        self.assertEqual(n4.prev, n5)
Exemple #5
0
    def test_find_wrong(self):
        list2 = LinkedList2()

        self.assertEqual(list2.find(55), None)
        self.assertEqual(list2.find(None), None)
        self.assertEqual(list2.get_head(), None)
        self.assertEqual(list2.get_tail(), None)
    def test_add_in_tail(self):
        s_list = LinkedList2()

        #add in empty list
        s_list.add_in_tail(Node(4))
        self.assertEqual(s_list.find(4).value, 4)
        self.assertEqual(s_list.head.value, 4)
        self.assertEqual(s_list.tail.value, 4)
        self.assertEqual(s_list.head.prev, None)
        self.assertEqual(s_list.head.next, None)
        self.assertEqual(s_list.tail.prev, None)
        self.assertEqual(s_list.tail.next, None)

        #add in non empty list
        s_list.add_in_tail(Node(8))
        self.assertEqual(s_list.find(8).value, 8)
        self.assertEqual(s_list.head.value, 4)
        self.assertEqual(s_list.tail.value, 8)
        self.assertEqual(s_list.head.prev, None)
        self.assertEqual(s_list.head.next.value, 8)
        self.assertEqual(s_list.tail.prev.value, 4)
        self.assertEqual(s_list.tail.next, None)

        #add in non empty list
        s_list.add_in_tail(Node(11))
        self.assertEqual(s_list.find(11).value, 11)
        self.assertEqual(s_list.head.value, 4)
        self.assertEqual(s_list.tail.value, 11)
        self.assertEqual(s_list.head.prev, None)
        self.assertEqual(s_list.head.next.value, 8)
        self.assertEqual(s_list.tail.prev.value, 8)
        self.assertEqual(s_list.tail.next, None)

        self.assertEqual(s_list.find(8).prev.value, 4)
        self.assertEqual(s_list.find(8).next.value, 11)
    def test_insert(self):
        s_list = LinkedList2()
        s_list.add_in_tail(Node(1))
        s_list.add_in_tail(Node(2))
        s_list.add_in_tail(Node(4))
        s_list.add_in_tail(Node(5))

        #insert in middle of list
        s_list.insert(Node(2), Node(3))
        self.assertEqual(s_list.find(3).value, 3)
        self.assertEqual(s_list.find(3).next.value, 4)
        self.assertEqual(s_list.find(3).prev.value, 2)
        self.assertEqual(s_list.head.value, 1)
        self.assertEqual(s_list.tail.value, 5)

        #insert in tail of list
        s_list.insert(Node(5), Node(99))
        self.assertEqual(s_list.find(99).value, 99)
        self.assertEqual(s_list.find(99).next, None)
        self.assertEqual(s_list.find(99).prev.value, 5)
        self.assertEqual(s_list.find(1).prev, None)
        self.assertEqual(s_list.find(1).next.value, 2)
        self.assertEqual(s_list.head.value, 1)
        self.assertEqual(s_list.tail.value, 99)

        #insert after head of list
        s_list.insert(Node(1), Node(11))
        self.assertEqual(s_list.find(11).value, 11)
        self.assertEqual(s_list.find(11).next.value, 2)
        self.assertEqual(s_list.find(11).prev.value, 1)
        self.assertEqual(s_list.find(1).prev, None)
        self.assertEqual(s_list.find(1).next.value, 11)
        self.assertEqual(s_list.head.value, 1)
        self.assertEqual(s_list.tail.value, 99)
Exemple #8
0
    def test_delete_multi_from_1el(self):
        list1 = LinkedList2().create_list([5])

        list1.delete(5, True)
        self.assertEqual(list1.get_all(), [])
        self.assertEqual(list1.len(), 0)
        self.assertEqual(list1.get_head(), None)
        self.assertEqual(list1.get_tail(), None)
    def test_add_in_tail(self):
        s_list = LinkedList2()

        #add in empty list
        s_list.add_in_tail(Node(4))
        self.assertEqual(s_list.find(4).value, 4)
        self.assertEqual(s_list.head.value, 4)
        self.assertEqual(s_list.tail.value, 4)
        self.assertEqual(s_list.head.prev, None)
        self.assertEqual(s_list.head.next, None)
        self.assertEqual(s_list.tail.prev, None)
        self.assertEqual(s_list.tail.next, None)
        self.assertEqual(s_list.len(), 1)

        #add in non empty list
        s_list.add_in_tail(Node(8))
        self.assertEqual(s_list.find(8).value, 8)
        self.assertEqual(s_list.head.value, 4)
        self.assertEqual(s_list.tail.value, 8)
        self.assertEqual(s_list.head.prev, None)
        self.assertEqual(s_list.head.next.value, 8)
        self.assertEqual(s_list.tail.prev.value, 4)
        self.assertEqual(s_list.tail.next, None)
        self.assertEqual(s_list.len(), 2)

        #add in non empty list
        s_list.add_in_tail(Node(11))
        self.assertEqual(s_list.find(11).value, 11)
        self.assertEqual(s_list.head.value, 4)
        self.assertEqual(s_list.tail.value, 11)
        self.assertEqual(s_list.head.prev, None)
        self.assertEqual(s_list.head.next.value, 8)
        self.assertEqual(s_list.tail.prev.value, 8)
        self.assertEqual(s_list.tail.next, None)

        self.assertEqual(s_list.find(8).prev.value, 4)
        self.assertEqual(s_list.find(8).next.value, 11)
        self.assertEqual(s_list.len(), 3)

        #check len after add Node(0) in empty list
        s_list = LinkedList2()
        s_list.add_in_tail(Node(0))
        s_list.len()
        self.assertEqual(s_list.len(), 1)
        self.assertNotEqual(s_list.len(), 0)
        self.assertEqual(s_list.find(0).value, 0)
Exemple #10
0
    def test_delete_from_1el(self):
        list4 = LinkedList2()
        n1 = Node(55)
        list4.add_in_tail(n1)

        list4.delete(55)
        self.assertEqual(list4.get_all(), [])
        self.assertEqual(list4.get_head(), None)
        self.assertEqual(list4.get_tail(), None)
Exemple #11
0
    def test_create(self):
        list1 = LinkedList2().create_list([12, 10, 14, 12, 55, 10, 5])

        self.assertEqual(list1.get_all(), [12, 10, 14, 12, 55, 10, 5])
        self.assertEqual(list1.get_head(), list1.find_all(12)[0])
        self.assertEqual(list1.get_tail(), list1.find(5))
        self.assertEqual(list1.get_head().prev, None)
        self.assertEqual(list1.get_tail().prev.value, 10)
        self.assertEqual(list1.get_tail().next, None)
Exemple #12
0
    def test_delete_in_tail(self):
        list1 = LinkedList2().create_list([12, 10, 14, 12, 55, 10, 5])

        list1.delete(5)
        self.assertEqual(list1.get_all(), [12, 10, 14, 12, 55, 10])
        self.assertEqual(list1.get_head().prev, None)
        self.assertEqual(list1.get_tail().next, None)
        self.assertEqual(list1.get_tail(), list1.find_all(10)[1])
        self.assertEqual(list1.get_tail().prev.value, 55)
Exemple #13
0
    def test_delete_in_head(self):
        list1 = LinkedList2().create_list([55, 12, 43, 10, 14, 12, 55, 10, 5])

        list1.delete(55)
        self.assertEqual(list1.get_all(), [12, 43, 10, 14, 12, 55, 10, 5])
        self.assertEqual(list1.len(), 8)
        self.assertEqual(list1.get_head().prev, None)
        self.assertEqual(list1.get_tail().next, None)
        self.assertEqual(list1.get_head(), list1.find(12))
        self.assertEqual(list1.get_tail(), list1.find(5))
Exemple #14
0
    def test_delete_multi_in_tail(self):
        list1 = LinkedList2().create_list([12, 43, 14, 12, 5, 5])

        list1.delete(5, True)
        self.assertEqual(list1.get_all(), [12, 43, 14, 12])
        self.assertEqual(list1.len(), 4)
        self.assertEqual(list1.get_head().value, 12)
        self.assertEqual(list1.find_all(12)[0].value, 12)
        self.assertEqual(list1.find_all(12)[1].value, 12)
        self.assertEqual(list1.get_tail().value, 12)
        self.assertEqual(list1.get_head().prev, None)
        self.assertEqual(list1.get_tail().next, None)
    def test_insert_equal_number(self):
        s_list = LinkedList2()
        s_list.add_in_tail(Node(1))
        s_list.add_in_tail(Node(2))
        s_list.add_in_tail(Node(4))
        s_list.add_in_tail(Node(5))

        s_list.insert(Node(1), Node(1))
        self.assertNotEqual(s_list.head, s_list.head.next)

        s_list.insert(Node(5), Node(5))
        self.assertNotEqual(s_list.tail, s_list.tail.prev)
Exemple #16
0
    def test_find_all_not_empty(self):
        list2 = LinkedList2()
        n1 = Node(55)
        n2 = Node(12)
        n3 = Node(55)
        list2.add_in_tail(n1)
        list2.add_in_tail(n2)
        list2.add_in_tail(n3)

        self.assertEqual(list2.find_all(n3.value), [n1, n3])
        self.assertEqual(list2.get_head(), n1)
        self.assertEqual(list2.get_tail(), n3)
Exemple #17
0
    def test_delete_in_body(self):
        list1 = LinkedList2().create_list([12, 43, 10, 14, 12, 55, 10, 5])

        list1.delete(43)
        self.assertEqual(list1.get_all(), [12, 10, 14, 12, 55, 10, 5])
        self.assertEqual(list1.len(), 7)
        self.assertEqual(list1.get_head().prev, None)
        self.assertEqual(list1.get_tail().next, None)
        self.assertEqual(list1.get_head(), list1.find(12))
        self.assertEqual(list1.get_tail(), list1.find(5))
        self.assertEqual(list1.find(12).next.value, 10)
        self.assertEqual(list1.find(10).prev.value, 12)
Exemple #18
0
    def test_delete_multi_wrong(self):
        list1 = LinkedList2().create_list([12, 10, 14, 12, 55, 10])

        list1.delete(77, True)
        self.assertEqual(list1.get_all(), [12, 10, 14, 12, 55, 10])
        self.assertEqual(list1.get_head(), list1.find_all(12)[0])
        self.assertEqual(list1.get_tail(), list1.find_all(10)[1])

        list1.delete(None, True)
        self.assertEqual(list1.get_all(), [12, 10, 14, 12, 55, 10])
        self.assertEqual(list1.len(), 6)
        self.assertEqual(list1.get_head(), list1.find_all(12)[0])
        self.assertEqual(list1.get_tail(), list1.find_all(10)[1])
Exemple #19
0
    def test_delete_multi_in_head_and_body(self):
        list1 = LinkedList2().create_list([12, 43, 14, 12, 5, 5])

        list1.delete(12, True)
        self.assertEqual(list1.get_all(), [43, 14, 5, 5])
        self.assertEqual(list1.len(), 4)
        self.assertEqual(list1.get_head().value, 43)
        self.assertEqual(list1.get_tail().value, 5)
        self.assertEqual(list1.get_head().prev, None)
        self.assertEqual(list1.get_tail().next, None)
        self.assertEqual(list1.get_head().next.value, 14)
        self.assertEqual(list1.find(14).next.value, 5)
        self.assertEqual(list1.find(5).prev.value, 14)
Exemple #20
0
    def test_add_in_tail_1el(self):
        list3 = LinkedList2()
        n1 = Node(55)
        n2 = Node(12)
        list3.add_in_tail(n1)

        list3.add_in_tail(n2)
        self.assertEqual(list3.get_all(), [n1.value, n2.value])
        self.assertEqual(list3.get_head().prev, None)
        self.assertEqual(list3.get_tail().next, None)
        self.assertEqual(list3.get_head(), n1)
        self.assertEqual(list3.get_tail(), n2)
        self.assertEqual(n1.next, n2)
        self.assertEqual(n2.prev, n1)
Exemple #21
0
    def test_delete_multi_from_empty(self):
        list1 = LinkedList2()

        list1.delete(5, True)
        self.assertEqual(list1.get_all(), [])
        self.assertEqual(list1.len(), 0)
        self.assertEqual(list1.get_head(), None)
        self.assertEqual(list1.get_tail(), None)

        list1.delete(None, True)
        self.assertEqual(list1.get_all(), [])
        self.assertEqual(list1.len(), 0)
        self.assertEqual(list1.get_head(), None)
        self.assertEqual(list1.get_tail(), None)
    def test_delete_all_nodes(self):
        s_list = LinkedList2()
        s_list.add_in_tail(Node(5))
        s_list.add_in_tail(Node(5))
        s_list.add_in_tail(Node(5))
        s_list.add_in_tail(Node(5))

        #all nodes in list are equal
        s_list.delete(5, all=True)
        self.assertEqual(s_list.head, None)
        self.assertEqual(s_list.tail, None)
        self.assertEqual(s_list.len(), 0)

        #one node in list non equal (in head)
        s_list = LinkedList2()
        s_list.add_in_tail(Node(1))
        s_list.add_in_tail(Node(5))
        s_list.add_in_tail(Node(5))
        s_list.add_in_tail(Node(5))

        s_list.delete(5, all=True)
        self.assertEqual(s_list.head.value, 1)
        self.assertEqual(s_list.tail.value, 1)
        self.assertEqual(s_list.len(), 1)

        #one node in list non equal (in tail)
        s_list = LinkedList2()
        s_list.add_in_tail(Node(5))
        s_list.add_in_tail(Node(5))
        s_list.add_in_tail(Node(5))
        s_list.add_in_tail(Node(1))

        s_list.delete(5, all=True)
        self.assertEqual(s_list.head.value, 1)
        self.assertEqual(s_list.tail.value, 1)
        s_list.len()
        self.assertEqual(s_list.len(), 1)
Exemple #23
0
    def test_add_in_head_in_clear(self):
        list3 = LinkedList2()
        n1 = Node(55)

        list3.add_in_head(None)
        self.assertEqual(list3.get_all(), [])
        self.assertEqual(list3.get_head(), None)
        self.assertEqual(list3.get_tail(), None)

        list3.add_in_head(n1)
        self.assertEqual(list3.get_all(), [55])
        self.assertEqual(list3.get_head(), n1)
        self.assertEqual(list3.get_tail(), n1)
        self.assertEqual(n1.prev, None)
        self.assertEqual(n1.next, None)
    def test_add_in_head(self):
        s_list = LinkedList2()

        #add in empty list
        s_list.add_in_head(Node(4))
        self.assertEqual(s_list.find(4).value, 4)
        self.assertEqual(s_list.head.value, 4)
        self.assertEqual(s_list.tail.value, 4)
        self.assertEqual(s_list.head.prev, None)
        self.assertEqual(s_list.head.next, None)
        self.assertEqual(s_list.tail.prev, None)
        self.assertEqual(s_list.tail.next, None)
        self.assertEqual(s_list.len(), 1)

        #add in non empty list
        s_list.add_in_head(Node(88))
        self.assertEqual(s_list.find(88).value, 88)
        self.assertEqual(s_list.head.value, 88)
        self.assertEqual(s_list.tail.value, 4)
        self.assertEqual(s_list.head.prev, None)
        self.assertEqual(s_list.head.next.value, 4)
        self.assertEqual(s_list.tail.prev.value, 88)
        self.assertEqual(s_list.tail.next, None)
        s_list.len()
        self.assertEqual(s_list.len(), 2)

        #add in non empty list
        s_list.add_in_head(Node(205))
        self.assertEqual(s_list.find(205).value, 205)
        self.assertEqual(s_list.head.value, 205)
        self.assertEqual(s_list.tail.value, 4)
        self.assertEqual(s_list.head.next.value, 88)
        self.assertEqual(s_list.tail.prev.value, 88)
        self.assertEqual(s_list.head.prev, None)
        self.assertEqual(s_list.tail.next, None)
        self.assertEqual(s_list.len(), 3)

        #add in non empty list
        s_list.add_in_head(Node(35))
        self.assertEqual(s_list.find(35).value, 35)
        self.assertEqual(s_list.head.value, 35)
        self.assertEqual(s_list.tail.value, 4)
        self.assertEqual(s_list.head.next.value, 205)
        self.assertEqual(s_list.tail.prev.value, 88)
        self.assertEqual(s_list.head.prev, None)
        self.assertEqual(s_list.tail.next, None)
        s_list.len()
        self.assertEqual(s_list.len(), 4)
Exemple #25
0
    def test_insert_in_tail(self):
        list3 = LinkedList2()
        n1 = Node(20)
        n2 = Node(55)
        n3 = Node(12)
        n4 = Node(10)
        n5 = Node(55)
        n6 = Node(22)
        list3.add_in_tail(n1)
        list3.add_in_tail(n2)

        #list3.insert(list3.get_tail(), n3)
        list3.insert(None, n3)
        self.assertEqual(list3.get_all(), [n1.value, n2.value, n3.value])
        self.assertEqual(list3.get_head().prev, None)
        self.assertEqual(list3.get_tail().next, None)
        self.assertEqual(list3.get_head(), n1)
        self.assertEqual(list3.get_tail(), n3)
        self.assertEqual(n3.prev, n2)
        self.assertEqual(n2.next, n3)

        list3.add_in_tail(n4)
        list3.add_in_tail(n5)
        self.assertEqual(list3.get_all(), [20, 55, 12, 10, 55])

        #list3.insert(list3.get_tail(), n6)
        list3.insert(None, n6)
        self.assertEqual(list3.get_all(), [20, 55, 12, 10, 55, 22])
        self.assertEqual(list3.get_head().prev, None)
        self.assertEqual(list3.get_tail().next, None)
        self.assertEqual(list3.get_head(), n1)
        self.assertEqual(list3.get_tail(), n6)
        self.assertEqual(n6.prev, n5)
        self.assertEqual(n5.next, n6)
        self.assertEqual(n2.prev, n1)
        self.assertEqual(n1.next, n2)
        self.assertEqual(n3.prev, n2)
        self.assertEqual(n2.next, n3)
        self.assertEqual(n4.prev, n3)
        self.assertEqual(n3.next, n4)
        self.assertEqual(n5.prev, n4)
        self.assertEqual(n4.next, n5)

        list3.insert(list3.get_tail(), None)
        self.assertEqual(list3.get_all(), [20, 55, 12, 10, 55, 22])
    def test_all_methods(self):
        s_list = LinkedList2()
        s_list.add_in_tail(Node(11))
        s_list.insert(Node(11), Node(22))

        #check head and tail after inserting
        self.assertEqual(s_list.head.value, 11)
        self.assertEqual(s_list.tail.value, 22)
        self.assertEqual(s_list.head.next.value, 22)
        self.assertEqual(s_list.tail.prev.value, 11)
        self.assertEqual(s_list.len(), 2)

        #add another element in tail
        s_list.add_in_tail(Node(48))
        self.assertEqual(s_list.head.next.value, 22)
        self.assertEqual(s_list.tail.value, 48)
        self.assertEqual(s_list.tail.prev.value, 22)
        self.assertEqual(s_list.len(), 3)

        #add another element in head with add_in_head
        s_list.add_in_head(Node(55))
        self.assertEqual(s_list.head.value, 55)
        self.assertEqual(s_list.head.next.value, 11)
        self.assertEqual(s_list.find(11).prev.value, 55)
        self.assertEqual(s_list.head.next.prev.value, 55)
        s_list.len()
        self.assertEqual(s_list.len(), 4)

        #add another element in head with add_in_head
        s_list.add_in_head(Node(99))
        self.assertEqual(s_list.head.value, 99)
        self.assertEqual(s_list.head.next.value, 55)
        self.assertEqual(s_list.find(55).prev.value, 99)
        self.assertEqual(s_list.head.next.prev.value, 99)
        self.assertEqual(s_list.len(), 5)

        #insert another element in tail (with afterNode = None)
        s_list.insert(None, Node(115))
        self.assertEqual(s_list.head.value, 99)
        self.assertEqual(s_list.tail.value, 115)
        self.assertEqual(s_list.tail.prev.value, 48)
        s_list.len()
        self.assertEqual(s_list.len(), 6)
Exemple #27
0
    def _test_insert_in_head_not_success(self):
        list3 = LinkedList2()
        n1 = Node(55)
        n2 = Node(12)
        n3 = Node(55)
        n4 = Node(10)
        n5 = Node(20)
        list3.add_in_tail(n1)
        list3.add_in_tail(n2)
        list3.add_in_tail(n3)
        list3.add_in_tail(n4)

        list3.insert(None, n5)
        self.assertEqual(list3.get_all(),
                         [n5.value, n1.value, n2.value, n3.value, n4.value])
        self.assertEqual(list3.get_head().prev, None)
        self.assertEqual(list3.get_tail().next, None)
        self.assertEqual(list3.get_head(), n5)
        self.assertEqual(list3.get_tail(), n4)
        self.assertEqual(n5.next, n1)
        self.assertEqual(n1.prev, n5)
Exemple #28
0
    def test_add_in_head_in_1el(self):
        list3 = LinkedList2()
        n1 = Node(55)
        n4 = Node(10)
        list3.add_in_tail(n1)

        list3.add_in_head(None)
        self.assertEqual(list3.get_all(), [55])
        self.assertEqual(list3.get_head(), n1)
        self.assertEqual(list3.get_head().prev, None)
        self.assertEqual(list3.get_tail().next, None)
        self.assertEqual(list3.get_head().next, None)
        self.assertEqual(list3.get_tail().prev, None)

        list3.add_in_head(n4)
        self.assertEqual(list3.get_all(), [10, 55])
        self.assertEqual(list3.get_head().prev, None)
        self.assertEqual(list3.get_tail().next, None)
        self.assertEqual(list3.get_head(), n4)
        self.assertEqual(list3.get_tail(), n1)
        self.assertEqual(n4.next, n1)
        self.assertEqual(n1.prev, n4)
Exemple #29
0
    def test_insert_to_empty(self):
        list3 = LinkedList2()
        n7 = Node(11)

        list3.insert(None, None)
        self.assertEqual(list3.get_all(), [])
        self.assertEqual(list3.get_head(), None)
        self.assertEqual(list3.get_tail(), None)

        list3.insert(None, n7)
        self.assertEqual(list3.get_all(), [n7.value])
        self.assertEqual(list3.get_head().prev, None)
        self.assertEqual(list3.get_tail().next, None)
        self.assertEqual(list3.get_head(), n7)
        self.assertEqual(list3.get_tail(), n7)

        list3.insert(None, None)
        self.assertEqual(list3.get_all(), [n7.value])
        self.assertEqual(list3.get_head().prev, None)
        self.assertEqual(list3.get_tail().next, None)
        self.assertEqual(list3.get_head(), n7)
        self.assertEqual(list3.get_tail(), n7)
Exemple #30
0
    def test_add_in_tail(self):
        list3 = LinkedList2()
        n1 = Node(55)
        n2 = Node(12)
        n3 = Node(55)
        list3.add_in_tail(n1)

        list3.add_in_tail(n2)
        self.assertEqual(list3.get_all(), [n1.value, n2.value])
        self.assertEqual(list3.get_head().prev, None)
        self.assertEqual(list3.get_tail().next, None)
        self.assertEqual(list3.get_head(), n1)
        self.assertEqual(list3.get_tail(), n2)
        self.assertEqual(n1.next, n2)
        self.assertEqual(n2.prev, n1)

        list3.add_in_tail(n3)
        self.assertEqual(list3.get_all(), [55, 12, 55])
        self.assertEqual(list3.get_head().prev, None)
        self.assertEqual(list3.get_tail().next, None)
        self.assertEqual(list3.get_head(), n1)
        self.assertEqual(list3.get_tail(), n3)
        self.assertEqual(n1.next, n2)
        self.assertEqual(n2.prev, n1)
        self.assertEqual(n3.prev, n2)
        self.assertEqual(n2.next, n3)

        list3.add_in_tail(None)
        self.assertEqual(list3.get_all(), [55, 12, 55])
        self.assertEqual(list3.find(55), n1)
        self.assertEqual(list3.find_all(55), [n1, n3])
        self.assertEqual(list3.get_head(), n1)
        self.assertEqual(list3.get_tail(), n3)
        self.assertEqual(n1.prev, None)
        self.assertEqual(n3.next, None)
        self.assertEqual(n1.next, n2)
        self.assertEqual(n3.prev, n2)
        self.assertEqual(n2.next, n3)