Ejemplo n.º 1
0
    def test_delete_several_in_everywhere(self):
        test_list = LinkedList2()
        n1 = Node(1)
        n2 = Node(2)
        n3 = Node(3)
        test_list.add_in_tail(Node(555))
        test_list.add_in_tail(Node(555))
        test_list.add_in_tail(Node(555))
        test_list.add_in_tail(Node(555))
        test_list.add_in_tail(Node(555))
        test_list.add_in_tail(n1)
        test_list.add_in_tail(Node(555))
        test_list.add_in_tail(n2)
        test_list.add_in_tail(Node(555))
        test_list.add_in_tail(n3)
        test_list.add_in_tail(Node(555))
        test_list.add_in_tail(Node(555))
        test_list.add_in_tail(Node(555))
        test_list.add_in_tail(Node(555))
        test_list.add_in_tail(Node(555))

        test_list.delete(555, all=True)
        self.assertEqual(n1.next, n2, "n3 should be followed by n1")
        self.assertEqual(test_list.head, n1, "n1 should be head")
        self.assertEqual(test_list.tail, n3, "n3 should be tail")
        self.assertEqual(n3.prev, n2)
        self.assertEqual(n2.prev, n1)
Ejemplo n.º 2
0
 def test_clean(self):
     test_list = LinkedList2()
     n1 = Node(1)
     n2 = Node(2)
     n3 = Node(3)
     test_list.add_in_tail(Node(555))
     test_list.add_in_tail(Node(555))
     test_list.add_in_tail(Node(555))
     test_list.add_in_tail(Node(555))
     test_list.add_in_tail(Node(555))
     test_list.add_in_tail(n1)
     test_list.add_in_tail(Node(555))
     test_list.add_in_tail(Node(555))
     test_list.add_in_tail(Node(555))
     test_list.add_in_tail(n2)
     test_list.add_in_tail(Node(555))
     test_list.add_in_tail(Node(555))
     test_list.add_in_tail(Node(555))
     test_list.add_in_tail(n3)
     test_list.add_in_tail(Node(555))
     test_list.add_in_tail(Node(555))
     test_list.add_in_tail(Node(555))
     test_list.clean()
     self.assertEqual(test_list.len(), 0, "Length should be 0")
     self.assertIsNone(test_list.head, "Should be None")
     self.assertIsNone(test_list.tail, "Should be None")
Ejemplo n.º 3
0
 def test_insert_in_the_empty_list(self):
     n1 = Node(12)
     test_list = LinkedList2()
     test_list.insert(None, n1)
     self.assertEqual(n1.value, test_list.head.value,
                      "Head should equal n1")
     self.assertEqual(n1, test_list.tail, "Tail should be n1")
     self.assertEqual(12, test_list.head.value, "Head should equal 12")
Ejemplo n.º 4
0
    def test_add_in_the_beginning_in_the_empty(self):
        n4 = Node(4)
        test_list = LinkedList2()

        test_list.add_in_head(n4)
        self.assertEqual(n4.value, test_list.head.value,
                         "Tail should equal n4")
        self.assertEqual(n4.next, None, "Tail should be n3")
        self.assertEqual(n4, test_list.tail, "Head should equal n4")
        self.assertEqual(n4.prev, None, "n4 prev should be None")
Ejemplo n.º 5
0
 def test_add_in_tail_empty(self):
     test_list = LinkedList2()
     self.assertIsNone(test_list.head, "Head is None")
     self.assertIsNone(test_list.tail, "Tail is None")
     n1 = Node(2)
     test_list.add_in_tail(n1)
     self.assertEqual(test_list.head, n1, "n1 is head")
     self.assertEqual(test_list.tail, n1, "n1 is tail")
     self.assertIsNone(n1.prev, "n1 prev is none")
     self.assertIsNone(n1.next, "n1 next is none")
Ejemplo n.º 6
0
 def test_delete_from_list_in_the_middle(self):
     test_name = self.test_delete_from_list_in_the_middle.__name__
     n1 = Node(12)
     n2 = Node(144)
     n3 = Node(55)
     test_list = LinkedList2()
     test_list.add_in_tail(n1)
     test_list.add_in_tail(n2)
     test_list.add_in_tail(n3)
     self.assertEqual(test_list.head, n1, "n1 should be head")
     self.assertEqual(test_list.tail, n3, "n3 should be tail")
Ejemplo n.º 7
0
 def test_delete_from_list_in_the_beginning(self):
     n1 = Node(12)
     n2 = Node(144)
     n3 = Node(55)
     test_list = LinkedList2()
     test_list.add_in_tail(n1)
     test_list.add_in_tail(n2)
     test_list.add_in_tail(n3)
     test_list.delete(12)
     self.assertEqual(n2.next, n3, "n3 should be followed by n1")
     self.assertEqual(test_list.head, n2, "n1 should be head")
     self.assertEqual(test_list.tail, n3, "n3 should be tail")
Ejemplo n.º 8
0
 def test_delete_something_not_in_the_list(self):
     n1 = Node(12)
     n2 = Node(144)
     n3 = Node(55)
     test_list = LinkedList2()
     test_list.add_in_tail(n1)
     test_list.add_in_tail(n2)
     test_list.add_in_tail(n3)
     test_list.delete(123)
     self.assertEqual(n1.next, n2, "n2 should be followed by n1")
     self.assertEqual(n2.next, n3, "n2 should be followed by n1")
     self.assertEqual(test_list.head, n1, "n1 should be head")
     self.assertEqual(test_list.tail, n3, "n3 should be tail")
Ejemplo n.º 9
0
 def test_insert_in_the_end_next(self):
     n1 = Node(12)
     n2 = Node(1)
     n3 = Node(123)
     n4 = Node(4)
     test_list = LinkedList2()
     test_list.add_in_tail(n1)
     test_list.add_in_tail(n2)
     test_list.add_in_tail(n3)
     test_list.insert(n3, n4)
     self.assertEqual(n3.next, n4, "n4 next is n3")
     self.assertEqual(n4.prev, n3, "n4 prev is n2")
     self.assertEqual(n4, test_list.tail, "Tail should equal n4")
     self.assertEqual(n1, test_list.head, "n4 should be before n1")
Ejemplo n.º 10
0
 def test_add_in_the_beginning(self):
     n1 = Node(12)
     n2 = Node(1)
     n3 = Node(123)
     n4 = Node(4)
     test_list = LinkedList2()
     test_list.add_in_tail(n1)
     test_list.add_in_tail(n2)
     test_list.add_in_tail(n3)
     test_list.add_in_head(n4)
     self.assertEqual(n4.value, test_list.head.value,
                      "Tail should equal n4")
     self.assertEqual(n4.next, n1, "Tail should be n3")
     self.assertEqual(n4, test_list.head, "Head should equal n4")
     self.assertEqual(n4.prev, None, "n4 prev should be None")
     self.assertEqual(n1.prev, n4, "n4 prev should be n3")
Ejemplo n.º 11
0
 def test_find_one_in_the_middle(self):
     test_list = LinkedList2()
     n1 = Node(1)
     n3 = Node(3)
     n2 = Node(1)
     n4 = Node(3)
     n5 = Node(5)
     test_list.add_in_tail(n1)
     test_list.add_in_tail(n3)
     test_list.add_in_tail(n2)
     test_list.add_in_tail(n4)
     test_list.add_in_tail(n5)
     self.assertIsNone(test_list.find(2), "There is no 2")
     self.assertEqual(test_list.find(1), n1, "n1 is the first with 1")
     self.assertEqual(test_list.find(3), n3, "n3 is the first with 3")
     self.assertEqual(test_list.find(5), n5, "n5 is the first with 5")
Ejemplo n.º 12
0
 def test_insert_in_the_end(self):
     n1 = Node(12)
     n2 = Node(1)
     n3 = Node(123)
     n4 = Node(4)
     test_list = LinkedList2()
     test_list.add_in_tail(n1)
     test_list.add_in_tail(n2)
     test_list.add_in_tail(n3)
     test_list.insert(None, n4)
     self.assertEqual(n4.value, test_list.tail.value,
                      "Tail should equal n4")
     self.assertEqual(n3.next, test_list.tail, "Tail should be n3")
     self.assertEqual(n4, test_list.tail, "Head should equal n4")
     self.assertEqual(n4.next, None, "n4 should be before n1")
     self.assertEqual(n4.prev, n3, "n4 prev should be n3")
Ejemplo n.º 13
0
 def test_find_all(self):
     test_list = LinkedList2()
     n1 = Node(1)
     n2 = Node(2)
     n3 = Node(3)
     n4 = Node(2)
     test_list.add_in_tail(n1)
     test_list.add_in_tail(n2)
     test_list.add_in_tail(n3)
     test_list.add_in_tail(n4)
     finding2 = test_list.find_all(2)
     finding3 = test_list.find_all(3)
     self.assertIn(n2, finding2, "n2 is in finding2")
     self.assertEqual(n2.value, finding2[0].value)
     self.assertIn(n4, finding2, "n4 is in finding2")
     self.assertEqual(len(finding2), 2, "The length of list is 2")
     self.assertIn(n3, finding3, "n3 is in finding3")
Ejemplo n.º 14
0
    def test_delete_from_list_from_the_end(self):
        n1 = Node(12)
        n2 = Node(144)
        n3 = Node(55)
        test_list = LinkedList2()
        test_list.add_in_tail(n1)
        test_list.add_in_tail(n2)
        test_list.add_in_tail(n3)
        self.assertEqual(test_list.head, n1, "n1 should be head ")
        self.assertEqual(test_list.tail, n3, "n3 should be tail ")
        test_list.delete(55)
        self.assertEqual(n1.next, n2, "n2 should be followed by n1")
        self.assertEqual(test_list.head, n1,
                         "n1 should be head after deletion")
        self.assertEqual(test_list.tail.value, n2.value,
                         "n2 should be tail after deletion")

        self.assertEqual(test_list.len(), 2, "Length should be 2")
Ejemplo n.º 15
0
 def test_add_in_tail_not_empty(self):
     test_list = LinkedList2()
     self.assertIsNone(test_list.head, "Head is None")
     self.assertIsNone(test_list.tail, "Tail is None")
     n1 = Node(2)
     test_list.add_in_tail(n1)
     self.assertEqual(test_list.head, n1, "n1 is head")
     self.assertEqual(test_list.tail, n1, "n1 is tail")
     self.assertIsNone(n1.prev, "n1 prev is none")
     self.assertIsNone(n1.next, "n1 next is none")
     n2 = Node(3)
     test_list.add_in_tail(n2)
     self.assertEqual(test_list.head, n1, "n1 is head")
     self.assertEqual(test_list.tail, n2, "n2 is tail")
     self.assertIsNone(test_list.head.prev, "Head prev is none")
     self.assertEqual(test_list.tail.prev, n1, "n1 is tail prev")
     self.assertIsNone(test_list.tail.next)
     self.assertEqual(n2.prev, n1, "n1 prev of n2")
     self.assertEqual(n1.next, n2, "n2 is n1 next")
Ejemplo n.º 16
0
 def test_insert_in_the_middle(self):
     n1 = Node(1)
     n3 = Node(3)
     n5 = Node(5)
     n4 = Node(4)
     n2 = Node(2)
     test_list = LinkedList2()
     test_list.add_in_tail(n1)
     test_list.add_in_tail(n3)
     test_list.add_in_tail(n5)
     test_list.insert(n3, n4)
     self.assertEqual(n3.next, n4, "n3 next is n4")
     self.assertEqual(n4.prev, n3, "n4 prev is n3")
     self.assertEqual(n5, test_list.tail, "Tail should equal n5")
     self.assertEqual(n1, test_list.head, "n1 should be head")
     test_list.insert(n1, n2)
     self.assertEqual(n1.next, n2, "n1 next is n2")
     self.assertEqual(n2.prev, n1, "n5 prev is n1")
     self.assertEqual(n2.next, n3, "n2 next is n3")
     self.assertEqual(n2.prev, n1, "n2 prev is n1")
     self.assertEqual(n5, test_list.tail, "Tail should equal n5")
     self.assertEqual(n1, test_list.head, "Head should equal n1")
Ejemplo n.º 17
0
 def test_find_all_empty_list(self):
     test_list = LinkedList2()
     finding_zero_list = test_list.find_all(2)
     self.assertEqual(len(finding_zero_list), 0, "The length of list is 0")
     self.assertEqual(type(finding_zero_list), list,
                      "The return value is list")
Ejemplo n.º 18
0
 def test_find_empty(self):
     test_list = LinkedList2()
     test_list.find(3)
     self.assertIsNone(test_list.find(3), "List is empty it should be None")
Ejemplo n.º 19
0
 def test_delete_from_list_with_one(self):
     test_list = LinkedList2()
     test_list.add_in_tail(Node(123))
     test_list.delete(123)
     self.assertIsNone(test_list.head, "Head should be none")
     self.assertIsNone(test_list.tail, "Tail should be none")
Ejemplo n.º 20
0
 def test_length_for_empty_list(self):
     test_list = LinkedList2()
     self.assertEqual(test_list.len(), 0, "length should be zero")
Ejemplo n.º 21
0
 def test_delete_from_empty_list(self):
     test_list = LinkedList2()
     test_list.delete(1)
     self.assertEqual(None, test_list.head, "Head should be none")
     self.assertEqual(None, test_list.tail, "Tail should be none")
Ejemplo n.º 22
0
 def test_find_one(self):
     test_list = LinkedList2()
     n1 = Node(2)
     test_list.add_in_tail(n1)
     self.assertEqual(test_list.find(2), n1,
                      "n1 should be equal to finding")