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:
Bhishmadev Ghosh 2024-01-27 00:00:26 +05:30 committed by GitHub
parent a216cb8a59
commit 55f08cc013
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 12 deletions

View File

@ -1,17 +1,6 @@
package com.thealgorithms.dynamicprogramming;
public class Sum_Of_Subset {
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 class SumOfSubset {
public static boolean subsetSum(int[] arr, int num, int Key) {
if (Key == 0) {

View File

@ -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));
}
}