Skip to content

Commit 59d8beb

Browse files
authored
Fix CombinationSumTest to use static method calls
Removed all instances of 'new CombinationSum()' in testBasicCase, testMultipleCombinations, and testNoSolution methods. Updated all calls to use the static method CombinationSum.combinationSum() directly instead of creating an instance, as the CombinationSum class has a private constructor and is designed to be used statically.
1 parent 29e3dde commit 59d8beb

File tree

1 file changed

+3
-19
lines changed

1 file changed

+3
-19
lines changed

src/test/java/com/thealgorithms/recursion/CombinationSumTest.java

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,42 @@
11
package com.thealgorithms.recursion;
2-
32
import static org.junit.jupiter.api.Assertions.*;
4-
53
import java.util.Arrays;
64
import java.util.List;
75
import org.junit.jupiter.api.Test;
8-
96
/**
107
* Comprehensive test class for CombinationSum algorithm
118
* Tests various scenarios including edge cases
129
*/
1310
class CombinationSumTest {
14-
1511
@Test
1612
void testBasicCase() {
17-
CombinationSum cs = new CombinationSum();
1813
int[] candidates = {2, 3, 6, 7};
1914
int target = 7;
20-
List<List<Integer>> result = cs.combinationSum(candidates, target);
15+
List<List<Integer>> result = CombinationSum.combinationSum(candidates, target);
2116

2217
assertTrue(result.contains(Arrays.asList(2, 2, 3)));
2318
assertTrue(result.contains(Arrays.asList(7)));
2419
assertEquals(2, result.size());
2520
}
26-
2721
@Test
2822
void testMultipleCombinations() {
29-
CombinationSum cs = new CombinationSum();
3023
int[] candidates = {2, 3, 5};
3124
int target = 8;
32-
List<List<Integer>> result = cs.combinationSum(candidates, target);
25+
List<List<Integer>> result = CombinationSum.combinationSum(candidates, target);
3326

3427
assertTrue(result.contains(Arrays.asList(2, 2, 2, 2)));
3528
assertTrue(result.contains(Arrays.asList(2, 3, 3)));
3629
assertTrue(result.contains(Arrays.asList(3, 5)));
3730
assertEquals(3, result.size());
3831
}
39-
4032
@Test
4133
void testNoSolution() {
42-
CombinationSum cs = new CombinationSum();
4334
int[] candidates = {2};
4435
int target = 1;
45-
List<List<Integer>> result = cs.combinationSum(candidates, target);
36+
List<List<Integer>> result = CombinationSum.combinationSum(candidates, target);
4637

4738
assertTrue(result.isEmpty());
4839
}
49-
5040
@Test
5141
void testSingleElement() {
5242

@@ -57,7 +47,6 @@ void testSingleElement() {
5747
assertEquals(1, result.size());
5848
assertTrue(result.contains(Arrays.asList(1)));
5949
}
60-
6150
@Test
6251
void testSingleElementRepeated() {
6352

@@ -68,7 +57,6 @@ void testSingleElementRepeated() {
6857
assertEquals(1, result.size());
6958
assertTrue(result.contains(Arrays.asList(2, 2, 2, 2)));
7059
}
71-
7260
@Test
7361
void testLargerNumbers() {
7462

@@ -83,7 +71,6 @@ void testLargerNumbers() {
8371
assertEquals(target, sum);
8472
}
8573
}
86-
8774
@Test
8875
void testTargetZero() {
8976

@@ -95,7 +82,6 @@ void testTargetZero() {
9582
assertEquals(1, result.size());
9683
assertTrue(result.get(0).isEmpty());
9784
}
98-
9985
@Test
10086
void testEmptyCandidates() {
10187

@@ -105,7 +91,6 @@ void testEmptyCandidates() {
10591

10692
assertTrue(result.isEmpty());
10793
}
108-
10994
@Test
11095
void testLargeTarget() {
11196
int[] candidates = {3, 5, 8};
@@ -121,7 +106,6 @@ void testLargeTarget() {
121106
assertEquals(target, sum);
122107
}
123108
}
124-
125109
@Test
126110
void testAllCombinationsValid() {
127111
int[] candidates = {2, 3, 6, 7};

0 commit comments

Comments
 (0)