diff --git a/src/test/java/g0401_0500/s0441_arranging_coins/SolutionTest.java b/src/test/java/g0401_0500/s0441_arranging_coins/SolutionTest.java index cffac2461..bdca1898d 100644 --- a/src/test/java/g0401_0500/s0441_arranging_coins/SolutionTest.java +++ b/src/test/java/g0401_0500/s0441_arranging_coins/SolutionTest.java @@ -2,6 +2,7 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import org.junit.jupiter.api.Test; @@ -15,4 +16,51 @@ void findKthNumber() { void arrangeCoins2() { assertThat(new Solution().arrangeCoins(8), equalTo(3)); } + + @Test + void arrangeCoins3() { + assertThat(new Solution().arrangeCoins(0), equalTo(0)); + } + + @Test + void arrangeCoins4() { + assertThat(new Solution().arrangeCoins(1), equalTo(1)); + } + + @Test + void arrangeCoins5() { + assertThat(new Solution().arrangeCoins(2), equalTo(1)); + } + + @Test + void arrangeCoins6() { + assertThat(new Solution().arrangeCoins(3), equalTo(2)); + } + + @Test + void arrangeCoins7() { + assertThat(new Solution().arrangeCoins(6), equalTo(3)); + } + + @Test + void arrangeCoins8() { + assertThat(new Solution().arrangeCoins(2147483647), equalTo(65535)); + } + + @Test + void arrangeCoins9() { + assertThat(new Solution().arrangeCoins(7), equalTo(3)); + } + + @Test + void arrangeCoins10() { + Solution solution = new Solution(); + + Exception exception = + assertThrows(IllegalArgumentException.class, () -> solution.arrangeCoins(-5)); + + assertThat( + exception.getMessage(), + equalTo("Input Number is invalid. Only positive numbers are allowed")); + } } diff --git a/src/test/java/g0801_0900/s0836_rectangle_overlap/SolutionTest.java b/src/test/java/g0801_0900/s0836_rectangle_overlap/SolutionTest.java index 48e7d22f8..617eafb6a 100644 --- a/src/test/java/g0801_0900/s0836_rectangle_overlap/SolutionTest.java +++ b/src/test/java/g0801_0900/s0836_rectangle_overlap/SolutionTest.java @@ -26,4 +26,47 @@ void isRectangleOverlap3() { new Solution().isRectangleOverlap(new int[] {0, 0, 1, 1}, new int[] {2, 2, 3, 3}), equalTo(false)); } + + @Test + void isRectangleOverlap4() { + assertThat( + new Solution().isRectangleOverlap(new int[] {0, 0, 2, 2}, new int[] {0, 2, 2, 4}), + equalTo(false)); + } + + @Test + void isRectangleOverlap5() { + assertThat( + new Solution().isRectangleOverlap(new int[] {1, 1, 3, 3}, new int[] {1, 0, 3, 1}), + equalTo(false)); + } + + @Test + void isRectangleOverlap6() { + assertThat( + new Solution() + .isRectangleOverlap(new int[] {-3, -3, -1, -1}, new int[] {-2, -2, 0, 0}), + equalTo(true)); + } + + @Test + void isRectangleOverlap7() { + assertThat( + new Solution().isRectangleOverlap(new int[] {0, 0, 4, 4}, new int[] {1, 1, 3, 3}), + equalTo(true)); + } + + @Test + void isRectangleOverlap8() { + assertThat( + new Solution().isRectangleOverlap(new int[] {0, 0, 2, 2}, new int[] {0, 0, 2, 2}), + equalTo(true)); + } + + @Test + void isRectangleOverlap9() { + assertThat( + new Solution().isRectangleOverlap(new int[] {0, 0, 1, 1}, new int[] {1, 1, 2, 2}), + equalTo(false)); + } } diff --git a/src/test/java/g0801_0900/s0840_magic_squares_in_grid/SolutionTest.java b/src/test/java/g0801_0900/s0840_magic_squares_in_grid/SolutionTest.java index b8d0dcd73..dfc7c1d31 100644 --- a/src/test/java/g0801_0900/s0840_magic_squares_in_grid/SolutionTest.java +++ b/src/test/java/g0801_0900/s0840_magic_squares_in_grid/SolutionTest.java @@ -19,4 +19,64 @@ void numMagicSquaresInside() { void numMagicSquaresInside2() { assertThat(new Solution().numMagicSquaresInside(new int[][] {{8}}), equalTo(0)); } + + @Test + void numMagicSquaresInside3() { + assertThat(new Solution().numMagicSquaresInside(new int[][] {{1, 2}, {3, 4}}), equalTo(0)); + } + + @Test + void numMagicSquaresInside4() { + assertThat( + new Solution() + .numMagicSquaresInside( + new int[][] { + {4, 3, 8, 4, 3}, + {9, 5, 1, 9, 5}, + {2, 7, 6, 2, 7}, + {4, 3, 8, 4, 3}, + {9, 5, 1, 9, 5} + }), + equalTo(1)); + } + + @Test + void numMagicSquaresInside5() { + assertThat( + new Solution() + .numMagicSquaresInside( + new int[][] { + {10, 3, 8}, + {9, 5, 1}, + {2, 7, 6} + }), + equalTo(0)); + } + + @Test + void numMagicSquaresInside6() { + assertThat( + new Solution() + .numMagicSquaresInside( + new int[][] { + {4, 3, 8, 4}, + {9, 5, 1, 9}, + {2, 7, 6, 2}, + {4, 3, 8, 4} + }), + equalTo(1)); + } + + @Test + void numMagicSquaresInside7() { + assertThat( + new Solution() + .numMagicSquaresInside( + new int[][] { + {2, 2, 2}, + {2, 2, 2}, + {2, 2, 2} + }), + equalTo(0)); + } } diff --git a/src/test/java/g0801_0900/s0863_all_nodes_distance_k_in_binary_tree/SolutionTest.java b/src/test/java/g0801_0900/s0863_all_nodes_distance_k_in_binary_tree/SolutionTest.java index 0ad390e13..7ab724137 100644 --- a/src/test/java/g0801_0900/s0863_all_nodes_distance_k_in_binary_tree/SolutionTest.java +++ b/src/test/java/g0801_0900/s0863_all_nodes_distance_k_in_binary_tree/SolutionTest.java @@ -32,4 +32,40 @@ void distanceK2() { 3), equalTo(Collections.emptyList())); } + + @Test + void distanceK3() { + TreeNode root = + TreeUtils.constructBinaryTree(Arrays.asList(3, 5, 1, 6, 2, 0, 8, null, null, 7, 4)); + assertThat( + new Solution().distanceK(root, new TreeNode(3), 2), + equalTo(Arrays.asList(6, 2, 0, 8))); + } + + @Test + void distanceK4() { + TreeNode root = + TreeUtils.constructBinaryTree(Arrays.asList(3, 5, 1, 6, 2, 0, 8, null, null, 7, 4)); + assertThat(new Solution().distanceK(root, new TreeNode(7), 1), equalTo(Arrays.asList(2))); + } + + @Test + void distanceK5() { + TreeNode root = TreeUtils.constructBinaryTree(Arrays.asList(1, 2, 3)); + assertThat(new Solution().distanceK(root, new TreeNode(2), 0), equalTo(Arrays.asList(2))); + } + + @Test + void distanceK6() { + TreeNode root = TreeUtils.constructBinaryTree(Arrays.asList(1, 2, 3)); + assertThat( + new Solution().distanceK(root, new TreeNode(1), 5), + equalTo(Collections.emptyList())); + } + + @Test + void distanceK7() { + TreeNode root = TreeUtils.constructBinaryTree(Arrays.asList(1, 2, null, 3, null, 4)); + assertThat(new Solution().distanceK(root, new TreeNode(2), 2), equalTo(Arrays.asList(4))); + } } diff --git a/src/test/java/g3001_3100/s3040_maximum_number_of_operations_with_the_same_score_ii/SolutionTest.java b/src/test/java/g3001_3100/s3040_maximum_number_of_operations_with_the_same_score_ii/SolutionTest.java index d4e9c939a..4120a1376 100644 --- a/src/test/java/g3001_3100/s3040_maximum_number_of_operations_with_the_same_score_ii/SolutionTest.java +++ b/src/test/java/g3001_3100/s3040_maximum_number_of_operations_with_the_same_score_ii/SolutionTest.java @@ -15,4 +15,44 @@ void maxOperations() { void maxOperations2() { assertThat(new Solution().maxOperations(new int[] {3, 2, 6, 1, 4}), equalTo(2)); } + + @Test + void maxOperations3() { + assertThat(new Solution().maxOperations(new int[] {1, 2}), equalTo(1)); + } + + @Test + void maxOperations4() { + assertThat(new Solution().maxOperations(new int[] {1, 1, 1}), equalTo(1)); + } + + @Test + void maxOperations5() { + assertThat(new Solution().maxOperations(new int[] {2, 2, 2, 2, 2, 2}), equalTo(3)); + } + + @Test + void maxOperations6() { + assertThat(new Solution().maxOperations(new int[] {1, 2, 3, 4, 5, 6}), equalTo(3)); + } + + @Test + void maxOperations7() { + assertThat(new Solution().maxOperations(new int[] {6, 5, 4, 3, 2, 1}), equalTo(3)); + } + + @Test + void maxOperations8() { + assertThat(new Solution().maxOperations(new int[] {1, 3, 2, 4, 1, 3}), equalTo(2)); + } + + @Test + void maxOperations9() { + assertThat(new Solution().maxOperations(new int[] {1, 2, 4, 5}), equalTo(2)); + } + + @Test + void maxOperations10() { + assertThat(new Solution().maxOperations(new int[] {5, 5}), equalTo(1)); + } }