def test_remove_nth_from_end(self): self.assertEqual([1, 2, 3, 5], linkedListToList( removeNthFromEnd(createListNode([1, 2, 3, 4, 5]), 2))) self.assertEqual([], linkedListToList( removeNthFromEnd(createListNode([1]), 1)))
def test_reorder_list(self): head = createListNode([1, 2, 3, 4]) reorderList(head) self.assertEqual([1, 4, 2, 3], linkedListToList(head)) head = createListNode([1, 2, 3, 4, 5]) reorderList(head) self.assertEqual([1, 5, 2, 4, 3], linkedListToList(head))
def test_merge_two_lists(self): self.assertEqual([1, 1, 2, 3, 4, 4], linkedListToList( mergeTwoLists(createListNode([1, 2, 4]), createListNode([1, 3, 4])))) self.assertEqual([], linkedListToList( mergeTwoLists(createListNode([]), createListNode([]))))
def test_add_two_numbers(self): self.assertEqual([7, 0, 8], linkedListToList( addTwoNumbers(createListNode([2, 4, 3]), createListNode([5, 6, 4]))))
def test_sort_list(self): self.assertEqual([1, 2, 3, 4], linkedListToList( sortList(createListNode([4, 2, 1, 3]))))
def test_merge_klists(self): input = [[1, 4, 5], [1, 3, 4], [2, 6]] inputListNodes = [createListNode(x) for x in input] self.assertEqual([1, 1, 2, 3, 4, 4, 5, 6], linkedListToList(mergeKLists(inputListNodes)))