def test_add_last_has_head(self): second_to_last = DoublyNode(55) last_node = DoublyNode(7) self.helper.helper_add_last_has_head(self.linked_list, second_to_last, last_node) self.assertEqual(last_node.prev, second_to_last)
def test_insert_before_only_head(self): after_node = DoublyNode(99999) new_node = DoublyNode(1246) self.helper.helper_insert_before_only_head(self.linked_list, after_node, new_node) self.assertIsNone(self.linked_list.head.prev) self.assertEqual(after_node.prev, new_node)
def test_insert_after_only_head(self): prev_node = DoublyNode(1) new_node = DoublyNode(11) self.helper.helper_insert_after_only_head(self.linked_list, prev_node, new_node) self.assertIsNone(self.linked_list.head.prev) self.assertEqual(self.linked_list.head, new_node.prev)
def test_add_first_has_head(self): old_head = DoublyNode(13) new_head = DoublyNode(6) self.helper.helper_add_first_has_head(self.linked_list, old_head, new_head) self.assertIsNone(self.linked_list.head.prev) self.assertEqual( self.linked_list.head.next.prev, #Second node's prev new_head)
def test_insert_before_after_head(self): after_node = DoublyNode(765) new_node = DoublyNode(123) self.linked_list.head = DoublyNode(3) self.linked_list.head.next = after_node after_node.prev = self.linked_list.head self.helper.helper_insert_before_after_head(self.linked_list, after_node, new_node) self.assertEqual(new_node.prev, self.linked_list.head) self.assertEqual(after_node.prev, new_node)
def test_insert_after_after_head(self): prev_node = DoublyNode(2) new_node = DoublyNode(5) self.linked_list.head = DoublyNode(7) self.linked_list.head.next = prev_node prev_node.prev = self.linked_list.head self.helper.helper_insert_after_after_head(self.linked_list, prev_node, new_node) self.assertEqual(prev_node.prev, self.linked_list.head) self.assertEqual(new_node.prev, prev_node)
def test_clone_multiple(self): head = DoublyNode(99999) head.next = DoublyNode(4562) head.next.prev = head head.next.next = DoublyNode(12353) head.next.next.prev = head.next clone = self.helper.helper_clone_multiple(self.linked_list, head) current_clone = clone.head.next current_list = head.next while current_clone is not None: self.assertNotEqual(current_list.prev, current_clone.prev) self.assertEqual(current_list.prev.data, current_clone.prev.data) current_clone = current_clone.next current_list = current_list.next
def test_add_last_in_list(self): head = DoublyNode(123) to_be_last_node = DoublyNode(555) head.next = to_be_last_node to_be_last_node.prev = head to_be_last_node.next = DoublyNode(7656) to_be_last_node.next.prev = to_be_last_node self.linked_list.head = head self.helper.helper_add_last_in_list(self.linked_list, to_be_last_node) prev_node = None current_node = self.linked_list.head while current_node.next is not None: prev_node = current_node current_node = current_node.next print(f"{prev_node.data} {current_node.data}") self.assertEqual(prev_node.data, current_node.prev.data)
def test_clone_only_head(self): head = DoublyNode(145) self.helper.helper_clone_only_head(self.linked_list, head)
def test_delete_node_only_head(self): node_to_delete = DoublyNode(6) self.helper.helper_delete_node_only_head(self.linked_list, node_to_delete)
def test_insert_before_no_head(self): after_node = DoublyNode(2) new_node = DoublyNode(1000) self.helper.helper_insert_before_no_head(self.linked_list, after_node, new_node)
def test_insert_after_no_head(self): self.helper.helper_insert_after_no_head(self.linked_list, DoublyNode(7))
def test_add_last_no_head(self): self.helper.helper_add_last_no_head(self.linked_list, DoublyNode(62))
def test_add_first_no_head(self): self.helper.helper_add_first_no_head(self.linked_list, DoublyNode(17))