|
2 | 2 | import copy |
3 | 3 | from typing import List |
4 | 4 | from parameterized import parameterized |
5 | | -from algorithms.dynamic_programming.min_path_sum import min_path_sum, min_path_sum_2 |
| 5 | +from algorithms.dynamic_programming.min_path_sum import min_path_sum_in_triangle, min_path_sum_in_triangle_2, min_path_sum_grid, min_path_sum_grid_2 |
6 | 6 |
|
7 | | -TEST_CASES = [ |
| 7 | +MIN_PATH_SUM_TRIANGLE_TEST_CASES = [ |
8 | 8 | ([[5]], 5), |
9 | 9 | ([[2], [3, 4]], 5), |
10 | 10 | ([[1000], [2000, 3000]], 3000), |
11 | 11 | ([[2], [3, 4], [6, 5, 7], [4, 1, 8, 3]], 11), |
12 | 12 | ([[7], [3, 8], [8, 1, 0], [2, 7, 4, 4], [4, 5, 2, 6, 5]], 17), |
13 | 13 | ] |
14 | 14 |
|
| 15 | +MIN_PATH_SUM_GRID_TEST_CASES = [ |
| 16 | + ([[1,3,1],[1,5,1],[4,2,1]], 7), |
| 17 | + ([[1,2,3],[4,5,6]], 12), |
| 18 | + ([[1, 2, 5], [3, 2, 1]], 6), |
| 19 | + ([[5, 9, 1, 3], [4, 2, 1, 7], [3, 1, 1, 2]], 15), |
| 20 | + ([[5]], 5), |
| 21 | + ([[1, 0, 0], [1, 1, 0], [1, 1, 1]], 2), |
| 22 | + ([[7, 1, 3, 2], [2, 5, 10, 1], [4, 2, 1, 3]], 17), |
| 23 | +] |
15 | 24 |
|
16 | | -class MinPathSumInTriangleTestCase(unittest.TestCase): |
17 | | - @parameterized.expand(TEST_CASES) |
| 25 | + |
| 26 | +class MinPathSumTestCase(unittest.TestCase): |
| 27 | + @parameterized.expand(MIN_PATH_SUM_TRIANGLE_TEST_CASES) |
18 | 28 | def test_min_path_sum_in_triangle(self, triangle: List[List[int]], expected: int): |
19 | 29 | input_triangle = copy.deepcopy(triangle) |
20 | | - actual = min_path_sum(input_triangle) |
| 30 | + actual = min_path_sum_in_triangle(input_triangle) |
21 | 31 | self.assertEqual(expected, actual) |
22 | 32 |
|
23 | | - @parameterized.expand(TEST_CASES) |
| 33 | + @parameterized.expand(MIN_PATH_SUM_TRIANGLE_TEST_CASES) |
24 | 34 | def test_min_path_sum_2_in_triangle(self, triangle: List[List[int]], expected: int): |
25 | 35 | input_triangle = copy.deepcopy(triangle) |
26 | | - actual = min_path_sum_2(input_triangle) |
| 36 | + actual = min_path_sum_in_triangle_2(input_triangle) |
| 37 | + self.assertEqual(expected, actual) |
| 38 | + |
| 39 | + @parameterized.expand(MIN_PATH_SUM_GRID_TEST_CASES) |
| 40 | + def test_min_path_sum_in_grid(self, grid: List[List[int]], expected: int): |
| 41 | + input_triangle = copy.deepcopy(grid) |
| 42 | + actual = min_path_sum_grid(input_triangle) |
| 43 | + self.assertEqual(expected, actual) |
| 44 | + |
| 45 | + @parameterized.expand(MIN_PATH_SUM_GRID_TEST_CASES) |
| 46 | + def test_min_path_sum_2_in_grid(self, grid: List[List[int]], expected: int): |
| 47 | + input_triangle = copy.deepcopy(grid) |
| 48 | + actual = min_path_sum_grid_2(input_triangle) |
27 | 49 | self.assertEqual(expected, actual) |
28 | 50 |
|
29 | 51 |
|
|
0 commit comments