Skip to content

Commit 5e07e78

Browse files
committed
refactor test structure for MaximumSumOfNonAdjacentElements
1 parent 681e9e4 commit 5e07e78

File tree

1 file changed

+33
-10
lines changed

1 file changed

+33
-10
lines changed

src/test/java/com/thealgorithms/dynamicprogramming/MaximumSumOfNonAdjacentElementsTest.java

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,48 @@
66

77
public class MaximumSumOfNonAdjacentElementsTest {
88

9+
// Tests for Approach1
910
@Test
10-
public void testGetMaxSumApproach1() {
11-
// Test with various cases
12-
assertEquals(15, MaximumSumOfNonAdjacentElements.getMaxSumApproach1(new int[] {3, 2, 5, 10, 7})); // 3 + 7 + 5
13-
assertEquals(10, MaximumSumOfNonAdjacentElements.getMaxSumApproach1(new int[] {5, 1, 1, 5})); // 5 + 5
11+
public void testGetMaxSumApproach1_WithEmptyArray() {
1412
assertEquals(0, MaximumSumOfNonAdjacentElements.getMaxSumApproach1(new int[] {})); // Empty array
13+
}
14+
15+
@Test
16+
public void testGetMaxSumApproach1_WithSingleElement() {
1517
assertEquals(1, MaximumSumOfNonAdjacentElements.getMaxSumApproach1(new int[] {1})); // Single element
18+
}
19+
20+
@Test
21+
public void testGetMaxSumApproach1_WithTwoElements_TakeMax() {
1622
assertEquals(2, MaximumSumOfNonAdjacentElements.getMaxSumApproach1(new int[] {1, 2})); // Take max of both
17-
assertEquals(3, MaximumSumOfNonAdjacentElements.getMaxSumApproach1(new int[] {3, 2})); // Take 3
1823
}
1924

2025
@Test
21-
public void testGetMaxSumApproach2() {
22-
// Test with various cases
23-
assertEquals(15, MaximumSumOfNonAdjacentElements.getMaxSumApproach2(new int[] {3, 2, 5, 10, 7})); // 3 + 7 + 5
24-
assertEquals(10, MaximumSumOfNonAdjacentElements.getMaxSumApproach2(new int[] {5, 1, 1, 5})); // 5 + 5
26+
public void testGetMaxSumApproach1_WithMultipleElements() {
27+
assertEquals(15, MaximumSumOfNonAdjacentElements.getMaxSumApproach1(new int[] {3, 2, 5, 10, 7})); // 3 + 7 + 5
28+
assertEquals(10, MaximumSumOfNonAdjacentElements.getMaxSumApproach1(new int[] {5, 1, 1, 5})); // 5 + 5
29+
}
30+
31+
// Tests for Approach2
32+
@Test
33+
public void testGetMaxSumApproach2_WithEmptyArray() {
2534
assertEquals(0, MaximumSumOfNonAdjacentElements.getMaxSumApproach2(new int[] {})); // Empty array
35+
}
36+
37+
@Test
38+
public void testGetMaxSumApproach2_WithSingleElement() {
2639
assertEquals(1, MaximumSumOfNonAdjacentElements.getMaxSumApproach2(new int[] {1})); // Single element
40+
}
41+
42+
@Test
43+
public void testGetMaxSumApproach2_WithTwoElements_TakeMax() {
2744
assertEquals(2, MaximumSumOfNonAdjacentElements.getMaxSumApproach2(new int[] {1, 2})); // Take max of both
28-
assertEquals(3, MaximumSumOfNonAdjacentElements.getMaxSumApproach2(new int[] {3, 2})); // Take 3
2945
}
46+
47+
@Test
48+
public void testGetMaxSumApproach2_WithMultipleElements() {
49+
assertEquals(15, MaximumSumOfNonAdjacentElements.getMaxSumApproach2(new int[] {3, 2, 5, 10, 7})); // 3 + 7 + 5
50+
assertEquals(10, MaximumSumOfNonAdjacentElements.getMaxSumApproach2(new int[] {5, 1, 1, 5})); // 5 + 5
51+
}
52+
3053
}

0 commit comments

Comments
 (0)