Skip to content

Commit e987dc8

Browse files
committed
Add Topological Sort using DFS with unit tests
1 parent fe08e48 commit e987dc8

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.thealgorithms.dynamicprogramming;
2+
3+
import org.junit.jupiter.api.Assertions;
4+
import org.junit.jupiter.api.Test;
5+
6+
public class KadanesAlgorithmTest {
7+
@Test
8+
public void testPositiveNumbers() {
9+
int[] arr = {1, 2, 3, 4};
10+
Assertions.assertEquals(10, KadanesAlgorithm.maxSubArraySum(arr));
11+
}
12+
13+
@Test
14+
public void testNegativeNumbers() {
15+
int[] arr = {-1, -2, -3, -4};
16+
Assertions.assertEquals(-1, KadanesAlgorithm.maxSubArraySum(arr));
17+
}
18+
19+
@Test
20+
public void testMixedNumbers() {
21+
int[] arr = {-2, 1, -3, 4, -1, 2, 1, -5, 4};
22+
Assertions.assertEquals(6, KadanesAlgorithm.maxSubArraySum(arr)); // [4, -1, 2, 1]
23+
}
24+
}

0 commit comments

Comments
 (0)