Skip to content

Commit

Permalink
Improved mysql tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
javadev authored Nov 22, 2024
1 parent fe66e08 commit 7a64938
Show file tree
Hide file tree
Showing 50 changed files with 169 additions and 168 deletions.
7 changes: 4 additions & 3 deletions src/main/kotlin/g0201_0300/s0212_word_search_ii/Solution.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ package g0201_0300.s0212_word_search_ii
@Suppress("NAME_SHADOWING")
class Solution {
private var root: Tree? = null
fun findWords(board: Array<CharArray>, words: Array<String?>): List<String> {
if (board.size < 1 || board[0].size < 1) {

fun findWords(board: Array<CharArray>, words: Array<String>): List<String> {
if (board.isEmpty() || board[0].isEmpty()) {
return emptyList()
}
root = Tree()
for (word in words) {
Tree.addWord(root, word!!)
Tree.addWord(root, word)
}
val collected: MutableList<String> = ArrayList()
for (i in board.indices) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal class MysqlTest {
@Test
@Throws(SQLException::class, FileNotFoundException::class)
fun testScript(@EmbeddedDatabase dataSource: DataSource) {
dataSource.getConnection().use { connection ->
dataSource.connection.use { connection ->
connection.createStatement().use { statement ->
statement.executeQuery(
BufferedReader(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal class SolutionTest {
charArrayOf('i', 'h', 'k', 'r'),
charArrayOf('i', 'f', 'l', 'v'),
)
val words = arrayOf<String?>("oath", "pea", "eat", "rain")
val words = arrayOf<String>("oath", "pea", "eat", "rain")
val expected: MutableList<String> = ArrayList()
expected.add("oath")
expected.add("eat")
Expand All @@ -23,7 +23,7 @@ internal class SolutionTest {
@Test
fun findWords2() {
val board = arrayOf(charArrayOf('a', 'b'), charArrayOf('c', 'd'))
val words = arrayOf<String?>("abcb")
val words = arrayOf<String>("abcb")
assertThat(Solution().findWords(board, words), equalTo(emptyList()))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ internal class MysqlTest {
@Test
@Throws(SQLException::class, FileNotFoundException::class)
fun testScript(@EmbeddedDatabase dataSource: DataSource) {
dataSource.getConnection().use { connection ->
dataSource.connection.use { connection ->
connection.createStatement().use { statement ->
statement.executeQuery(
BufferedReader(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal class MysqlTest {
@Test
@Throws(SQLException::class, FileNotFoundException::class)
fun testScript(@EmbeddedDatabase dataSource: DataSource) {
dataSource.getConnection().use { connection ->
dataSource.connection.use { connection ->
connection.createStatement().use { statement ->
statement.executeQuery(
BufferedReader(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ internal class MysqlTest {
@Test
@Throws(SQLException::class, FileNotFoundException::class)
fun testScript(@EmbeddedDatabase dataSource: DataSource) {
dataSource.getConnection().use { connection ->
dataSource.connection.use { connection ->
connection.createStatement().use { statement ->
statement.executeQuery(
BufferedReader(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal class MysqlTest {
@Test
@Throws(SQLException::class, FileNotFoundException::class)
fun testScript(@EmbeddedDatabase dataSource: DataSource) {
dataSource.getConnection().use { connection ->
dataSource.connection.use { connection ->
connection.createStatement().use { statement ->
statement.executeQuery(
BufferedReader(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal class MysqlTest {
@Test
@Throws(SQLException::class, FileNotFoundException::class)
fun testScript(@EmbeddedDatabase dataSource: DataSource) {
dataSource.getConnection().use { connection ->
dataSource.connection.use { connection ->
connection.createStatement().use { statement ->
statement.executeQuery(
BufferedReader(
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/g0601_0700/s0607_sales_person/MysqlTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal class MysqlTest {
@Test
@Throws(SQLException::class, FileNotFoundException::class)
fun testScript(@EmbeddedDatabase dataSource: DataSource) {
dataSource.getConnection().use { connection ->
dataSource.connection.use { connection ->
connection.createStatement().use { statement ->
statement.executeQuery(
BufferedReader(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal class MysqlTest {
@Test
@Throws(SQLException::class, FileNotFoundException::class)
fun testScript(@EmbeddedDatabase dataSource: DataSource) {
dataSource.getConnection().use { connection ->
dataSource.connection.use { connection ->
connection.createStatement().use { statement ->
statement.executeQuery(
BufferedReader(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal class MysqlTest {
@Test
@Throws(SQLException::class, FileNotFoundException::class)
fun testScript(@EmbeddedDatabase dataSource: DataSource) {
dataSource.getConnection().use { connection ->
dataSource.connection.use { connection ->
connection.createStatement().use { statement ->
statement.executeQuery(
BufferedReader(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import org.junit.jupiter.api.Test
internal class SolutionTest {
@Test
fun btreeGameWinningMove() {
val root = TreeNode.create(mutableListOf<Int?>(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11))
val root = TreeNode.create(mutableListOf<Int>(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11))
assertThat(Solution().btreeGameWinningMove(root, 11, 3), equalTo(true))
}

@Test
fun btreeGameWinningMove2() {
val root = TreeNode.create(mutableListOf<Int?>(1, 2, 3))
val root = TreeNode.create(mutableListOf<Int>(1, 2, 3))
assertThat(Solution().btreeGameWinningMove(root, 3, 1), equalTo(false))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal class MysqlTest {
@Test
@Throws(SQLException::class, FileNotFoundException::class)
fun testScript(@EmbeddedDatabase dataSource: DataSource) {
dataSource.getConnection().use { connection ->
dataSource.connection.use { connection ->
connection.createStatement().use { statement ->
statement.executeQuery(
BufferedReader(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal class SolutionTest {
assertThat(
Solution().splitMessage("this is really a very awesome message", 9),
equalTo(
arrayOf<String?>(
arrayOf<String>(
"thi<1/14>",
"s i<2/14>",
"s r<3/14>",
Expand All @@ -34,7 +34,7 @@ internal class SolutionTest {
fun splitMessage2() {
assertThat(
Solution().splitMessage("short message", 15),
equalTo(arrayOf<String?>("short mess<1/2>", "age<2/2>")),
equalTo(arrayOf<String>("short mess<1/2>", "age<2/2>")),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ internal class SolutionTest {
@Test
fun minimumTime() {
assertThat(
Solution().minimumTime(mutableListOf<Int?>(1, 2, 3), mutableListOf<Int?>(1, 2, 3), 4),
Solution().minimumTime(mutableListOf<Int>(1, 2, 3), mutableListOf<Int>(1, 2, 3), 4),
equalTo(3),
)
}

@Test
fun minimumTime2() {
assertThat(
Solution().minimumTime(mutableListOf<Int?>(1, 2, 3), mutableListOf<Int?>(3, 3, 3), 4),
Solution().minimumTime(mutableListOf<Int>(1, 2, 3), mutableListOf<Int>(3, 3, 3), 4),
equalTo(-1),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ internal class SolutionTest {
@Test
fun maximumScore() {
assertThat(
Solution().maximumScore(mutableListOf<Int?>(8, 3, 9, 3, 8), 2),
Solution().maximumScore(mutableListOf<Int>(8, 3, 9, 3, 8), 2),
equalTo(81),
)
}

@Test
fun maximumScore2() {
assertThat(
Solution().maximumScore(mutableListOf<Int?>(19, 12, 14, 6, 10, 18), 3),
Solution().maximumScore(mutableListOf<Int>(19, 12, 14, 6, 10, 18), 3),
equalTo(4788),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal class SolutionTest {
fun divideArray() {
assertThat(
Solution().divideArray(intArrayOf(1, 3, 4, 8, 7, 9, 3, 5, 1), 2),
equalTo(arrayOf<IntArray?>(intArrayOf(1, 1, 3), intArrayOf(3, 4, 5), intArrayOf(7, 8, 9))),
equalTo(arrayOf<IntArray>(intArrayOf(1, 1, 3), intArrayOf(3, 4, 5), intArrayOf(7, 8, 9))),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ internal class SolutionTest {
fun shortestSubstrings() {
assertThat(
Solution().shortestSubstrings(arrayOf("cab", "ad", "bad", "c")),
equalTo(arrayOf<String?>("ab", "", "ba", "")),
equalTo(arrayOf<String>("ab", "", "ba", "")),
)
}

@Test
fun shortestSubstrings2() {
assertThat(
Solution().shortestSubstrings(arrayOf("abc", "bcd", "abcd")),
equalTo(arrayOf<String?>("", "", "abcd")),
equalTo(arrayOf<String>("", "", "abcd")),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import org.junit.jupiter.api.Test
internal class SolutionTest {
@Test
fun convertDateToBinary() {
assertThat<String?>(
assertThat<String>(
Solution().convertDateToBinary("2080-02-29"),
equalTo<String?>("100000100000-10-11101"),
equalTo<String>("100000100000-10-11101"),
)
}

@Test
fun convertDateToBinary2() {
assertThat<String?>(
assertThat<String>(
Solution().convertDateToBinary("1900-01-01"),
equalTo<String?>("11101101100-1-1"),
equalTo<String>("11101101100-1-1"),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import org.junit.jupiter.api.Test
internal class SolutionTest {
@Test
fun maxPossibleScore() {
assertThat<Int?>(
assertThat<Int>(
Solution().maxPossibleScore(intArrayOf(6, 0, 3), 2),
equalTo<Int?>(4),
equalTo<Int>(4),
)
}

@Test
fun maxPossibleScore2() {
assertThat<Int?>(
assertThat<Int>(
Solution().maxPossibleScore(intArrayOf(2, 6, 13, 13), 5),
equalTo<Int?>(5),
equalTo<Int>(5),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import org.junit.jupiter.api.Test
internal class SolutionTest {
@Test
fun findMaximumScore() {
assertThat<Long?>(
assertThat<Long>(
Solution().findMaximumScore(mutableListOf<Int>(1, 3, 1, 5)),
equalTo<Long?>(7L),
equalTo<Long>(7L),
)
}

@Test
fun findMaximumScore2() {
assertThat<Long?>(
assertThat<Long>(
Solution().findMaximumScore(mutableListOf<Int>(4, 3, 1, 3, 2)),
equalTo<Long?>(16L),
equalTo<Long>(16L),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,33 @@ import org.junit.jupiter.api.Test
internal class SolutionTest {
@Test
fun maxMoves() {
assertThat<Int?>(
assertThat<Int>(
Solution().maxMoves(1, 1, arrayOf(intArrayOf(0, 0))),
equalTo<Int?>(4),
equalTo<Int>(4),
)
}

@Test
fun maxMoves2() {
assertThat<Int?>(
assertThat<Int>(
Solution().maxMoves(
0,
2,
arrayOf(intArrayOf(1, 1), intArrayOf(2, 2), intArrayOf(3, 3)),
),
equalTo<Int?>(8),
equalTo<Int>(8),
)
}

@Test
fun maxMoves3() {
assertThat<Int?>(
assertThat<Int>(
Solution().maxMoves(
0,
0,
arrayOf(intArrayOf(1, 2), intArrayOf(2, 4)),
),
equalTo<Int?>(3),
equalTo<Int>(3),
)
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package g3201_3300.s3286_find_a_safe_walk_through_a_grid

import com_github_leetcode.ArrayUtils.getLists
import org.hamcrest.CoreMatchers
import org.hamcrest.MatcherAssert
import org.hamcrest.CoreMatchers.equalTo
import org.hamcrest.MatcherAssert.assertThat
import org.junit.jupiter.api.Test

internal class SolutionTest {
@Test
fun findSafeWalk() {
MatcherAssert.assertThat<Boolean?>(
assertThat<Boolean>(
Solution()
.findSafeWalk(
getLists(
Expand All @@ -20,13 +20,13 @@ internal class SolutionTest {
),
1,
),
CoreMatchers.equalTo<Boolean?>(true),
equalTo<Boolean>(true),
)
}

@Test
fun findSafeWalk2() {
MatcherAssert.assertThat<Boolean?>(
assertThat<Boolean>(
Solution()
.findSafeWalk(
getLists(
Expand All @@ -39,13 +39,13 @@ internal class SolutionTest {
),
3,
),
CoreMatchers.equalTo<Boolean?>(false),
equalTo<Boolean>(false),
)
}

@Test
fun findSafeWalk3() {
MatcherAssert.assertThat<Boolean?>(
assertThat<Boolean>(
Solution()
.findSafeWalk(
getLists(
Expand All @@ -57,7 +57,7 @@ internal class SolutionTest {
),
5,
),
CoreMatchers.equalTo<Boolean?>(true),
equalTo<Boolean>(true),
)
}
}
Loading

0 comments on commit 7a64938

Please sign in to comment.