From 4c2444ace4fefc85120d0e3e92d32703a5a9a2c0 Mon Sep 17 00:00:00 2001 From: ThanhNIT Date: Sat, 29 Nov 2025 08:35:00 +0700 Subject: [PATCH] Added tests for tasks 441-3040 --- .../s0441_arranging_coins/SolutionTest.kt | 35 ++++++++++ .../s0836_rectangle_overlap/SolutionTest.kt | 48 +++++++++++++ .../SolutionTest.kt | 67 +++++++++++++++++++ .../SolutionTest.kt | 50 ++++++++++++++ .../SolutionTest.kt | 40 +++++++++++ 5 files changed, 240 insertions(+) diff --git a/src/test/kotlin/g0401_0500/s0441_arranging_coins/SolutionTest.kt b/src/test/kotlin/g0401_0500/s0441_arranging_coins/SolutionTest.kt index 6c8607547..462c7d293 100644 --- a/src/test/kotlin/g0401_0500/s0441_arranging_coins/SolutionTest.kt +++ b/src/test/kotlin/g0401_0500/s0441_arranging_coins/SolutionTest.kt @@ -14,4 +14,39 @@ internal class SolutionTest { fun arrangeCoins2() { assertThat(Solution().arrangeCoins(8), equalTo(3)) } + + @Test + fun arrangeCoins3() { + assertThat(Solution().arrangeCoins(0), equalTo(0)) + } + + @Test + fun arrangeCoins4() { + assertThat(Solution().arrangeCoins(1), equalTo(1)) + } + + @Test + fun arrangeCoins5() { + assertThat(Solution().arrangeCoins(2), equalTo(1)) + } + + @Test + fun arrangeCoins6() { + assertThat(Solution().arrangeCoins(3), equalTo(2)) + } + + @Test + fun arrangeCoins7() { + assertThat(Solution().arrangeCoins(6), equalTo(3)) + } + + @Test + fun arrangeCoins8() { + assertThat(Solution().arrangeCoins(2147483647), equalTo(65535)) + } + + @Test + fun arrangeCoins9() { + assertThat(Solution().arrangeCoins(7), equalTo(3)) + } } diff --git a/src/test/kotlin/g0801_0900/s0836_rectangle_overlap/SolutionTest.kt b/src/test/kotlin/g0801_0900/s0836_rectangle_overlap/SolutionTest.kt index 4201bee24..76309310c 100644 --- a/src/test/kotlin/g0801_0900/s0836_rectangle_overlap/SolutionTest.kt +++ b/src/test/kotlin/g0801_0900/s0836_rectangle_overlap/SolutionTest.kt @@ -28,4 +28,52 @@ internal class SolutionTest { equalTo(false), ) } + + @Test + fun isRectangleOverlap4() { + assertThat( + Solution().isRectangleOverlap(intArrayOf(0, 0, 2, 2), intArrayOf(0, 2, 2, 4)), + equalTo(false), + ) + } + + @Test + fun isRectangleOverlap5() { + assertThat( + Solution().isRectangleOverlap(intArrayOf(1, 1, 3, 3), intArrayOf(1, 0, 3, 1)), + equalTo(false), + ) + } + + @Test + fun isRectangleOverlap6() { + assertThat( + Solution().isRectangleOverlap(intArrayOf(-3, -3, -1, -1), intArrayOf(-2, -2, 0, 0)), + equalTo(true), + ) + } + + @Test + fun isRectangleOverlap7() { + assertThat( + Solution().isRectangleOverlap(intArrayOf(0, 0, 4, 4), intArrayOf(1, 1, 3, 3)), + equalTo(true), + ) + } + + @Test + fun isRectangleOverlap8() { + assertThat( + Solution().isRectangleOverlap(intArrayOf(0, 0, 2, 2), intArrayOf(0, 0, 2, 2)), + equalTo(true), + ) + } + + @Test + fun isRectangleOverlap9() { + assertThat( + Solution().isRectangleOverlap(intArrayOf(0, 0, 1, 1), intArrayOf(1, 1, 2, 2)), + equalTo(false), + ) + } } diff --git a/src/test/kotlin/g0801_0900/s0840_magic_squares_in_grid/SolutionTest.kt b/src/test/kotlin/g0801_0900/s0840_magic_squares_in_grid/SolutionTest.kt index 053dba5c0..913ddfbe3 100644 --- a/src/test/kotlin/g0801_0900/s0840_magic_squares_in_grid/SolutionTest.kt +++ b/src/test/kotlin/g0801_0900/s0840_magic_squares_in_grid/SolutionTest.kt @@ -130,4 +130,71 @@ internal class SolutionTest { ) assertThat(Solution().numMagicSquaresInside(grid), equalTo(1)) } + + @Test + fun numMagicSquaresInside14() { + assertThat( + Solution().numMagicSquaresInside(arrayOf(intArrayOf(1, 2), intArrayOf(3, 4))), + equalTo(0), + ) + } + + @Test + fun numMagicSquaresInside15() { + assertThat( + Solution().numMagicSquaresInside( + arrayOf( + intArrayOf(4, 3, 8, 4, 3), + intArrayOf(9, 5, 1, 9, 5), + intArrayOf(2, 7, 6, 2, 7), + intArrayOf(4, 3, 8, 4, 3), + intArrayOf(9, 5, 1, 9, 5), + ), + ), + equalTo(1), + ) + } + + @Test + fun numMagicSquaresInside16() { + assertThat( + Solution().numMagicSquaresInside( + arrayOf( + intArrayOf(10, 3, 8), + intArrayOf(9, 5, 1), + intArrayOf(2, 7, 6), + ), + ), + equalTo(0), + ) + } + + @Test + fun numMagicSquaresInside17() { + assertThat( + Solution().numMagicSquaresInside( + arrayOf( + intArrayOf(4, 3, 8, 4), + intArrayOf(9, 5, 1, 9), + intArrayOf(2, 7, 6, 2), + intArrayOf(4, 3, 8, 4), + ), + ), + equalTo(1), + ) + } + + @Test + fun numMagicSquaresInside18() { + assertThat( + Solution().numMagicSquaresInside( + arrayOf( + intArrayOf(2, 2, 2), + intArrayOf(2, 2, 2), + intArrayOf(2, 2, 2), + ), + ), + equalTo(0), + ) + } } diff --git a/src/test/kotlin/g0801_0900/s0863_all_nodes_distance_k_in_binary_tree/SolutionTest.kt b/src/test/kotlin/g0801_0900/s0863_all_nodes_distance_k_in_binary_tree/SolutionTest.kt index 25701c3df..e4f013014 100644 --- a/src/test/kotlin/g0801_0900/s0863_all_nodes_distance_k_in_binary_tree/SolutionTest.kt +++ b/src/test/kotlin/g0801_0900/s0863_all_nodes_distance_k_in_binary_tree/SolutionTest.kt @@ -1,6 +1,7 @@ package g0801_0900.s0863_all_nodes_distance_k_in_binary_tree import com_github_leetcode.TreeNode +import com_github_leetcode.TreeUtils import org.hamcrest.CoreMatchers.equalTo import org.hamcrest.MatcherAssert.assertThat import org.junit.jupiter.api.Test @@ -33,4 +34,53 @@ internal class SolutionTest { equalTo(emptyList()), ) } + + @Test + fun distanceK3() { + val root = TreeUtils.constructBinaryTree( + listOf(3, 5, 1, 6, 2, 0, 8, null, null, 7, 4), + ) + assertThat( + Solution().distanceK(root, TreeNode(3), 2), + equalTo(listOf(6, 2, 0, 8)), + ) + } + + @Test + fun distanceK4() { + val root = TreeUtils.constructBinaryTree( + listOf(3, 5, 1, 6, 2, 0, 8, null, null, 7, 4), + ) + assertThat( + Solution().distanceK(root, TreeNode(7), 1), + equalTo(listOf(2)), + ) + } + + @Test + fun distanceK5() { + val root = TreeUtils.constructBinaryTree(listOf(1, 2, 3)) + assertThat( + Solution().distanceK(root, TreeNode(2), 0), + equalTo(listOf(2)), + ) + } + + @Test + fun distanceK6() { + val root = TreeUtils.constructBinaryTree(listOf(1, 2, 3)) + assertThat( + Solution().distanceK(root, TreeNode(1), 5), + equalTo(emptyList()), + ) + } + + @Test + fun distanceK7() { + val root = TreeUtils.constructBinaryTree(listOf(1, 2, null, 3, null, 4)) + assertThat( + Solution().distanceK(root, TreeNode(2), 2), + equalTo(listOf(4)), + ) + } } diff --git a/src/test/kotlin/g3001_3100/s3040_maximum_number_of_operations_with_the_same_score_ii/SolutionTest.kt b/src/test/kotlin/g3001_3100/s3040_maximum_number_of_operations_with_the_same_score_ii/SolutionTest.kt index 8daa3e798..9c4af2a01 100644 --- a/src/test/kotlin/g3001_3100/s3040_maximum_number_of_operations_with_the_same_score_ii/SolutionTest.kt +++ b/src/test/kotlin/g3001_3100/s3040_maximum_number_of_operations_with_the_same_score_ii/SolutionTest.kt @@ -14,4 +14,44 @@ internal class SolutionTest { fun maxOperations2() { assertThat(Solution().maxOperations(intArrayOf(3, 2, 6, 1, 4)), equalTo(2)) } + + @Test + fun maxOperations3() { + assertThat(Solution().maxOperations(intArrayOf(1, 2)), equalTo(1)) + } + + @Test + fun maxOperations4() { + assertThat(Solution().maxOperations(intArrayOf(1, 1, 1)), equalTo(1)) + } + + @Test + fun maxOperations5() { + assertThat(Solution().maxOperations(intArrayOf(2, 2, 2, 2, 2, 2)), equalTo(3)) + } + + @Test + fun maxOperations6() { + assertThat(Solution().maxOperations(intArrayOf(1, 2, 3, 4, 5, 6)), equalTo(3)) + } + + @Test + fun maxOperations7() { + assertThat(Solution().maxOperations(intArrayOf(6, 5, 4, 3, 2, 1)), equalTo(3)) + } + + @Test + fun maxOperations8() { + assertThat(Solution().maxOperations(intArrayOf(1, 3, 2, 4, 1, 3)), equalTo(2)) + } + + @Test + fun maxOperations9() { + assertThat(Solution().maxOperations(intArrayOf(1, 2, 4, 5)), equalTo(2)) + } + + @Test + fun maxOperations10() { + assertThat(Solution().maxOperations(intArrayOf(5, 5)), equalTo(1)) + } }