-
Notifications
You must be signed in to change notification settings - Fork 19.4k
/
KadaneAlogrithmTest.java
57 lines (46 loc) · 1.29 KB
/
KadaneAlogrithmTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.thealgorithms.others;
import static org.junit.jupiter.api.Assertions.assertTrue;
import com.thealgorithms.dynamicprogramming.KadaneAlgorithm;
import org.junit.jupiter.api.Test;
public class KadaneAlogrithmTest {
@Test
void testForOneElement() {
int[] a = {-1};
assertTrue(KadaneAlgorithm.maxSum(a, -1));
}
@Test
void testForTwoElements() {
int[] a = {-2, 1};
assertTrue(KadaneAlgorithm.maxSum(a, 1));
}
@Test
void testForThreeElements() {
int[] a = {5, 3, 12};
assertTrue(KadaneAlgorithm.maxSum(a, 20));
}
@Test
void testForFourElements() {
int[] a = {-1, -3, -7, -4};
assertTrue(KadaneAlgorithm.maxSum(a, -1));
}
@Test
void testForFiveElements() {
int[] a = {4, 5, 3, 0, 2};
assertTrue(KadaneAlgorithm.maxSum(a, 14));
}
@Test
void testForSixElements() {
int[] a = {-43, -45, 47, 12, 87, -13};
assertTrue(KadaneAlgorithm.maxSum(a, 146));
}
@Test
void testForSevenElements() {
int[] a = {9, 8, 2, 23, 13, 6, 7};
assertTrue(KadaneAlgorithm.maxSum(a, 68));
}
@Test
void testForEightElements() {
int[] a = {9, -5, -5, -2, 4, 5, 0, 1};
assertTrue(KadaneAlgorithm.maxSum(a, 10));
}
}