Skip to content

Commit 29e3dde

Browse files
authored
Refactor CombinationSumTest to use static method
1 parent d0fd391 commit 29e3dde

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

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

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,32 +49,32 @@ void testNoSolution() {
4949

5050
@Test
5151
void testSingleElement() {
52-
CombinationSum cs = new CombinationSum();
52+
5353
int[] candidates = {1};
5454
int target = 1;
55-
List<List<Integer>> result = cs.combinationSum(candidates, target);
55+
List<List<Integer>> result = CombinationSum.combinationSum(candidates, target);
5656

5757
assertEquals(1, result.size());
5858
assertTrue(result.contains(Arrays.asList(1)));
5959
}
6060

6161
@Test
6262
void testSingleElementRepeated() {
63-
CombinationSum cs = new CombinationSum();
63+
6464
int[] candidates = {2};
6565
int target = 8;
66-
List<List<Integer>> result = cs.combinationSum(candidates, target);
66+
List<List<Integer>> result = CombinationSum.combinationSum(candidates, target);
6767

6868
assertEquals(1, result.size());
6969
assertTrue(result.contains(Arrays.asList(2, 2, 2, 2)));
7070
}
7171

7272
@Test
7373
void testLargerNumbers() {
74-
CombinationSum cs = new CombinationSum();
74+
7575
int[] candidates = {10, 1, 2, 7, 6, 1, 5};
7676
int target = 8;
77-
List<List<Integer>> result = cs.combinationSum(candidates, target);
77+
List<List<Integer>> result = CombinationSum.combinationSum(candidates, target);
7878

7979
assertFalse(result.isEmpty());
8080
// Verify all combinations sum to target
@@ -86,10 +86,10 @@ void testLargerNumbers() {
8686

8787
@Test
8888
void testTargetZero() {
89-
CombinationSum cs = new CombinationSum();
89+
9090
int[] candidates = {1, 2, 3};
9191
int target = 0;
92-
List<List<Integer>> result = cs.combinationSum(candidates, target);
92+
List<List<Integer>> result = CombinationSum.combinationSum(candidates, target);
9393

9494
// Should return empty list in the combination
9595
assertEquals(1, result.size());
@@ -98,20 +98,19 @@ void testTargetZero() {
9898

9999
@Test
100100
void testEmptyCandidates() {
101-
CombinationSum cs = new CombinationSum();
101+
102102
int[] candidates = {};
103103
int target = 5;
104-
List<List<Integer>> result = cs.combinationSum(candidates, target);
104+
List<List<Integer>> result = CombinationSum.combinationSum(candidates, target);
105105

106106
assertTrue(result.isEmpty());
107107
}
108108

109109
@Test
110110
void testLargeTarget() {
111-
CombinationSum cs = new CombinationSum();
112111
int[] candidates = {3, 5, 8};
113112
int target = 11;
114-
List<List<Integer>> result = cs.combinationSum(candidates, target);
113+
List<List<Integer>> result = CombinationSum.combinationSum(candidates, target);
115114

116115
assertTrue(result.contains(Arrays.asList(3, 3, 5)));
117116
assertTrue(result.contains(Arrays.asList(3, 8)));
@@ -125,10 +124,9 @@ void testLargeTarget() {
125124

126125
@Test
127126
void testAllCombinationsValid() {
128-
CombinationSum cs = new CombinationSum();
129127
int[] candidates = {2, 3, 6, 7};
130128
int target = 7;
131-
List<List<Integer>> result = cs.combinationSum(candidates, target);
129+
List<List<Integer>> result = CombinationSum.combinationSum(candidates, target);
132130

133131
// Verify each combination sums to target
134132
for (List<Integer> combination : result) {

0 commit comments

Comments
 (0)