Skip to content

Commit a9e1b84

Browse files
committed
Simplified unit tests.
1 parent b3e0e31 commit a9e1b84

File tree

10 files changed

+24
-84
lines changed

10 files changed

+24
-84
lines changed

src/test/java/g0001_0100/s0040_combination_sum_ii/SolutionTest.java

+5-28
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,15 @@
33
import static org.hamcrest.CoreMatchers.equalTo;
44
import static org.hamcrest.MatcherAssert.assertThat;
55

6-
import java.util.ArrayList;
7-
import java.util.Arrays;
8-
import java.util.List;
6+
import com_github_leetcode.ArrayUtils;
97
import org.junit.Test;
108

119
public class SolutionTest {
1210
@Test
1311
public void combinationSum2() {
14-
List<List<Integer>> expected = new ArrayList<>();
15-
16-
List<Integer> sub1 = new ArrayList<>();
17-
sub1.addAll(Arrays.asList(1, 1, 6));
18-
19-
List<Integer> sub2 = new ArrayList<>();
20-
sub2.addAll(Arrays.asList(1, 2, 5));
21-
22-
List<Integer> sub3 = new ArrayList<>();
23-
sub3.addAll(Arrays.asList(1, 7));
24-
25-
List<Integer> sub4 = new ArrayList<>();
26-
sub4.addAll(Arrays.asList(2, 6));
27-
28-
expected.add(sub1);
29-
expected.add(sub2);
30-
expected.add(sub3);
31-
expected.add(sub4);
32-
33-
List<List<Integer>> actual =
34-
new Solution().combinationSum2(new int[] {10, 1, 2, 7, 6, 1, 5}, 8);
35-
36-
for (int i = 0; i < expected.size(); i++) {
37-
assertThat(actual.get(i).toArray(), equalTo(expected.get(i).toArray()));
38-
}
12+
int[][] expected = {{1, 1, 6}, {1, 2, 5}, {1, 7}, {2, 6}};
13+
assertThat(
14+
new Solution().combinationSum2(new int[] {10, 1, 2, 7, 6, 1, 5}, 8),
15+
equalTo(ArrayUtils.getLists(expected)));
3916
}
4017
}

src/test/java/g0001_0100/s0046_permutations/SolutionTest.java

+6-19
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,15 @@
33
import static org.hamcrest.CoreMatchers.equalTo;
44
import static org.hamcrest.MatcherAssert.assertThat;
55

6-
import java.util.ArrayList;
7-
import java.util.Arrays;
8-
import java.util.List;
6+
import com_github_leetcode.ArrayUtils;
97
import org.junit.Test;
108

119
public class SolutionTest {
1210
@Test
13-
public void permutations() {
14-
List<List<Integer>> expected = new ArrayList<>();
15-
expected.add(Arrays.asList(1, 2, 3));
16-
expected.add(Arrays.asList(1, 3, 2));
17-
expected.add(Arrays.asList(2, 1, 3));
18-
expected.add(Arrays.asList(2, 3, 1));
19-
expected.add(Arrays.asList(3, 1, 2));
20-
expected.add(Arrays.asList(3, 2, 1));
21-
22-
List<List<Integer>> actual = new Solution().permute(new int[] {1, 2, 3});
23-
24-
for (int i = 0; i < expected.size(); i++) {
25-
assertThat(
26-
Arrays.toString(actual.get(i).toArray()),
27-
equalTo(Arrays.toString(expected.get(i).toArray())));
28-
}
11+
public void permute() {
12+
int[][] expected = {{1, 2, 3}, {1, 3, 2}, {2, 1, 3}, {2, 3, 1}, {3, 1, 2}, {3, 2, 1}};
13+
assertThat(
14+
new Solution().permute(new int[] {1, 2, 3}),
15+
equalTo(ArrayUtils.getLists(expected)));
2916
}
3017
}

src/test/java/g0001_0100/s0047_permutations_ii/SolutionTest.java

+5-15
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,15 @@
33
import static org.hamcrest.CoreMatchers.equalTo;
44
import static org.hamcrest.MatcherAssert.assertThat;
55

6-
import java.util.ArrayList;
7-
import java.util.Arrays;
8-
import java.util.List;
6+
import com_github_leetcode.ArrayUtils;
97
import org.junit.Test;
108

119
public class SolutionTest {
1210
@Test
1311
public void permuteUnique() {
14-
List<List<Integer>> expected = new ArrayList<>();
15-
expected.add(Arrays.asList(1, 1, 2));
16-
expected.add(Arrays.asList(1, 2, 1));
17-
expected.add(Arrays.asList(2, 1, 1));
18-
19-
List<List<Integer>> actual = new Solution().permuteUnique(new int[] {1, 1, 2});
20-
21-
for (int i = 0; i < expected.size(); i++) {
22-
assertThat(
23-
Arrays.toString(actual.get(i).toArray()),
24-
equalTo(Arrays.toString(expected.get(i).toArray())));
25-
}
12+
int[][] expected = {{1, 1, 2}, {1, 2, 1}, {2, 1, 1}};
13+
assertThat(
14+
new Solution().permuteUnique(new int[] {1, 1, 2}),
15+
equalTo(ArrayUtils.getLists(expected)));
2616
}
2717
}

src/test/java/g0001_0100/s0048_rotate_image/SolutionTest.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,16 @@
33
import static org.hamcrest.CoreMatchers.equalTo;
44
import static org.hamcrest.MatcherAssert.assertThat;
55

6-
import java.util.Arrays;
76
import org.junit.Test;
87

98
public class SolutionTest {
109
@Test
11-
public void rotateImage() {
10+
public void rotate() {
1211
int[][] expected = new int[][] {{7, 4, 1}, {8, 5, 2}, {9, 6, 3}};
1312
int[][] input = new int[][] {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
1413

1514
new Solution().rotate(input);
1615

17-
for (int i = 0; i < expected.length; i++) {
18-
assertThat(Arrays.toString(input[i]), equalTo(Arrays.toString(expected[i])));
19-
}
16+
assertThat(input, equalTo(expected));
2017
}
2118
}

src/test/java/g0001_0100/s0056_merge_intervals/SolutionTest.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ public void mergeIntervals() {
1212
int[][] expected = {{1, 6}, {8, 10}, {15, 18}};
1313
int[][] actual = new Solution().merge(input);
1414

15-
for (int i = 0; i < expected.length; i++) {
16-
assertThat(actual[i], equalTo(expected[i]));
17-
}
15+
assertThat(actual, equalTo(expected));
1816
}
1917
}

src/test/java/g0001_0100/s0057_insert_interval/SolutionTest.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ public void insertInterval() {
1111
int[][] expected = {{1, 5}, {6, 9}};
1212
int[][] actual = new Solution().insert(new int[][] {{1, 3}, {6, 9}}, new int[] {2, 5});
1313

14-
for (int i = 0; i < actual.length; i++) {
15-
assertThat(actual[i], equalTo(expected[i]));
16-
}
14+
assertThat(actual, equalTo(expected));
1715
}
1816
}

src/test/java/g0001_0100/s0059_spiral_matrix_ii/SolutionTest.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ public class SolutionTest {
1010
public void generateMatrix() {
1111
int[][] actual = new Solution().generateMatrix(3);
1212
int[][] expected = {{1, 2, 3}, {8, 9, 4}, {7, 6, 5}};
13-
for (int i = 0; i < expected.length; i++) {
14-
assertThat(actual[i], equalTo(expected[i]));
15-
}
13+
assertThat(actual, equalTo(expected));
1614
}
1715
}

src/test/java/g0001_0100/s0063_unique_paths_ii/SolutionTest.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ public class SolutionTest {
99
@Test
1010
public void uniquePathsWithObstacles() {
1111
int[][] expected = {
12-
{
13-
0, 0, 0,
14-
},
12+
{0, 0, 0},
1513
{0, 1, 0},
1614
{0, 0, 0}
1715
};

src/test/java/g0001_0100/s0068_text_justification/SolutionTest.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
public class SolutionTest {
1111
@Test
12-
public void textJustification() {
12+
public void fullJustify() {
1313
String[] input =
1414
new String[] {"This", "is", "an", "example", "of", "text", "justification."};
1515
List<String> actual = new Solution().fullJustify(input, 16);
@@ -19,8 +19,6 @@ public void textJustification() {
1919
expected.add("example of text");
2020
expected.add("justification. ");
2121

22-
for (int i = 0; i < expected.size(); i++) {
23-
assertThat(actual.get(i), equalTo(expected.get(i)));
24-
}
22+
assertThat(actual, equalTo(expected));
2523
}
2624
}

src/test/java/g0001_0100/s0070_climbing_stairs/SolutionTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import org.junit.Test;
77

88
public class SolutionTest {
9-
109
@Test
1110
public void climbStairs() {
1211
assertThat(new Solution().climbStairs(2), equalTo(2));

0 commit comments

Comments
 (0)