|
1 | 1 | packagecom.fishercoder; |
2 | 2 |
|
3 | 3 | importcom.fishercoder.solutions._40; |
4 | | -importjava.util.ArrayList; |
| 4 | + |
5 | 5 | importjava.util.Arrays; |
6 | 6 | importjava.util.List; |
| 7 | + |
7 | 8 | importorg.junit.BeforeClass; |
8 | 9 | importorg.junit.Test; |
9 | 10 |
|
10 | 11 | importstaticorg.junit.Assert.assertEquals; |
11 | 12 |
|
12 | 13 | publicclass_40Test { |
13 | | -privatestatic_40.Solution1solution1; |
14 | | -privatestaticint[]candidates; |
15 | | -privatestaticList<List<Integer>>expected; |
16 | | - |
17 | | -@BeforeClass |
18 | | -publicstaticvoidsetup() { |
19 | | -solution1 =new_40.Solution1(); |
20 | | - } |
21 | | - |
22 | | -@Test |
23 | | -publicvoidtest1() { |
24 | | -candidates =newint[] {10,1,2,7,6,1,5}; |
25 | | -expected =newArrayList<>(); |
26 | | -expected.add(Arrays.asList(1,1,6)); |
27 | | -expected.add(Arrays.asList(1,2,5)); |
28 | | -expected.add(Arrays.asList(1,7)); |
29 | | -expected.add(Arrays.asList(2,6)); |
30 | | -assertEquals(expected,solution1.combinationSum2(candidates,8)); |
31 | | - } |
| 14 | +privatestatic_40.Solution1solution1; |
| 15 | +privatestaticint[]candidates; |
| 16 | +privatestaticinttarget; |
| 17 | +privatestaticList<List<Integer>>expected; |
| 18 | + |
| 19 | +@BeforeClass |
| 20 | +publicstaticvoidsetup() { |
| 21 | +solution1 =new_40.Solution1(); |
| 22 | + } |
| 23 | + |
| 24 | +@Test |
| 25 | +publicvoidtest1() { |
| 26 | +candidates =newint[]{10,1,2,7,6,1,5}; |
| 27 | +expected =Arrays.asList((Arrays.asList(1,1,6)),Arrays.asList(1,2,5),Arrays.asList(1,7),Arrays.asList(2,6)); |
| 28 | +target =8; |
| 29 | +assertEquals(expected,solution1.combinationSum2(candidates,target)); |
| 30 | + } |
| 31 | + |
| 32 | +@Test |
| 33 | +publicvoidtest2() { |
| 34 | +candidates =newint[]{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}; |
| 35 | +expected =Arrays.asList(Arrays.asList(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1)); |
| 36 | +target =30; |
| 37 | +assertEquals(expected,solution1.combinationSum2(candidates,target)); |
| 38 | + } |
32 | 39 | } |