class Test(unittest.TestCase): '''Test Cases''' def setUp(self): self.node1 = Node(7) self.node1.connect(1).connect(6) self.node2 = Node(5) self.node2.connect(9).connect(2) def testGetNumberFromList(self): self.assertEqual(getReverseNumberFromLinkedList(self.node1), 617) self.assertEqual(getReverseNumberFromLinkedList(self.node2), 295) def testGetListFromNumber(self): node = getReverseLinkedListFromNumber(123) self.assertEqual(node.getPrev(), None) self.assertEqual(node.getValue(), 3) self.assertEqual(node.getNext().getValue(), 2) self.assertEqual(node.getNext().getNext().getValue(), 1) self.assertEqual(node.getNext().getNext().getNext(), None) def testSumLists(self): sum_node = sumLists(self.node1, self.node2) self.assertEqual(sum_node.getPrev(), None) self.assertEqual(sum_node.getValue(), 2) self.assertEqual(sum_node.getNext().getValue(), 1) self.assertEqual(sum_node.getNext().getNext().getValue(), 9) self.assertEqual(sum_node.getNext().getNext().getNext(), None)
class Test(unittest.TestCase): '''Test Cases''' def setUp(self): self.node = Node(1) self.node.connect(2).connect(3).connect(2).connect(4) def test_node_values(self): self.assertEqual(returnKthToLast(2, self.node), [2, 3, 2, 4])
class Test(unittest.TestCase): '''Test Cases''' def setUp(self): self.node = Node(1) self.node.connect(2).connect(3).connect(2).connect(4) removeDups(self.node) def test_node_values(self): self.assertEqual(self.node.getValue(), 1) self.assertEqual(self.node.getNext().getValue(), 2) self.assertEqual(self.node.getNext().getNext().getValue(), 3) self.assertEqual(self.node.getNext().getNext().getNext().getValue(), 4) self.assertEqual(self.node.getNext().getNext().getNext().getNext(), None)
class Test(unittest.TestCase): '''Test Cases''' def setUp(self): self.node = Node(1) self.node.connect(2).connect(3).connect(4).connect(5) deleteMiddleNode(self.node) self.node2 = Node(1) self.node2.connect(2).connect(3).connect(4) deleteMiddleNode(self.node2) def test_node_values_1(self): self.assertEqual(self.node.getValue(), 1) self.assertEqual(self.node.getNext().getValue(), 2) self.assertEqual(self.node.getNext().getNext().getValue(), 4) self.assertEqual(self.node.getNext().getNext().getNext().getValue(), 5) self.assertEqual(self.node.getNext().getNext().getNext().getNext(), None) def test_node_values_2(self): self.assertEqual(self.node2.getValue(), 1) self.assertEqual(self.node2.getNext().getValue(), 2) self.assertEqual(self.node2.getNext().getNext().getValue(), 4) self.assertEqual(self.node2.getNext().getNext().getNext(), None)
next_node = node.getNext() if v < n: prev_main_node.setPrev(node) node.setNext(prev_main_node) node.setPrev(None) prev_main_node = node else: next_main_node.setNext(node) node.setPrev(next_main_node) next_main_node = node node = next_node return prev_main_node node = Node(1) node.connect(2).connect(10).connect(3).connect(4).connect(5) new_node = partition(node, 5) print(new_node.getPrev()) print(new_node.getValue()) print(new_node.getNext().getValue()) print(new_node.getNext().getNext().getValue()) print(new_node.getNext().getNext().getNext().getValue()) print(new_node.getNext().getNext().getNext().getNext().getValue()) print(new_node.getNext().getNext().getNext().getNext().getNext().getValue()) print(new_node.getNext().getNext().getNext().getNext().getNext().getNext())