Add unit tests for Minimum Path Sum algorithm (#4233)

* Add unit tests for Minimum Path Sum algorithm

* fix lint issues

* fix lint issues

* fix clang lint issue
This commit is contained in:
ngominhtrint 2023-07-09 12:24:00 -05:00 committed by GitHub
parent 9ecc3aae59
commit 4effd28d80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -0,0 +1,44 @@
package com.thealgorithms.dynamicprogramming;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
public class MinimumPathSumTest {
@Test
public void testMinimumPathSumWithRegularGrid() {
int[][] grid = {{1, 3, 1}, {1, 5, 1}, {4, 2, 1}};
assertEquals(7, MinimumPathSum.minimumPathSum(grid));
}
@Test
public void testMinimumPathSumWithOneRowOneColumnGrid() {
int[][] grid = {{2}};
assertEquals(2, MinimumPathSum.minimumPathSum(grid));
}
@Test
public void testMinimumPathSumWithEmptyGrid() {
int[][] grid = {{}};
assertEquals(0, MinimumPathSum.minimumPathSum(grid));
}
@Test
public void testMinimumPathSumWithOneColumnGrid() {
int[][] grid = {{1}, {2}, {3}};
assertEquals(6, MinimumPathSum.minimumPathSum(grid));
}
@Test
public void testMinimumPathSumGridOneRowGrid() {
int[][] grid = {{1, 2, 3}};
assertEquals(6, MinimumPathSum.minimumPathSum(grid));
}
@Test
public void testMinimumPathSumWithDiffRowAndColumnGrid() {
int[][] grid = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}};
assertEquals(30, MinimumPathSum.minimumPathSum(grid));
}
}