def test_reverseBetween1(): head = ListNode.stringToListNode("[1,2,3,4,5]") m = 2 n = 4 expect = "[1, 4, 3, 2, 5]" actual = ListNode.listNodeToString(solution.reverseBetween(head, m, n)) assert actual == expect
def test_reverseBetween5(): head = ListNode.stringToListNode("[1,2,3,4,5,6,7,8,9]") m = 1 n = 5 expect = "[5, 4, 3, 2, 1, 6, 7, 8, 9]" actual = ListNode.listNodeToString(solution.reverseBetween(head, m, n)) assert actual == expect
def test_insertionsortlist1(): head = ListNode.stringToListNode("[4,2,1,3]") expexct = ListNode.stringToListNode("[1,2,3,4]") actual = solution.insertionSortList(head) assert ListNode.listNodeToString(actual) == ListNode.listNodeToString( expexct)
def test_rotateRight1(): head = ListNode.stringToListNode("[1, 2, 3, 4, 5]") k = 2 actual = solution.rotateRight(head, k) expect = ListNode.stringToListNode("[4, 5, 1, 2, 3]") assert ListNode.listNodeToString(actual) == ListNode.listNodeToString(expect)
def test_rotateRight4(): head = ListNode.stringToListNode("[0, 1, 2]") k = 3 actual = solution.rotateRight(head, k) expect = ListNode.stringToListNode("[0, 1, 2]") assert ListNode.listNodeToString(actual) == ListNode.listNodeToString(expect)
def test_reorderList1(): head = ListNode.stringToListNode("[1,2,3,4]") expect = ListNode.stringToListNode("[1,4,2,3]") solution.reorderList(head)
def test_reorderList5(): head = ListNode.stringToListNode("[1,2]") expect = ListNode.stringToListNode("[1,2]") solution.reorderList(head)
def test_deleteDuplicates8(): head = ListNode.stringToListNode('[1, 1, 2, 2]') expect = '[]' actual = ListNode.listNodeToString(solution.deleteDuplicates(head)) assert actual == expect
def test_detectCycle1(): head = ListNode.stringToListNode("[3,2,0,-4]") expect = head.next expect.next.next.next = expect actual = solution.detectCycle(head) assert actual == expect
def test_detectCycle4(): head = ListNode.stringToListNode("[1, 2, 3, 4]") expect = None actual = solution.detectCycle(head) assert actual == expect
def test_detectCycle2(): head = ListNode.stringToListNode("[1, 2]") expect = head expect.next.next = expect actual = solution.detectCycle(head) assert actual == expect
def test_buildTree1(): head = ListNode.stringToListNode("[-10,-3,0,5,9]") expect = TreeNode.stringToTreeNode("[0,-3,9,-10,null,5]") actual = solution.sortedListToBST(head) assert TreeNode.isSame(actual, expect)
def test_partitionList1(): head = ListNode.stringToListNode('[1, 4, 3, 2, 5, 2]') x = 3 expect = '[1, 2, 2, 4, 3, 5]' actual = ListNode.listNodeToString(solution.partition(head, x)) assert actual == expect