-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathCombinationSumIITest.java
More file actions
37 lines (30 loc) · 1.16 KB
/
CombinationSumIITest.java
File metadata and controls
37 lines (30 loc) · 1.16 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
import org.junit.Assert;
import org.junit.Test;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class CombinationSumIITest {
@Test
public void testCombinationSum2() {
CombinationSumII cs = new CombinationSumII();
// Expected: [[1, 7], [1, 2, 5], [2, 6], [1, 1, 6]]
List<List<Integer>> list0 = cs.combinationSum2(new int[]{10, 1, 2, 7, 6, 1, 5}, 8);
Set<List<Integer>> set = new HashSet<>();
set.add(Arrays.asList(1, 7));
set.add(Arrays.asList(1, 2, 5));
set.add(Arrays.asList(2, 6));
set.add(Arrays.asList(1, 1, 6));
Assert.assertTrue(list0.size() == 4);
Assert.assertEquals(new HashSet<>(list0), set);
// Expected: []
Assert.assertTrue(cs.combinationSum2(new int[]{1}, 2).isEmpty());
// Expected: [[1, 1, 2], [2, 2]]
set.clear();
List<List<Integer>> list1 = cs.combinationSum2(new int[]{1, 1, 2, 2}, 4);
set.add(Arrays.asList(1, 1, 2));
set.add(Arrays.asList(2, 2));
Assert.assertTrue(list1.size() == 2);
Assert.assertEquals(new HashSet<>(list1), set);
}
}