From 3b55434bb3da0954177a22068e0d3f80c2bdd0ab Mon Sep 17 00:00:00 2001 From: ThanhNIT Date: Sat, 29 Nov 2025 09:28:31 +0700 Subject: [PATCH] Added tests 558-3548 --- .../SolutionTest.kt | 48 ++++++++ .../s0715_range_module/RangeModuleTest.kt | 82 +++++++++++++ .../SolutionTest.kt | 48 ++++++++ .../SolutionTest.kt | 54 +++++++++ .../SolutionTest.kt | 45 ++++++++ .../SolutionTest.kt | 109 ++++++++++++++++++ 6 files changed, 386 insertions(+) diff --git a/src/test/kotlin/g0501_0600/s0558_logical_or_of_two_binary_grids_represented_as_quad_trees/SolutionTest.kt b/src/test/kotlin/g0501_0600/s0558_logical_or_of_two_binary_grids_represented_as_quad_trees/SolutionTest.kt index 38694ead5..57656672f 100644 --- a/src/test/kotlin/g0501_0600/s0558_logical_or_of_two_binary_grids_represented_as_quad_trees/SolutionTest.kt +++ b/src/test/kotlin/g0501_0600/s0558_logical_or_of_two_binary_grids_represented_as_quad_trees/SolutionTest.kt @@ -26,4 +26,52 @@ internal class SolutionTest { equalTo("[0,0][1,1][1,1][1,1][1,0]"), ) } + + @Test + fun intersect2() { + val n1 = Node(true, true) + val n2 = Node(true, true) + assertThat(Solution().intersect(n1, n2), equalTo(n1)) + } + + @Test + fun intersect3() { + val n1 = Node(true, true) + val n2 = Node(false, false) + assertThat(Solution().intersect(n1, n2), equalTo(n1)) + } + + @Test + fun intersect4() { + val n1 = Node(false, false) + val n2 = Node(true, true) + assertThat(Solution().intersect(n1, n2), equalTo(n2)) + } + + @Test + fun intersect5() { + val n1 = Node(true, false) + val n2 = Node(true, true) + assertThat(Solution().intersect(n1, n2), equalTo(n2)) + } + + @Test + fun intersect6() { + val a = Node(true, true) + val n1 = Node(false, false) + n1.topLeft = a + n1.topRight = a + n1.bottomLeft = a + n1.bottomRight = a + + val n2 = Node(false, false) + n2.topLeft = Node(true, true) + n2.topRight = Node(true, true) + n2.bottomLeft = Node(true, true) + n2.bottomRight = Node(true, true) + + val result = Solution().intersect(n1, n2) + assertThat(result?.isLeaf, equalTo(true)) + assertThat(result?.`val`, equalTo(true)) + } } diff --git a/src/test/kotlin/g0701_0800/s0715_range_module/RangeModuleTest.kt b/src/test/kotlin/g0701_0800/s0715_range_module/RangeModuleTest.kt index b45fcbd61..80373a1eb 100644 --- a/src/test/kotlin/g0701_0800/s0715_range_module/RangeModuleTest.kt +++ b/src/test/kotlin/g0701_0800/s0715_range_module/RangeModuleTest.kt @@ -14,4 +14,86 @@ internal class RangeModuleTest { assertThat(rangeModule.queryRange(13, 15), equalTo(false)) assertThat(rangeModule.queryRange(16, 17), equalTo(true)) } + + @Test + fun solutionTest2() { + val rm = RangeModule() + rm.addRange(5, 10) + rm.addRange(10, 15) + assertThat(rm.queryRange(6, 14), equalTo(true)) + } + + @Test + fun solutionTest3() { + val rm = RangeModule() + rm.addRange(1, 5) + rm.addRange(3, 7) + rm.addRange(6, 10) + assertThat(rm.queryRange(2, 9), equalTo(true)) + assertThat(rm.queryRange(0, 2), equalTo(false)) + } + + @Test + fun solutionTest4() { + val rm = RangeModule() + rm.addRange(0, 10) + rm.removeRange(3, 7) + assertThat(rm.queryRange(1, 3), equalTo(true)) + assertThat(rm.queryRange(7, 9), equalTo(true)) + assertThat(rm.queryRange(4, 6), equalTo(false)) + } + + @Test + fun solutionTest5() { + val rm = RangeModule() + rm.addRange(5, 8) + rm.removeRange(0, 20) + assertThat(rm.queryRange(5, 7), equalTo(false)) + } + + @Test + fun solutionTest6() { + val rm = RangeModule() + rm.addRange(10, 20) + rm.removeRange(5, 12) + assertThat(rm.queryRange(10, 12), equalTo(false)) + assertThat(rm.queryRange(12, 15), equalTo(true)) + } + + @Test + fun solutionTest7() { + val rm = RangeModule() + rm.addRange(10, 20) + rm.removeRange(18, 30) + assertThat(rm.queryRange(17, 18), equalTo(true)) + assertThat(rm.queryRange(18, 19), equalTo(false)) + } + + @Test + fun solutionTest8() { + val rm = RangeModule() + rm.removeRange(5, 10) + assertThat(rm.queryRange(5, 6), equalTo(false)) + } + + @Test + fun solutionTest9() { + val rm = RangeModule() + rm.addRange(5, 7) + rm.addRange(10, 12) + assertThat(rm.queryRange(6, 7), equalTo(true)) + assertThat(rm.queryRange(8, 9), equalTo(false)) + assertThat(rm.queryRange(11, 12), equalTo(true)) + } + + @Test + fun solutionTest10() { + val rm = RangeModule() + rm.addRange(1, 5) + rm.addRange(10, 15) + rm.removeRange(3, 12) + assertThat(rm.queryRange(2, 3), equalTo(true)) + assertThat(rm.queryRange(3, 4), equalTo(false)) + assertThat(rm.queryRange(12, 14), equalTo(true)) + } } diff --git a/src/test/kotlin/g1501_1600/s1520_maximum_number_of_non_overlapping_substrings/SolutionTest.kt b/src/test/kotlin/g1501_1600/s1520_maximum_number_of_non_overlapping_substrings/SolutionTest.kt index 4fb5a064c..dd45d222f 100644 --- a/src/test/kotlin/g1501_1600/s1520_maximum_number_of_non_overlapping_substrings/SolutionTest.kt +++ b/src/test/kotlin/g1501_1600/s1520_maximum_number_of_non_overlapping_substrings/SolutionTest.kt @@ -20,4 +20,52 @@ internal class SolutionTest { equalTo(mutableListOf("bb", "cc", "d")), ) } + + @Test + fun maxNumOfSubstrings3() { + val result = Solution().maxNumOfSubstrings("a") + assertThat(result, equalTo(listOf("a"))) + } + + @Test + fun maxNumOfSubstrings4() { + val result = Solution().maxNumOfSubstrings("abc") + assertThat(result, equalTo(listOf("a", "b", "c"))) + } + + @Test + fun maxNumOfSubstrings5() { + val result = Solution().maxNumOfSubstrings("abac") + assertThat(result, equalTo(listOf("b", "c"))) + } + + @Test + fun maxNumOfSubstrings6() { + val result = Solution().maxNumOfSubstrings("bba") + assertThat(result, equalTo(listOf("bb", "a"))) + } + + @Test + fun maxNumOfSubstrings7() { + val result = Solution().maxNumOfSubstrings("abcabc") + assertThat(result, equalTo(listOf("abcabc"))) + } + + @Test + fun maxNumOfSubstrings8() { + val result = Solution().maxNumOfSubstrings("aaaa") + assertThat(result, equalTo(listOf("aaaa"))) + } + + @Test + fun maxNumOfSubstrings9() { + val result = Solution().maxNumOfSubstrings("") + assertThat(result, equalTo(emptyList())) + } + + @Test + fun maxNumOfSubstrings10() { + val result = Solution().maxNumOfSubstrings("cabcccbaa") + assertThat(result, equalTo(listOf("cabcccbaa"))) + } } diff --git a/src/test/kotlin/g2501_2600/s2540_minimum_common_value/SolutionTest.kt b/src/test/kotlin/g2501_2600/s2540_minimum_common_value/SolutionTest.kt index 758c6f944..5f56b49f9 100644 --- a/src/test/kotlin/g2501_2600/s2540_minimum_common_value/SolutionTest.kt +++ b/src/test/kotlin/g2501_2600/s2540_minimum_common_value/SolutionTest.kt @@ -20,4 +20,58 @@ internal class SolutionTest { equalTo(2), ) } + + @Test + fun common3() { + val result = Solution().getCommon(intArrayOf(1, 2, 3), intArrayOf(4, 5, 6)) + assertThat(result, equalTo(-1)) + } + + @Test + fun common4() { + val result = Solution().getCommon(intArrayOf(1, 3, 5, 7), intArrayOf(0, 2, 4, 7)) + assertThat(result, equalTo(7)) + } + + @Test + fun common5() { + val result = Solution().getCommon(intArrayOf(2, 3, 4), intArrayOf(2, 5, 6)) + assertThat(result, equalTo(2)) + } + + @Test + fun common6() { + val result = Solution().getCommon(intArrayOf(5), intArrayOf(5)) + assertThat(result, equalTo(5)) + } + + @Test + fun common7() { + val result = Solution().getCommon(intArrayOf(5), intArrayOf(6)) + assertThat(result, equalTo(-1)) + } + + @Test + fun common8() { + val result = Solution().getCommon(intArrayOf(1, 2, 3, 4), intArrayOf(2, 3, 4)) + assertThat(result, equalTo(2)) + } + + @Test + fun common9() { + val result = Solution().getCommon(intArrayOf(1, 2), intArrayOf(100, 200)) + assertThat(result, equalTo(-1)) + } + + @Test + fun common10() { + val result = Solution().getCommon(intArrayOf(50, 60), intArrayOf(1, 2, 3)) + assertThat(result, equalTo(-1)) + } + + @Test + fun common11() { + val result = Solution().getCommon(intArrayOf(1, 2, 5), intArrayOf(3, 4, 6)) + assertThat(result, equalTo(-1)) + } } diff --git a/src/test/kotlin/g2901_3000/s2905_find_indices_with_index_and_value_difference_ii/SolutionTest.kt b/src/test/kotlin/g2901_3000/s2905_find_indices_with_index_and_value_difference_ii/SolutionTest.kt index 326adb9f4..962c5ee24 100644 --- a/src/test/kotlin/g2901_3000/s2905_find_indices_with_index_and_value_difference_ii/SolutionTest.kt +++ b/src/test/kotlin/g2901_3000/s2905_find_indices_with_index_and_value_difference_ii/SolutionTest.kt @@ -25,4 +25,49 @@ internal class SolutionTest { equalTo(intArrayOf(-1, -1)), ) } + + @Test + fun findIndices4() { + val big = IntArray(100_000) + val result = Solution().findIndices(big, 1, 1_000_000_000) + assertThat(result, equalTo(intArrayOf(49998, 50000))) + } + + @Test + fun findIndices5() { + val big = IntArray(100_001) + val result = Solution().findIndices(big, 2, 100_000) + assertThat(result, equalTo(intArrayOf(-1, -1))) + } + + @Test + fun findIndices6() { + val big = IntArray(100_001) + val result = Solution().findIndices(big, 5, 1_000_000_000) + assertThat(result, equalTo(intArrayOf(-1, -1))) + } + + @Test + fun findIndices7() { + val result = Solution().findIndices(intArrayOf(1, 1, 10), 1, 5) + assertThat(result, equalTo(intArrayOf(0, 2))) + } + + @Test + fun findIndices8() { + val result = Solution().findIndices(intArrayOf(7, 7, 7), 3, 1) + assertThat(result, equalTo(intArrayOf(-1, -1))) + } + + @Test + fun findIndices9() { + val result = Solution().findIndices(intArrayOf(9, 3, 5), 0, 0) + assertThat(result, equalTo(intArrayOf(0, 0))) + } + + @Test + fun findIndices10() { + val result = Solution().findIndices(intArrayOf(3, 10, 3), 1, 7) + assertThat(result, equalTo(intArrayOf(0, 1))) + } } diff --git a/src/test/kotlin/g3501_3600/s3548_equal_sum_grid_partition_ii/SolutionTest.kt b/src/test/kotlin/g3501_3600/s3548_equal_sum_grid_partition_ii/SolutionTest.kt index c7b2243e1..f4eb6804e 100644 --- a/src/test/kotlin/g3501_3600/s3548_equal_sum_grid_partition_ii/SolutionTest.kt +++ b/src/test/kotlin/g3501_3600/s3548_equal_sum_grid_partition_ii/SolutionTest.kt @@ -192,4 +192,113 @@ internal class SolutionTest { ) assertThat(solution.canPartitionGrid(grid), equalTo(true)) } + + @Test + fun canPartitionGrid18() { + val grid = arrayOf( + intArrayOf(3, 3, 1), + ) + assertThat(Solution().canPartitionGrid(grid), equalTo(false)) + } + + @Test + fun canPartitionGrid19() { + val grid = arrayOf( + intArrayOf(100_000, 100_000), + intArrayOf(100_000, 100_000), + ) + assertThat(Solution().canPartitionGrid(grid), equalTo(true)) + } + + @Test + fun canPartitionGrid20() { + val grid = arrayOf( + intArrayOf(1, 2), + intArrayOf(4, 6), + ) + assertThat(Solution().canPartitionGrid(grid), equalTo(false)) + } + + @Test + fun canPartitionGrid21() { + val grid = arrayOf( + intArrayOf(1, 2), + intArrayOf(4, 5), + ) + assertThat(Solution().canPartitionGrid(grid), equalTo(true)) + } + + @Test + fun canPartitionGrid22() { + val grid = arrayOf( + intArrayOf(9, 1, 8), + ) + assertThat(Solution().canPartitionGrid(grid), equalTo(true)) + } + + @Test + fun canPartitionGrid23() { + val grid = arrayOf( + intArrayOf(2, 2), + intArrayOf(2, 2), + intArrayOf(1, 1), + ) + assertThat(Solution().canPartitionGrid(grid), equalTo(true)) + } + + @Test + fun canPartitionGrid24() { + val grid = arrayOf( + intArrayOf(1, 5), + intArrayOf(2, 4), + intArrayOf(3, 3), + ) + assertThat(Solution().canPartitionGrid(grid), equalTo(false)) + } + + @Test + fun canPartitionGrid25() { + val grid = arrayOf( + intArrayOf(1, 1), + intArrayOf(2, 0), + ) + assertThat(Solution().canPartitionGrid(grid), equalTo(true)) + } + + @Test + fun canPartitionGrid26() { + val grid = arrayOf( + intArrayOf(5, 2), + intArrayOf(1, 1), + ) + assertThat(Solution().canPartitionGrid(grid), equalTo(true)) + } + + @Test + fun canPartitionGrid27() { + val grid = arrayOf( + intArrayOf(4), + intArrayOf(1), + intArrayOf(3), + ) + assertThat(Solution().canPartitionGrid(grid), equalTo(true)) + } + + @Test + fun canPartitionGrid28() { + val grid = arrayOf( + intArrayOf(5), + intArrayOf(3), + intArrayOf(2), + ) + assertThat(Solution().canPartitionGrid(grid), equalTo(true)) + } + + @Test + fun canPartitionGrid29() { + val grid = arrayOf( + intArrayOf(2, 2, 4), + ) + assertThat(Solution().canPartitionGrid(grid), equalTo(true)) + } }