Example #1
0
 def test_remove_all_in_between(self):
     dl_list = DoublyLinkedList([1, 2, 3, 4, 5, 6])
     self.assertEqual(len([i for i in dl_list.items()]), 6)
     new_list = dl_list.removeAllInBetween(\
         dl_list.firstnode().next(), dl_list.lastnode().prev())
     self.assertEqual(len([i for i in dl_list.items()]), 4)
     self.assertEqual(len([i for i in new_list.items()]), 2)
     self.assertEqual(new_list.firstnode().value, 3)
Example #2
0
 def test_remove_before(self):
     dl_list = DoublyLinkedList([1, 2, 3])
     self.assertEqual(len([i for i in dl_list.items()]), 3)
     dl_list.removeBeforeNode(dl_list.lastnode())
     self.assertEqual(dl_list.lastnode().prev().value, 1)
     self.assertEqual(len([i for i in dl_list.items()]), 2)
Example #3
0
 def test_remove_node_last_item(self):
     dl_list = DoublyLinkedList([1, 2, 3])
     self.assertEqual(len([i for i in dl_list.items()]), 3)
     dl_list.removeNode(dl_list.lastnode())
     self.assertEqual(dl_list.lastnode().value, 2)
     self.assertEqual(len([i for i in dl_list.items()]), 2)
Example #4
0
 def test_create_new_linked_list_from_list(self):
     dl_list = DoublyLinkedList([1, 2, 3])
     self.assertIsInstance(dl_list, DoublyLinkedList)
     self.assertEqual(dl_list.firstnode().value, 1)
     self.assertEqual(dl_list.lastnode().value, 3)
Example #5
0
 def test_insert_after_last_item(self):
     dl_list = DoublyLinkedList([1, 2, 3])
     self.assertEqual(len([i for i in dl_list.items()]), 3)
     dl_list.insertAfter(4, dl_list.lastnode())
     self.assertEqual(dl_list.lastnode().value, 4)
     self.assertEqual(len([i for i in dl_list.items()]), 4)
Example #6
0
 def test_insert_before(self):
     dl_list = DoublyLinkedList([1, 2, 3])
     self.assertEqual(len([i for i in dl_list.items()]), 3)
     dl_list.insertBefore(4, dl_list.lastnode().prev())
     self.assertEqual(dl_list.lastnode().prev().prev().value, 4)
     self.assertEqual(len([i for i in dl_list.items()]), 4)
Example #7
0
 def test_lastnode_on_empty_list(self):
     dl_list = DoublyLinkedList()
     self.assertEqual(dl_list.lastnode(), None)
Example #8
0
 def test_insert_last_node_empty_list(self):
     dl_list = DoublyLinkedList()
     self.assertEqual(len([i for i in dl_list.items()]), 0)
     dl_list.insertLastNode(1)
     self.assertEqual(dl_list.lastnode().value, 1)
     self.assertEqual(len([i for i in dl_list.items()]), 1)
Example #9
0
 def test_insert_last_node(self):
     dl_list = DoublyLinkedList([1, 2, 3])
     self.assertEqual(len([i for i in dl_list.items()]), 3)
     dl_list.insertLastNode(4)
     self.assertEqual(dl_list.lastnode().value, 4)
     self.assertEqual(len([i for i in dl_list.items()]), 4)
Example #10
0
 def test_create_new_linked_list_one_elem(self):
     dl_list = DoublyLinkedList([1])
     self.assertEqual(dl_list.firstnode().value, 1)
     self.assertEqual(dl_list.lastnode().value, 1)
Example #11
0
 def test_remove_after_first_item(self):
     dl_list = DoublyLinkedList([1, 2, 3])
     with self.assertRaises(DoublyLinkedListError):
         dl_list.removeAfterNode(dl_list.lastnode())