Skip to content

Commit 55f08cc

Browse files
bhishma620vil02
andauthored
Add tests SumOfSubset (TheAlgorithms#5021)
* Updated main and test * removed * style: reorder test cases --------- Co-authored-by: Piotr Idzik <[email protected]>
1 parent a216cb8 commit 55f08cc

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

src/main/java/com/thealgorithms/dynamicprogramming/Sum_Of_Subset.java renamed to src/main/java/com/thealgorithms/dynamicprogramming/SumOfSubset.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
package com.thealgorithms.dynamicprogramming;
22

3-
public class Sum_Of_Subset {
4-
5-
public static void main(String[] args) {
6-
int[] arr = {7, 3, 2, 5, 8};
7-
int Key = 14;
8-
9-
if (subsetSum(arr, arr.length - 1, Key)) {
10-
System.out.print("Yes, that sum exists");
11-
} else {
12-
System.out.print("Nope, that number does not exist");
13-
}
14-
}
3+
public class SumOfSubset {
154

165
public static boolean subsetSum(int[] arr, int num, int Key) {
176
if (Key == 0) {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.thealgorithms.dynamicprogramming;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
class SumOfSubsetTest {
8+
9+
@Test
10+
void basicCheck() {
11+
assertEquals(false, SumOfSubset.subsetSum(new int[] {1, 2, 7, 10, 9}, 4, 14));
12+
assertEquals(false, SumOfSubset.subsetSum(new int[] {2, 15, 1, 6, 7}, 4, 4));
13+
assertEquals(true, SumOfSubset.subsetSum(new int[] {7, 3, 2, 5, 8}, 4, 14));
14+
assertEquals(true, SumOfSubset.subsetSum(new int[] {4, 3, 2, 1}, 3, 5));
15+
assertEquals(true, SumOfSubset.subsetSum(new int[] {1, 7, 2, 9, 10}, 4, 13));
16+
}
17+
}

0 commit comments

Comments
 (0)