Skip to content

Commit aa4f714

Browse files
committed
update main and test
1 parent a216cb8 commit aa4f714

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,6 @@
22

33
public class Sum_Of_Subset {
44

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-
}
15-
165
public static boolean subsetSum(int[] arr, int num, int Key) {
176
if (Key == 0) {
187
return true;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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(true, SumOfSubset.subsetSum(new int[] {7, 3, 2, 5, 8}, 4, 14));
12+
13+
assertEquals(true, SumOfSubset.subsetSum(new int[] {4, 3, 2, 1}, 3, 5));
14+
15+
assertEquals(false, SumOfSubset.subsetSum(new int[] {1, 2, 7, 10, 9}, 4, 14));
16+
17+
assertEquals(false, SumOfSubset.subsetSum(new int[] {2, 15, 1, 6, 7}, 4, 4));
18+
19+
assertEquals(true, SumOfSubset.subsetSum(new int[] {1, 7, 2, 9, 10}, 4, 13));
20+
}
21+
}

0 commit comments

Comments
 (0)