Skip to content

Commit 55dea6a

Browse files
committed
Improved tests
1 parent 8e7883e commit 55dea6a

File tree

10 files changed

+203
-151
lines changed

10 files changed

+203
-151
lines changed

src/main/kotlin/g3301_3400/s3362_zero_array_transformation_iii/Solution.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Solution {
1717
idx++
1818
}
1919
cur += diffs[i]
20-
while (cur < nums[i] && !last.isEmpty() && last.peek()!! >= i) {
20+
while (cur < nums[i] && last.isNotEmpty() && last.peek()!! >= i) {
2121
cur++
2222
diffs[last.poll()!! + 1]--
2323
}

src/main/kotlin/g3301_3400/s3367_maximize_sum_of_weights_after_edge_removals/Solution.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ class Solution {
99
fun maximizeSumOfWeights(edges: Array<IntArray>, k: Int): Long {
1010
val map = HashMap<Int?, ArrayList<IntArray>?>()
1111
for (edge in edges) {
12-
map.computeIfAbsent(edge[0]) { t: Int? -> ArrayList<IntArray>() }!!
12+
map.computeIfAbsent(edge[0]) { _: Int? -> ArrayList<IntArray>() }!!
1313
.add(intArrayOf(edge[1], edge[2]))
14-
map.computeIfAbsent(edge[1]) { t: Int? -> ArrayList<IntArray>() }!!
14+
map.computeIfAbsent(edge[1]) { _: Int? -> ArrayList<IntArray>() }!!
1515
.add(intArrayOf(edge[0], edge[2]))
1616
}
1717
return maximizeSumOfWeights(0, -1, k, map)[0]
@@ -25,7 +25,7 @@ class Solution {
2525
): LongArray {
2626
var sum: Long = 0
2727
val queue = PriorityQueue<Long>()
28-
for (i in map.get(v)!!) {
28+
for (i in map[v]!!) {
2929
if (i[0] != from) {
3030
val next = maximizeSumOfWeights(i[0], v, k, map)
3131
next[1] += i[1].toLong()
Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1-
package g3301_3400.s3360_stone_removal_game;
1+
package g3301_3400.s3360_stone_removal_game
22

3-
import static org.hamcrest.CoreMatchers.equalTo;
4-
import static org.hamcrest.MatcherAssert.assertThat;
3+
import org.hamcrest.CoreMatchers.equalTo
4+
import org.hamcrest.MatcherAssert.assertThat
5+
import org.junit.jupiter.api.Test
56

6-
import org.junit.jupiter.api.Test;
7-
8-
class SolutionTest {
7+
internal class SolutionTest {
98
@Test
10-
void canAliceWin() {
11-
assertThat(new Solution().canAliceWin(12), equalTo(true));
9+
fun canAliceWin() {
10+
assertThat<Boolean>(Solution().canAliceWin(12), equalTo<Boolean>(true))
1211
}
1312

1413
@Test
15-
void canAliceWin2() {
16-
assertThat(new Solution().canAliceWin(1), equalTo(false));
14+
fun canAliceWin2() {
15+
assertThat<Boolean>(Solution().canAliceWin(1), equalTo<Boolean>(false))
1716
}
1817

1918
@Test
20-
void canAliceWin3() {
21-
assertThat(new Solution().canAliceWin(19), equalTo(false));
19+
fun canAliceWin3() {
20+
assertThat<Boolean>(Solution().canAliceWin(19), equalTo<Boolean>(false))
2221
}
2322
}
Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,47 @@
1-
package g3301_3400.s3361_shift_distance_between_two_strings;
1+
package g3301_3400.s3361_shift_distance_between_two_strings
22

3-
import static org.hamcrest.CoreMatchers.equalTo;
4-
import static org.hamcrest.MatcherAssert.assertThat;
3+
import org.hamcrest.CoreMatchers.equalTo
4+
import org.hamcrest.MatcherAssert.assertThat
5+
import org.junit.jupiter.api.Test
56

6-
import org.junit.jupiter.api.Test;
7-
8-
class SolutionTest {
7+
internal class SolutionTest {
98
@Test
10-
void shiftDistance() {
11-
assertThat(
12-
new Solution()
13-
.shiftDistance(
14-
"abab",
15-
"baba",
16-
new int[] {
17-
100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
18-
0, 0, 0, 0, 0
19-
},
20-
new int[] {
21-
1, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
22-
0, 0, 0, 0, 0
23-
}),
24-
equalTo(2L));
9+
fun shiftDistance() {
10+
assertThat<Long>(
11+
Solution()
12+
.shiftDistance(
13+
"abab",
14+
"baba",
15+
intArrayOf(
16+
100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
17+
0, 0, 0, 0, 0,
18+
),
19+
intArrayOf(
20+
1, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
21+
0, 0, 0, 0, 0,
22+
),
23+
),
24+
equalTo<Long>(2L),
25+
)
2526
}
2627

2728
@Test
28-
void shiftDistance2() {
29-
assertThat(
30-
new Solution()
31-
.shiftDistance(
32-
"leet",
33-
"code",
34-
new int[] {
35-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
36-
1, 1, 1, 1, 1
37-
},
38-
new int[] {
39-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
40-
1, 1, 1, 1, 1
41-
}),
42-
equalTo(31L));
29+
fun shiftDistance2() {
30+
assertThat<Long>(
31+
Solution()
32+
.shiftDistance(
33+
"leet",
34+
"code",
35+
intArrayOf(
36+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
37+
1, 1, 1, 1, 1,
38+
),
39+
intArrayOf(
40+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
41+
1, 1, 1, 1, 1,
42+
),
43+
),
44+
equalTo<Long>(31L),
45+
)
4346
}
4447
}
Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,39 @@
1-
package g3301_3400.s3362_zero_array_transformation_iii;
1+
package g3301_3400.s3362_zero_array_transformation_iii
22

3-
import static org.hamcrest.CoreMatchers.equalTo;
4-
import static org.hamcrest.MatcherAssert.assertThat;
3+
import org.hamcrest.CoreMatchers.equalTo
4+
import org.hamcrest.MatcherAssert.assertThat
5+
import org.junit.jupiter.api.Test
56

6-
import org.junit.jupiter.api.Test;
7-
8-
class SolutionTest {
7+
internal class SolutionTest {
98
@Test
10-
void maxRemoval() {
11-
assertThat(
12-
new Solution()
13-
.maxRemoval(new int[] {2, 0, 2}, new int[][] {{0, 2}, {0, 2}, {1, 1}}),
14-
equalTo(1));
9+
fun maxRemoval() {
10+
assertThat<Int>(
11+
Solution()
12+
.maxRemoval(
13+
intArrayOf(2, 0, 2),
14+
arrayOf<IntArray>(intArrayOf(0, 2), intArrayOf(0, 2), intArrayOf(1, 1)),
15+
),
16+
equalTo<Int>(1),
17+
)
1518
}
1619

1720
@Test
18-
void maxRemoval2() {
19-
assertThat(
20-
new Solution()
21-
.maxRemoval(
22-
new int[] {1, 1, 1, 1},
23-
new int[][] {{1, 3}, {0, 2}, {1, 3}, {1, 2}}),
24-
equalTo(2));
21+
fun maxRemoval2() {
22+
assertThat<Int>(
23+
Solution()
24+
.maxRemoval(
25+
intArrayOf(1, 1, 1, 1),
26+
arrayOf<IntArray>(intArrayOf(1, 3), intArrayOf(0, 2), intArrayOf(1, 3), intArrayOf(1, 2)),
27+
),
28+
equalTo<Int>(2),
29+
)
2530
}
2631

2732
@Test
28-
void maxRemoval3() {
29-
assertThat(
30-
new Solution().maxRemoval(new int[] {1, 2, 3, 4}, new int[][] {{0, 3}}),
31-
equalTo(-1));
33+
fun maxRemoval3() {
34+
assertThat<Int>(
35+
Solution().maxRemoval(intArrayOf(1, 2, 3, 4), arrayOf<IntArray>(intArrayOf(0, 3))),
36+
equalTo<Int>(-1),
37+
)
3238
}
3339
}
Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,36 @@
1-
package g3301_3400.s3363_find_the_maximum_number_of_fruits_collected;
1+
package g3301_3400.s3363_find_the_maximum_number_of_fruits_collected
22

3-
import static org.hamcrest.CoreMatchers.equalTo;
4-
import static org.hamcrest.MatcherAssert.assertThat;
3+
import org.hamcrest.CoreMatchers.equalTo
4+
import org.hamcrest.MatcherAssert.assertThat
5+
import org.junit.jupiter.api.Test
56

6-
import org.junit.jupiter.api.Test;
7-
8-
class SolutionTest {
7+
internal class SolutionTest {
98
@Test
10-
void maxCollectedFruits() {
11-
assertThat(
12-
new Solution()
13-
.maxCollectedFruits(
14-
new int[][] {
15-
{1, 2, 3, 4}, {5, 6, 8, 7}, {9, 10, 11, 12}, {13, 14, 15, 16}
16-
}),
17-
equalTo(100));
9+
fun maxCollectedFruits() {
10+
assertThat<Int>(
11+
Solution()
12+
.maxCollectedFruits(
13+
arrayOf<IntArray>(
14+
intArrayOf(1, 2, 3, 4),
15+
intArrayOf(5, 6, 8, 7),
16+
intArrayOf(9, 10, 11, 12),
17+
intArrayOf(13, 14, 15, 16),
18+
),
19+
),
20+
equalTo<Int>(100),
21+
)
1822
}
1923

2024
@Test
21-
void maxCollectedFruits2() {
22-
assertThat(new Solution().maxCollectedFruits(new int[][] {{1, 1}, {1, 1}}), equalTo(4));
25+
fun maxCollectedFruits2() {
26+
assertThat<Int>(
27+
Solution().maxCollectedFruits(
28+
arrayOf<IntArray>(
29+
intArrayOf(1, 1),
30+
intArrayOf(1, 1),
31+
),
32+
),
33+
equalTo<Int>(4),
34+
)
2335
}
2436
}
Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
1-
package g3301_3400.s3364_minimum_positive_sum_subarray;
1+
package g3301_3400.s3364_minimum_positive_sum_subarray
22

3-
import static org.hamcrest.CoreMatchers.equalTo;
4-
import static org.hamcrest.MatcherAssert.assertThat;
3+
import org.hamcrest.CoreMatchers.equalTo
4+
import org.hamcrest.MatcherAssert.assertThat
5+
import org.junit.jupiter.api.Test
56

6-
import java.util.List;
7-
import org.junit.jupiter.api.Test;
8-
9-
class SolutionTest {
7+
internal class SolutionTest {
108
@Test
11-
void minimumSumSubarray() {
12-
assertThat(new Solution().minimumSumSubarray(List.of(3, -2, 1, 4), 2, 3), equalTo(1));
9+
fun minimumSumSubarray() {
10+
assertThat<Int>(
11+
Solution().minimumSumSubarray(listOf<Int>(3, -2, 1, 4), 2, 3),
12+
equalTo<Int>(1),
13+
)
1314
}
1415

1516
@Test
16-
void minimumSumSubarray2() {
17-
assertThat(new Solution().minimumSumSubarray(List.of(-2, 2, -3, 1), 2, 3), equalTo(-1));
17+
fun minimumSumSubarray2() {
18+
assertThat<Int>(
19+
Solution().minimumSumSubarray(listOf<Int>(-2, 2, -3, 1), 2, 3),
20+
equalTo<Int>(-1),
21+
)
1822
}
1923

2024
@Test
21-
void minimumSumSubarray3() {
22-
assertThat(new Solution().minimumSumSubarray(List.of(1, 2, 3, 4), 2, 4), equalTo(3));
25+
fun minimumSumSubarray3() {
26+
assertThat<Int>(
27+
Solution().minimumSumSubarray(mutableListOf<Int>(1, 2, 3, 4), 2, 4),
28+
equalTo<Int>(3),
29+
)
2330
}
2431
}
Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,34 @@
1-
package g3301_3400.s3365_rearrange_k_substrings_to_form_target_string;
1+
package g3301_3400.s3365_rearrange_k_substrings_to_form_target_string
22

3-
import static org.hamcrest.CoreMatchers.equalTo;
4-
import static org.hamcrest.MatcherAssert.assertThat;
3+
import org.hamcrest.CoreMatchers.equalTo
4+
import org.hamcrest.MatcherAssert.assertThat
5+
import org.junit.jupiter.api.Test
56

6-
import org.junit.jupiter.api.Test;
7-
8-
class SolutionTest {
7+
internal class SolutionTest {
98
@Test
10-
void isPossibleToRearrange() {
11-
assertThat(new Solution().isPossibleToRearrange("abcd", "cdab", 2), equalTo(true));
9+
fun isPossibleToRearrange() {
10+
assertThat<Boolean>(
11+
Solution()
12+
.isPossibleToRearrange("abcd", "cdab", 2),
13+
equalTo<Boolean>(true),
14+
)
1215
}
1316

1417
@Test
15-
void isPossibleToRearrange2() {
16-
assertThat(new Solution().isPossibleToRearrange("aabbcc", "bbaacc", 3), equalTo(true));
18+
fun isPossibleToRearrange2() {
19+
assertThat<Boolean>(
20+
Solution()
21+
.isPossibleToRearrange("aabbcc", "bbaacc", 3),
22+
equalTo<Boolean>(true),
23+
)
1724
}
1825

1926
@Test
20-
void isPossibleToRearrange3() {
21-
assertThat(new Solution().isPossibleToRearrange("aabbcc", "bbaacc", 2), equalTo(false));
27+
fun isPossibleToRearrange3() {
28+
assertThat<Boolean>(
29+
Solution()
30+
.isPossibleToRearrange("aabbcc", "bbaacc", 2),
31+
equalTo<Boolean>(false),
32+
)
2233
}
2334
}
Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
1-
package g3301_3400.s3366_minimum_array_sum;
1+
package g3301_3400.s3366_minimum_array_sum
22

3-
import static org.hamcrest.CoreMatchers.equalTo;
4-
import static org.hamcrest.MatcherAssert.assertThat;
3+
import org.hamcrest.CoreMatchers.equalTo
4+
import org.hamcrest.MatcherAssert.assertThat
5+
import org.junit.jupiter.api.Test
56

6-
import org.junit.jupiter.api.Test;
7-
8-
class SolutionTest {
7+
internal class SolutionTest {
98
@Test
10-
void minArraySum() {
11-
assertThat(new Solution().minArraySum(new int[] {2, 8, 3, 19, 3}, 3, 1, 1), equalTo(23));
9+
fun minArraySum() {
10+
assertThat<Int>(
11+
Solution().minArraySum(intArrayOf(2, 8, 3, 19, 3), 3, 1, 1),
12+
equalTo<Int>(23),
13+
)
1214
}
1315

1416
@Test
15-
void minArraySum2() {
16-
assertThat(new Solution().minArraySum(new int[] {2, 4, 3}, 3, 2, 1), equalTo(3));
17+
fun minArraySum2() {
18+
assertThat<Int>(
19+
Solution().minArraySum(intArrayOf(2, 4, 3), 3, 2, 1),
20+
equalTo<Int>(3),
21+
)
1722
}
1823
}

0 commit comments

Comments
 (0)