|
10 | 10 |
|
11 | 11 | importstaticjunit.framework.Assert.assertEquals;
|
12 | 12 |
|
13 |
| -/** |
14 |
| - * Created by fishercoder on 12/31/16. |
15 |
| - */ |
16 | 13 | publicclass_163Test {
|
17 | 14 |
|
18 |
| -privatestatic_163test; |
19 |
| -privatestaticList<String>expected; |
20 |
| -privatestaticList<String>actual; |
21 |
| -privatestaticintlower; |
22 |
| -privatestaticintupper; |
23 |
| -privatestaticint[]nums; |
| 15 | +privatestatic_163.Solution1solution1; |
| 16 | +privatestaticList<String>expected; |
| 17 | +privatestaticList<String>actual; |
| 18 | +privatestaticint[]nums; |
24 | 19 |
|
25 |
| -@BeforeClass |
26 |
| -publicstaticvoidsetup() { |
27 |
| -test=new_163(); |
28 |
| -expected =newArrayList(); |
29 |
| -actual =newArrayList(); |
30 |
| -} |
| 20 | +@BeforeClass |
| 21 | +publicstaticvoidsetup() { |
| 22 | +solution1=new_163.Solution1(); |
| 23 | +expected =newArrayList(); |
| 24 | +actual =newArrayList(); |
| 25 | + } |
31 | 26 |
|
32 |
| -@Before |
33 |
| -publicvoidsetupForEachTest() { |
34 |
| -expected.clear(); |
35 |
| -actual.clear(); |
36 |
| -} |
| 27 | +@Before |
| 28 | +publicvoidsetupForEachTest() { |
| 29 | +expected.clear(); |
| 30 | +actual.clear(); |
| 31 | + } |
37 | 32 |
|
38 |
| -@Test |
39 |
| -publicvoidtest1() { |
| 33 | +@Test |
| 34 | +publicvoidtest1() { |
| 35 | +//solution1 case 1: should return ["0->2147483646"] |
| 36 | +nums =newint[] {2147483647}; |
| 37 | +expected.add("0->2147483646"); |
| 38 | +actual =solution1.findMissingRanges(nums,0,2147483647); |
| 39 | +assertEquals(expected,actual); |
| 40 | + } |
40 | 41 |
|
41 |
| -//test case 1: should return ["0->2147483646"] |
42 |
| -lower =0; |
43 |
| -upper =2147483647; |
44 |
| -nums =newint[]{2147483647}; |
45 |
| -expected.add("0->2147483646"); |
46 |
| -actual =test.findMissingRanges(nums,lower,upper); |
47 |
| -assertEquals(expected,actual); |
| 42 | +@Test |
| 43 | +publicvoidtest2() { |
| 44 | +//solution1 case 2: should return ["-2147483647->-1","1->2147483646"] |
| 45 | +nums =newint[] {-2147483648, -2147483648,0,2147483647,2147483647}; |
| 46 | +expected.add("-2147483647->-1"); |
| 47 | +expected.add("1->2147483646"); |
| 48 | +actual =solution1.findMissingRanges(nums, -2147483648,2147483647); |
| 49 | +assertEquals(expected,actual); |
| 50 | + } |
48 | 51 |
|
49 |
| - } |
| 52 | +@Test |
| 53 | +publicvoidtest3() { |
| 54 | +//solution1 case 3: should return ["-2147483648->2147483647"] |
| 55 | +nums =newint[] {}; |
| 56 | +expected.add("-2147483648->2147483647"); |
| 57 | +actual =solution1.findMissingRanges(nums, -2147483648,2147483647); |
| 58 | +assertEquals(expected,actual); |
| 59 | + } |
50 | 60 |
|
51 |
| -@Test |
52 |
| -publicvoidtest2() { |
53 |
| -//test case 2: should return ["-2147483647->-1","1->2147483646"] |
54 |
| -lower = -2147483648; |
55 |
| -upper =2147483647; |
56 |
| -nums =newint[]{-2147483648, -2147483648,0,2147483647,2147483647}; |
57 |
| -expected.add("-2147483647->-1"); |
58 |
| -expected.add("1->2147483646"); |
59 |
| -actual =test.findMissingRanges(nums,lower,upper); |
60 |
| -assertEquals(expected,actual); |
61 |
| - } |
| 61 | +@Test |
| 62 | +publicvoidtest4() { |
| 63 | +//solution1 case 4: should return ["-2147483648->2147483646"] |
| 64 | +nums =newint[] {2147483647}; |
| 65 | +expected.add("-2147483648->2147483646"); |
| 66 | +actual =solution1.findMissingRanges(nums, -2147483648,2147483647); |
| 67 | +assertEquals(expected,actual); |
| 68 | + } |
62 | 69 |
|
63 |
| -@Test |
64 |
| -publicvoidtest3() { |
65 |
| -//test case 3: should return ["-2147483648->2147483647"] |
66 |
| -lower = -2147483648; |
67 |
| -upper =2147483647; |
68 |
| -nums =newint[]{}; |
69 |
| -expected.add("-2147483648->2147483647"); |
70 |
| -actual =test.findMissingRanges(nums,lower,upper); |
71 |
| -assertEquals(expected,actual); |
72 |
| - } |
| 70 | +@Test |
| 71 | +publicvoidtest5() { |
| 72 | +//solution1 case 5: should return ["0->2147483647"] |
| 73 | +nums =newint[] {}; |
| 74 | +expected.add("0->2147483647"); |
| 75 | +actual =solution1.findMissingRanges(nums,0,2147483647); |
| 76 | +assertEquals(expected,actual); |
| 77 | + } |
73 | 78 |
|
74 |
| -@Test |
75 |
| -publicvoidtest4() { |
76 |
| -//test case 4: should return ["-2147483648->2147483646"] |
77 |
| -lower = -2147483648; |
78 |
| -upper =2147483647; |
79 |
| -nums =newint[]{2147483647}; |
80 |
| -expected.add("-2147483648->2147483646"); |
81 |
| -actual =test.findMissingRanges(nums,lower,upper); |
82 |
| -assertEquals(expected,actual); |
83 |
| - } |
84 |
| - |
85 |
| -@Test |
86 |
| -publicvoidtest5() { |
87 |
| -//test case 5: should return ["0->2147483647"] |
88 |
| -lower =0; |
89 |
| -upper =2147483647; |
90 |
| -nums =newint[]{}; |
91 |
| -expected.add("0->2147483647"); |
92 |
| -actual =test.findMissingRanges(nums,lower,upper); |
93 |
| -assertEquals(expected,actual); |
94 |
| - } |
95 |
| - |
96 |
| -@Test |
97 |
| -publicvoidtest6() { |
98 |
| -//test case 6: should return ["-2147483647->2147483647"] |
99 |
| -lower = -2147483648; |
100 |
| -upper =2147483647; |
101 |
| -nums =newint[]{-2147483648}; |
102 |
| -expected.add("-2147483647->2147483647"); |
103 |
| -actual =test.findMissingRanges(nums,lower,upper); |
104 |
| -assertEquals(expected,actual); |
105 |
| - } |
| 79 | +@Test |
| 80 | +publicvoidtest6() { |
| 81 | +//solution1 case 6: should return ["-2147483647->2147483647"] |
| 82 | +nums =newint[] {-2147483648}; |
| 83 | +expected.add("-2147483647->2147483647"); |
| 84 | +actual =solution1.findMissingRanges(nums, -2147483648,2147483647); |
| 85 | +assertEquals(expected,actual); |
| 86 | + } |
106 | 87 | }
|