Add tests SumOfSubset
(#5021)
* Updated main and test * removed * style: reorder test cases --------- Co-authored-by: Piotr Idzik <65706193+vil02@users.noreply.github.com>
This commit is contained in:
parent
a216cb8a59
commit
55f08cc013
@ -1,17 +1,6 @@
|
|||||||
package com.thealgorithms.dynamicprogramming;
|
package com.thealgorithms.dynamicprogramming;
|
||||||
|
|
||||||
public class Sum_Of_Subset {
|
public class SumOfSubset {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
int[] arr = {7, 3, 2, 5, 8};
|
|
||||||
int Key = 14;
|
|
||||||
|
|
||||||
if (subsetSum(arr, arr.length - 1, Key)) {
|
|
||||||
System.out.print("Yes, that sum exists");
|
|
||||||
} else {
|
|
||||||
System.out.print("Nope, that number does not exist");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean subsetSum(int[] arr, int num, int Key) {
|
public static boolean subsetSum(int[] arr, int num, int Key) {
|
||||||
if (Key == 0) {
|
if (Key == 0) {
|
@ -0,0 +1,17 @@
|
|||||||
|
package com.thealgorithms.dynamicprogramming;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
class SumOfSubsetTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void basicCheck() {
|
||||||
|
assertEquals(false, SumOfSubset.subsetSum(new int[] {1, 2, 7, 10, 9}, 4, 14));
|
||||||
|
assertEquals(false, SumOfSubset.subsetSum(new int[] {2, 15, 1, 6, 7}, 4, 4));
|
||||||
|
assertEquals(true, SumOfSubset.subsetSum(new int[] {7, 3, 2, 5, 8}, 4, 14));
|
||||||
|
assertEquals(true, SumOfSubset.subsetSum(new int[] {4, 3, 2, 1}, 3, 5));
|
||||||
|
assertEquals(true, SumOfSubset.subsetSum(new int[] {1, 7, 2, 9, 10}, 4, 13));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user