コード例 #1
0
 def test(self):
     test_array = [
         {
             'l1': [1, 2, 4],
             'l2': [1, 3, 4],
             'expected': [1, 1, 2, 3, 4, 4]
         },
     ]
     for data in test_array:
         l1 = list_to_listnode(data['l1'])
         l2 = list_to_listnode(data['l2'])
         expected = data['expected']
         with self.subTest(l1=l1, l2=l2):
             head = self.solution.mergeTwoLists(l1, l2)
             self.assertEqual(listnode_to_list(head), expected)
コード例 #2
0
 def test(self):
     test_array = [
         {'arr': [4, 2, 1, 3]},
         {'arr': [-1, 5, 3, 4, 0]},
         {'arr': [1, 2, 3, 4, 5]},
         {'arr': []},
     ]
     for data in test_array:
         arr = data['arr']
         expected = sorted(data['arr'])
         with self.subTest(arr=arr):
             head = list_to_listnode(arr)
             result = self.solution.sortList(head)
             self.assertEqual(listnode_to_list(result), expected)
コード例 #3
0
 def test(self):
     test_array = [
         {
             'lists': [
                 [1, 4, 5],
                 [1, 3, 4],
                 [2, 6],
             ],
             'expected': [1, 1, 2, 3, 4, 4, 5, 6],
         },
     ]
     for data in test_array:
         lists = [list_to_listnode(array) for array in data['lists']]
         expected = data['expected']
         with self.subTest(lists=lists):
             head = self.solution.mergeKLists(lists)
             self.assertEqual(listnode_to_list(head), expected)
コード例 #4
0
 def test(self):
     test_array = [
         {
             'arr': [1, 2, 3, 4, 5],
             'expected': [3, 4, 5]
         },
         {
             'arr': [1, 2, 3, 4, 5, 6],
             'expected': [4, 5, 6]
         },
         {
             'arr': [],
             'expected': []
         },
     ]
     for data in test_array:
         arr = data['arr']
         expected = data['expected']
         with self.subTest(arr=arr):
             head = list_to_listnode(arr)
             result = self.solution.middleNode(head)
             self.assertEqual(listnode_to_list(result), expected)
コード例 #5
0
 def test2(self):
     l1 = list_to_listnode([0, 1, 0, 9])
     l2 = list_to_listnode([1, 9, 9])
     expected_head = self.solution.addTwoNumbers(l1, l2)
     expected = [1, 0, 0, 0, 1]
     self.assertEqual(listnode_to_list(expected_head), expected)
コード例 #6
0
 def test(self):
     l1 = list_to_listnode([2, 4, 3])
     l2 = list_to_listnode([5, 6, 4])
     expected_head = self.solution.addTwoNumbers(l1, l2)
     expected = [7, 0, 8]
     self.assertEqual(listnode_to_list(expected_head), expected)
コード例 #7
0
 def test4(self):
     head = list_to_listnode([1])
     n = 1
     expected_head = self.solution.removeNthFromEnd(head, n)
     expected = []
     self.assertEqual(listnode_to_list(expected_head), expected)
コード例 #8
0
 def test(self):
     head = list_to_listnode([1, 2, 3, 4, 5])
     n = 2
     expected_head = self.solution.removeNthFromEnd(head, n)
     expected = [1, 2, 3, 5]
     self.assertEqual(listnode_to_list(expected_head), expected)
コード例 #9
0
 def test(self):
     head = list_to_listnode([1, 2, 3, 4, 5])
     expected_head = self.solution.reverseList(head)
     expected = [5, 4, 3, 2, 1]
     self.assertEqual(listnode_to_list(expected_head), expected)