Skip to content

Commit 6008de7

Browse files
authored
Added tests 30-50.
1 parent bbec5b9 commit 6008de7

File tree

14 files changed

+158
-3
lines changed

14 files changed

+158
-3
lines changed

src.save/test/java/g0001_0100/s0030_substring_with_concatenation_of_all_words/SolutionTest.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,34 @@
33
import static org.hamcrest.CoreMatchers.equalTo;
44
import static org.hamcrest.MatcherAssert.assertThat;
55

6+
import java.util.Arrays;
7+
import java.util.Collections;
68
import org.junit.jupiter.api.Test;
79

810
class SolutionTest {
911
@Test
1012
void findSubstring() {
13+
assertThat(
14+
new Solution().findSubstring("barfoothefoobarman", new String[] {"foo", "bar"}),
15+
equalTo(Arrays.asList(0, 9)));
16+
}
17+
18+
@Test
19+
void findSubstring2() {
20+
assertThat(
21+
new Solution()
22+
.findSubstring(
23+
"wordgoodgoodgoodbestword",
24+
new String[] {"word", "good", "best", "word"}),
25+
equalTo(Collections.emptyList()));
26+
}
27+
28+
@Test
29+
void findSubstring3() {
1130
assertThat(
1231
new Solution()
13-
.findSubstring("barfoothefoobarman", new String[] {"foo", "bar"})
14-
.toString(),
15-
equalTo("[0, 9]"));
32+
.findSubstring(
33+
"barfoofoobarthefoobarman", new String[] {"bar", "foo", "the"}),
34+
equalTo(Arrays.asList(6, 9, 12)));
1635
}
1736
}

src.save/test/java/g0001_0100/s0031_next_permutation/SolutionTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,18 @@ void nextPermutation() {
1212
new Solution().nextPermutation(array);
1313
assertThat(array, equalTo(new int[] {1, 3, 2}));
1414
}
15+
16+
@Test
17+
void nextPermutation2() {
18+
int[] array = new int[] {3, 2, 1};
19+
new Solution().nextPermutation(array);
20+
assertThat(array, equalTo(new int[] {1, 2, 3}));
21+
}
22+
23+
@Test
24+
void nextPermutation3() {
25+
int[] array = new int[] {1, 1, 5};
26+
new Solution().nextPermutation(array);
27+
assertThat(array, equalTo(new int[] {1, 5, 1}));
28+
}
1529
}

src.save/test/java/g0001_0100/s0035_search_insert_position/SolutionTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,14 @@ class SolutionTest {
1010
void searchInsert() {
1111
assertThat(new Solution().searchInsert(new int[] {1, 3, 5, 6}, 5), equalTo(2));
1212
}
13+
14+
@Test
15+
void searchInsert2() {
16+
assertThat(new Solution().searchInsert(new int[] {1, 3, 5, 6}, 2), equalTo(1));
17+
}
18+
19+
@Test
20+
void searchInsert3() {
21+
assertThat(new Solution().searchInsert(new int[] {1, 3, 5, 6}, 7), equalTo(4));
22+
}
1323
}

src.save/test/java/g0001_0100/s0036_valid_sudoku/SolutionTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,23 @@ void isValidSudoku() {
2424
});
2525
assertThat(result, equalTo(true));
2626
}
27+
28+
@Test
29+
void isValidSudoku2() {
30+
boolean result =
31+
new Solution()
32+
.isValidSudoku(
33+
new char[][] {
34+
{'8', '3', '.', '.', '7', '.', '.', '.', '.'},
35+
{'6', '.', '.', '1', '9', '5', '.', '.', '.'},
36+
{'.', '9', '8', '.', '.', '.', '.', '6', '.'},
37+
{'8', '.', '.', '.', '6', '.', '.', '.', '3'},
38+
{'4', '.', '.', '8', '.', '3', '.', '.', '1'},
39+
{'7', '.', '.', '.', '2', '.', '.', '.', '6'},
40+
{'.', '6', '.', '.', '.', '.', '2', '8', '.'},
41+
{'.', '.', '.', '4', '1', '9', '.', '.', '5'},
42+
{'.', '.', '.', '.', '8', '.', '.', '7', '9'}
43+
});
44+
assertThat(result, equalTo(false));
45+
}
2746
}

src.save/test/java/g0001_0100/s0039_combination_sum/SolutionTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,18 @@ void combinationSum() {
1313
new Solution().combinationSum(new int[] {2, 3, 6, 7}, 7),
1414
equalTo(ArrayUtils.getLists(new int[][] {{7}, {3, 2, 2}})));
1515
}
16+
17+
@Test
18+
void combinationSum2() {
19+
assertThat(
20+
new Solution().combinationSum(new int[] {2, 3, 5}, 8),
21+
equalTo(ArrayUtils.getLists(new int[][] {{5, 3}, {3, 3, 2}, {2, 2, 2, 2}})));
22+
}
23+
24+
@Test
25+
void combinationSum3() {
26+
assertThat(
27+
new Solution().combinationSum(new int[] {2}, 1),
28+
equalTo(ArrayUtils.getLists(new int[][] {})));
29+
}
1630
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,12 @@ void combinationSum2() {
1414
new Solution().combinationSum2(new int[] {10, 1, 2, 7, 6, 1, 5}, 8),
1515
equalTo(ArrayUtils.getLists(expected)));
1616
}
17+
18+
@Test
19+
void combinationSum22() {
20+
int[][] expected = {{1, 2, 2}, {5}};
21+
assertThat(
22+
new Solution().combinationSum2(new int[] {2, 5, 2, 1, 2}, 5),
23+
equalTo(ArrayUtils.getLists(expected)));
24+
}
1725
}

src.save/test/java/g0001_0100/s0042_trapping_rain_water/SolutionTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,9 @@ class SolutionTest {
1010
void trap() {
1111
assertThat(new Solution().trap(new int[] {0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1}), equalTo(6));
1212
}
13+
14+
@Test
15+
void trap2() {
16+
assertThat(new Solution().trap(new int[] {4, 2, 0, 3, 2, 5}), equalTo(9));
17+
}
1318
}

src.save/test/java/g0001_0100/s0043_multiply_strings/SolutionTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,9 @@ class SolutionTest {
1010
void multiply() {
1111
assertThat(new Solution().multiply("2", "3"), equalTo("6"));
1212
}
13+
14+
@Test
15+
void multiply2() {
16+
assertThat(new Solution().multiply("123", "456"), equalTo("56088"));
17+
}
1318
}

src.save/test/java/g0001_0100/s0045_jump_game_ii/SolutionTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,9 @@ class SolutionTest {
1010
void jump() {
1111
assertThat(new Solution().jump(new int[] {2, 3, 1, 1, 4}), equalTo(2));
1212
}
13+
14+
@Test
15+
void jump2() {
16+
assertThat(new Solution().jump(new int[] {2, 3, 0, 1, 4}), equalTo(2));
17+
}
1318
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,17 @@ void permute() {
1414
new Solution().permute(new int[] {1, 2, 3}),
1515
equalTo(ArrayUtils.getLists(expected)));
1616
}
17+
18+
@Test
19+
void permute2() {
20+
int[][] expected = {{0, 1}, {1, 0}};
21+
assertThat(
22+
new Solution().permute(new int[] {0, 1}), equalTo(ArrayUtils.getLists(expected)));
23+
}
24+
25+
@Test
26+
void permute3() {
27+
int[][] expected = {{1}};
28+
assertThat(new Solution().permute(new int[] {1}), equalTo(ArrayUtils.getLists(expected)));
29+
}
1730
}

0 commit comments

Comments
 (0)