-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubSet_Sum_Test.java
More file actions
55 lines (41 loc) · 1.43 KB
/
SubSet_Sum_Test.java
File metadata and controls
55 lines (41 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package interviews;
import org.junit.Test;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import org.hamcrest.core.IsEqual;
import org.hamcrest.core.IsNot;
import org.junit.Assert;
public class SubSet_Sum_Test {
@Test
public void TestCombination() {
SubSet_sum_problem SubsetObj = new SubSet_sum_problem();
int SetElements[] = {1,4};
int sum =5;
int size = SetElements.length;
ArrayList<Integer> Expected = new ArrayList<Integer>();
ArrayList<Integer> Actual = new ArrayList<Integer>();
// here sum 5 has a combination of
Expected.add(4);
Expected.add(1);
Actual = SubsetObj.Subsets(SetElements, size, sum);
assertArrayEquals(Actual.toArray(), Expected.toArray());
}
@Test
public void TestCombinationNegative() {
SubSet_sum_problem SubsetObj = new SubSet_sum_problem();
int SetElements[] = {1,4};
int sum =5;
int size = SetElements.length;
ArrayList<Integer> ExpectedWrongAns = new ArrayList<Integer>();
ArrayList<Integer> Actual = new ArrayList<Integer>();
// here sum 5 has a combination of
ExpectedWrongAns.add(4);
ExpectedWrongAns.add(7);
Actual = SubsetObj.Subsets(SetElements, size, sum);
Assert.assertThat(Actual.toArray(), IsNot.not(IsEqual.equalTo(ExpectedWrongAns.toArray())));
}
}