JAVA-12383 GitHub Issue: Incorrect results in Kadane Algorithm for Maximal Subarray

This commit is contained in:
anuragkumawat
2022-06-01 21:05:22 +05:30
parent 1f96a77fec
commit ddf898fe0b
2 changed files with 13 additions and 1 deletions
@@ -27,4 +27,16 @@ class KadaneAlgorithmUnitTest {
//then
assertEquals(-1, maxSum);
}
@Test
void givenArrayWithAllPosiitveNumbersWhenMaximumSubarrayThenReturnsExpectedResult() {
//given
int[] arr = new int[] {4, 1, 3, 2};
//when
KadaneAlgorithm algorithm = new KadaneAlgorithm();
int maxSum = algorithm.maxSubArraySum(arr);
//then
assertEquals(10, maxSum);
}
}