-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwoSumTest.java
More file actions
52 lines (41 loc) · 1.15 KB
/
TwoSumTest.java
File metadata and controls
52 lines (41 loc) · 1.15 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
43
44
45
46
47
48
49
50
51
52
package nSum;
import org.junit.Assert;
import org.junit.Test;
import java.util.ArrayList;
public class TwoSumTest {
@Test
public void testTwoSum() {
int[][] nums = new int[][]{
{},
{1,5,3,2},
{1,1,2,2,2,3,3,4},
{2,2,2,2,2,2,2,2,2,2}
};
int[][][] expect = new int[][][]{
{{}},
{{2,3}},
{{1,3},{2,2}},
{{2,2}}
};
int[] target = new int[]{
0,
5,
4,
4
};
TwoSum solution = new TwoSum();
for(int i=0;i<nums.length;i++) {
ArrayList<ArrayList<Integer>> res = solution.twoSum(nums[i], target[i]);
assertNSum(res, expect[i], 2);
}
}
private void assertNSum(ArrayList<ArrayList<Integer>>res, int[][] expect,int n) {
for(int i=0;i<res.size();i++) {
int[] temp = new int[n];
for(int j=0;j<res.get(i).size();j++) {
temp[j] = res.get(i).get(j);
}
Assert.assertArrayEquals(temp, expect[i]);
}
}
}