forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_163Test.java
106 lines (91 loc) · 2.83 KB
/
_163Test.java
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package com.fishercoder;
import com.fishercoder.solutions._163;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import static junit.framework.Assert.assertEquals;
/**
* Created by fishercoder on 12/31/16.
*/
public class _163Test {
private static _163 test;
private static List<String> expected;
private static List<String> actual;
private static int lower;
private static int upper;
private static int[] nums;
@BeforeClass
public static void setup(){
test = new _163();
expected = new ArrayList();
actual = new ArrayList();
}
@Before
public void setupForEachTest(){
expected.clear();
actual.clear();
}
@Test
public void test1(){
//test case 1: should return ["0->2147483646"]
lower = 0;
upper = 2147483647;
nums = new int[]{2147483647};
expected.add("0->2147483646");
actual = test.findMissingRanges(nums, lower, upper);
assertEquals(expected, actual);
}
@Test
public void test2(){
//test case 2: should return ["-2147483647->-1","1->2147483646"]
lower = -2147483648;
upper = 2147483647;
nums = new int[]{-2147483648,-2147483648,0,2147483647,2147483647};
expected.add("-2147483647->-1");
expected.add("1->2147483646");
actual = test.findMissingRanges(nums, lower, upper);
assertEquals(expected, actual);
}
@Test
public void test3(){
//test case 3: should return ["-2147483648->2147483647"]
lower = -2147483648;
upper = 2147483647;
nums = new int[]{};
expected.add("-2147483648->2147483647");
actual = test.findMissingRanges(nums, lower, upper);
assertEquals(expected, actual);
}
@Test
public void test4(){
//test case 4: should return ["-2147483648->2147483646"]
lower = -2147483648;
upper = 2147483647;
nums = new int[]{2147483647};
expected.add("-2147483648->2147483646");
actual = test.findMissingRanges(nums, lower, upper);
assertEquals(expected, actual);
}
@Test
public void test5(){
//test case 5: should return ["0->2147483647"]
lower = 0;
upper = 2147483647;
nums = new int[]{};
expected.add("0->2147483647");
actual = test.findMissingRanges(nums, lower, upper);
assertEquals(expected, actual);
}
@Test
public void test6(){
//test case 6: should return ["-2147483647->2147483647"]
lower = -2147483648;
upper = 2147483647;
nums = new int[]{-2147483648};
expected.add("-2147483647->2147483647");
actual = test.findMissingRanges(nums, lower, upper);
assertEquals(expected, actual);
}
}