def testReverseKGroup(self): s = Solution() heads = [getList(range(1,6)), getList(range(1,6))] ks = [2,3] ans = [[2,1,4,3,5], [3,2,1,4,5]] for head, k, an in zip(heads, ks, ans): self.assertEqual(saveList(s.reverseKGroup(head, k)), an)
def testSwapPairs(self): s = Solution() head = getList([1, 2, 3]) head = s.swapPairs(head) vals = saveList(head) an = [2, 1, 3] self.assertEqual(vals, an)
def testPartition(self): s = Solution() head = getList([1,4,3,2,5,2]) an = [1,2,2,4,3,5] self.assertEqual(saveList(s.partition(head, 3)), an)
def testRemoveNthFromEnd(self): s = Solution() head = getList([1,2,3,4,5]) self.assertEqual(saveList(s.removeNthFromEnd(head, 1)), [1,2,3,4])
def testInsertionSortList(self): s = Solution() head = getList([0, 1, 3, 2, 6, 7, 5, 4]) an = range(8) self.assertEqual(saveList(s.insertionSortList(head)), an)
def testDeleteDuplicates(self): s = Solution() heads = [getList([1,2,3,3,4,4,5]), getList([1,1,1,2,3])] ans = [[1,2,5], [2,3]] for head,an in zip(heads, ans): self.assertEqual(saveList(s.deleteDuplicates(head)), an)
def testReverseBetween(self): s = Solution() head = getList([0, 1, 3, 2, 6, 7, 5, 4]) an = [0, 6, 2, 3, 1, 7, 5, 4] self.assertEqual(saveList(s.reverseBetween(head, 2, 5)), an)