1+ import org .junit .Assert ;
2+ import org .junit .Test ;
3+
4+ import java .util .Arrays ;
5+ import java .util .HashSet ;
6+ import java .util .List ;
7+ import java .util .Set ;
8+
9+ public class CombinationSumIITest {
10+
11+ @ Test
12+ public void testCombinationSum2 () {
13+ CombinationSumII cs = new CombinationSumII ();
14+
15+ // Expected: [[1, 7], [1, 2, 5], [2, 6], [1, 1, 6]]
16+ List <List <Integer >> list0 = cs .combinationSum2 (new int []{10 , 1 , 2 , 7 , 6 , 1 , 5 }, 8 );
17+ Set <List <Integer >> set = new HashSet <>();
18+ set .add (Arrays .asList (1 , 7 ));
19+ set .add (Arrays .asList (1 , 2 , 5 ));
20+ set .add (Arrays .asList (2 , 6 ));
21+ set .add (Arrays .asList (1 , 1 , 6 ));
22+ Assert .assertTrue (list0 .size () == 4 );
23+ Assert .assertEquals (new HashSet <>(list0 ), set );
24+
25+ // Expected: []
26+ Assert .assertTrue (cs .combinationSum2 (new int []{1 }, 2 ).isEmpty ());
27+
28+ // Expected: [[1, 1, 2], [2, 2]]
29+ set .clear ();
30+ List <List <Integer >> list1 = cs .combinationSum2 (new int []{1 , 1 , 2 , 2 }, 4 );
31+ set .add (Arrays .asList (1 , 1 , 2 ));
32+ set .add (Arrays .asList (2 , 2 ));
33+ Assert .assertTrue (list1 .size () == 2 );
34+ Assert .assertEquals (new HashSet <>(list1 ), set );
35+ }
36+
37+ }
0 commit comments