-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathCombinationsTest.java
More file actions
42 lines (34 loc) · 1.27 KB
/
CombinationsTest.java
File metadata and controls
42 lines (34 loc) · 1.27 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
import org.junit.Assert;
import org.junit.Test;
import java.util.*;
public class CombinationsTest {
@Test
public void testCombine() {
Combinations c = new Combinations();
Assert.assertTrue(c.combine(2, 0).isEmpty());
List<List<Integer>> list0 = c.combine(2, 1);
Set<List<Integer>> tmp = new HashSet<>();
tmp.add(Collections.singletonList(1));
tmp.add(Collections.singletonList(2));
Assert.assertTrue(list0.size() == 2);
Assert.assertEquals(new HashSet<>(list0), tmp);
tmp.clear();
List<List<Integer>> list1 = c.combine(4, 2);
tmp.add(Arrays.asList(2, 4));
tmp.add(Arrays.asList(3, 4));
tmp.add(Arrays.asList(2, 3));
tmp.add(Arrays.asList(1, 2));
tmp.add(Arrays.asList(1, 3));
tmp.add(Arrays.asList(1, 4));
Assert.assertTrue(list1.size() == 6);
Assert.assertEquals(new HashSet<>(list1), tmp);
tmp.clear();
List<List<Integer>> list2 = c.combine(4, 3);
tmp.add(Arrays.asList(1, 2, 3));
tmp.add(Arrays.asList(1, 2, 4));
tmp.add(Arrays.asList(1, 3, 4));
tmp.add(Arrays.asList(2, 3, 4));
Assert.assertTrue(list2.size() == 4);
Assert.assertEquals(new HashSet<>(list2), tmp);
}
}