Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,52 @@ void intersect() {
new Solution().intersect(node1, node2).toString(),
equalTo("[0,0][1,1][1,1][1,1][1,0]"));
}

@Test
void intersect2() {
Node n1 = new Node(true, true);
Node n2 = new Node(true, true);
assertThat(new Solution().intersect(n1, n2), equalTo(n1));
}

@Test
void intersect3() {
Node n1 = new Node(true, true);
Node n2 = new Node(false, false);
assertThat(new Solution().intersect(n1, n2), equalTo(n1));
}

@Test
void intersect4() {
Node n1 = new Node(false, false);
Node n2 = new Node(true, true);
assertThat(new Solution().intersect(n1, n2), equalTo(n2));
}

@Test
void intersect5() {
Node n1 = new Node(true, false);
Node n2 = new Node(true, true);
assertThat(new Solution().intersect(n1, n2), equalTo(n2));
}

@Test
void intersect6() {
Node a = new Node(true, true);
Node n1 = new Node(false, false);
n1.topLeft = a;
n1.topRight = a;
n1.bottomLeft = a;
n1.bottomRight = a;

Node n2 = new Node(false, false);
n2.topLeft = new Node(true, true);
n2.topRight = new Node(true, true);
n2.bottomLeft = new Node(true, true);
n2.bottomRight = new Node(true, true);

Node result = new Solution().intersect(n1, n2);
assertThat(result.isLeaf, equalTo(true));
assertThat(result.val, equalTo(true));
}
}
83 changes: 83 additions & 0 deletions src/test/java/g0701_0800/s0715_range_module/RangeModuleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,87 @@ void solutionTest() {
assertThat(rangeModule.queryRange(13, 15), equalTo(false));
assertThat(rangeModule.queryRange(16, 17), equalTo(true));
}

@Test
void solutionTest2() {
RangeModule rm = new RangeModule();
rm.addRange(5, 10);
rm.addRange(10, 15);
assertThat(rm.queryRange(6, 14), equalTo(true));
}

@Test
void solutionTest3() {
RangeModule rm = new 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
void solutionTest4() {
RangeModule rm = new 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
void solutionTest5() {
RangeModule rm = new RangeModule();
rm.addRange(5, 8);
rm.removeRange(0, 20);
assertThat(rm.queryRange(5, 7), equalTo(false));
}

@Test
void solutionTest6() {
RangeModule rm = new RangeModule();
rm.addRange(10, 20);
rm.removeRange(5, 12);
assertThat(rm.queryRange(10, 12), equalTo(false));
assertThat(rm.queryRange(12, 15), equalTo(true));
}

@Test
void solutionTest7() {
RangeModule rm = new RangeModule();
rm.addRange(10, 20);
rm.removeRange(18, 30);
assertThat(rm.queryRange(17, 18), equalTo(true));
assertThat(rm.queryRange(18, 19), equalTo(false));
}

@Test
void solutionTest8() {
RangeModule rm = new RangeModule();
rm.removeRange(5, 10);
assertThat(rm.queryRange(5, 6), equalTo(false));
}

@Test
void solutionTest9() {
RangeModule rm = new 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
void solutionTest10() {
RangeModule rm = new 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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.hamcrest.MatcherAssert.assertThat;

import java.util.Arrays;
import java.util.Collections;
import org.junit.jupiter.api.Test;

class SolutionTest {
Expand All @@ -20,4 +21,46 @@ void maxNumOfSubstrings2() {
new Solution().maxNumOfSubstrings("abbaccd"),
equalTo(Arrays.asList("bb", "cc", "d")));
}

@Test
void maxNumOfSubstrings3() {
assertThat(new Solution().maxNumOfSubstrings("a"), equalTo(Arrays.asList("a")));
}

@Test
void maxNumOfSubstrings4() {
assertThat(new Solution().maxNumOfSubstrings("abc"), equalTo(Arrays.asList("a", "b", "c")));
}

@Test
void maxNumOfSubstrings5() {
assertThat(new Solution().maxNumOfSubstrings("abac"), equalTo(Arrays.asList("b", "c")));
}

@Test
void maxNumOfSubstrings6() {
assertThat(new Solution().maxNumOfSubstrings("bba"), equalTo(Arrays.asList("bb", "a")));
}

@Test
void maxNumOfSubstrings7() {
assertThat(new Solution().maxNumOfSubstrings("abcabc"), equalTo(Arrays.asList("abcabc")));
}

@Test
void maxNumOfSubstrings8() {
assertThat(new Solution().maxNumOfSubstrings("aaaa"), equalTo(Arrays.asList("aaaa")));
}

@Test
void maxNumOfSubstrings9() {
assertThat(new Solution().maxNumOfSubstrings(""), equalTo(Collections.emptyList()));
}

@Test
void maxNumOfSubstrings10() {
assertThat(
new Solution().maxNumOfSubstrings("cabcccbaa"),
equalTo(Arrays.asList("cabcccbaa")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,52 @@ void getCommon2() {
new Solution().getCommon(new int[] {1, 2, 3, 6}, new int[] {2, 3, 4, 5}),
equalTo(2));
}

@Test
void getCommon3() {
assertThat(new Solution().getCommon(new int[] {1, 2, 3}, new int[] {4, 5, 6}), equalTo(-1));
}

@Test
void getCommon4() {
assertThat(
new Solution().getCommon(new int[] {1, 3, 5, 7}, new int[] {0, 2, 4, 7}),
equalTo(7));
}

@Test
void getCommon5() {
assertThat(new Solution().getCommon(new int[] {2, 3, 4}, new int[] {2, 5, 6}), equalTo(2));
}

@Test
void getCommon6() {
assertThat(new Solution().getCommon(new int[] {5}, new int[] {5}), equalTo(5));
}

@Test
void getCommon7() {
assertThat(new Solution().getCommon(new int[] {5}, new int[] {6}), equalTo(-1));
}

@Test
void getCommon8() {
assertThat(
new Solution().getCommon(new int[] {1, 2, 3, 4}, new int[] {2, 3, 4}), equalTo(2));
}

@Test
void getCommon9() {
assertThat(new Solution().getCommon(new int[] {1, 2}, new int[] {100, 200}), equalTo(-1));
}

@Test
void getCommon10() {
assertThat(new Solution().getCommon(new int[] {50, 60}, new int[] {1, 2, 3}), equalTo(-1));
}

@Test
void getCommon11() {
assertThat(new Solution().getCommon(new int[] {1, 2, 5}, new int[] {3, 4, 6}), equalTo(-1));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,48 @@ void findIndices3() {
assertThat(
new Solution().findIndices(new int[] {1, 2, 3}, 2, 4), equalTo(new int[] {-1, -1}));
}

@Test
void findIndices4() {
int[] big = new int[100000];
assertThat(
new Solution().findIndices(big, 1, 1_000_000_000),
equalTo(new int[] {49998, 50000}));
}

@Test
void findIndices5() {
int[] big = new int[100001];
assertThat(new Solution().findIndices(big, 2, 100000), equalTo(new int[] {-1, -1}));
}

@Test
void findIndices6() {
int[] big = new int[100001];
assertThat(new Solution().findIndices(big, 5, 1_000_000_000), equalTo(new int[] {-1, -1}));
}

@Test
void findIndices7() {
assertThat(
new Solution().findIndices(new int[] {1, 1, 10}, 1, 5), equalTo(new int[] {0, 2}));
}

@Test
void findIndices8() {
assertThat(
new Solution().findIndices(new int[] {7, 7, 7}, 3, 1), equalTo(new int[] {-1, -1}));
}

@Test
void findIndices9() {
assertThat(
new Solution().findIndices(new int[] {9, 3, 5}, 0, 0), equalTo(new int[] {0, 0}));
}

@Test
void findIndices10() {
assertThat(
new Solution().findIndices(new int[] {3, 10, 3}, 1, 7), equalTo(new int[] {0, 1}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,69 @@ void canPartitionGrid11() {
new int[][] {{2, 40, 2}, {4, 2, 3}, {5, 1, 6}, {7, 8, 9}}),
equalTo(true));
}

@Test
void canPartitionGrid12() {
assertThat(
new Solution().canPartitionGrid(new int[][] {{1, 5}, {2, 4}, {3, 3}}),
equalTo(false));
}

@Test
void canPartitionGrid13() {
assertThat(new Solution().canPartitionGrid(new int[][] {{1, 1}, {2, 0}}), equalTo(true));
}

@Test
void canPartitionGrid14() {
assertThat(new Solution().canPartitionGrid(new int[][] {{5, 2}, {1, 1}}), equalTo(true));
}

@Test
void canPartitionGrid15() {
assertThat(new Solution().canPartitionGrid(new int[][] {{4}, {1}, {3}}), equalTo(true));
}

@Test
void canPartitionGrid16() {
assertThat(new Solution().canPartitionGrid(new int[][] {{5}, {3}, {2}}), equalTo(true));
}

@Test
void canPartitionGrid17() {
assertThat(new Solution().canPartitionGrid(new int[][] {{2, 2, 4}}), equalTo(true));
}

@Test
void canPartitionGrid18() {
assertThat(new Solution().canPartitionGrid(new int[][] {{3, 3, 1}}), equalTo(false));
}

@Test
void canPartitionGrid19() {
int[][] grid = {{100000, 100000}, {100000, 100000}};
assertThat(new Solution().canPartitionGrid(grid), equalTo(true));
}

@Test
void canPartitionGrid20() {
assertThat(new Solution().canPartitionGrid(new int[][] {{1, 2}, {4, 6}}), equalTo(false));
}

@Test
void canPartitionGrid21() {
assertThat(new Solution().canPartitionGrid(new int[][] {{1, 2}, {4, 5}}), equalTo(true));
}

@Test
void canPartitionGrid22() {
assertThat(new Solution().canPartitionGrid(new int[][] {{9, 1, 8}}), equalTo(true));
}

@Test
void canPartitionGrid23() {
assertThat(
new Solution().canPartitionGrid(new int[][] {{2, 2}, {2, 2}, {1, 1}}),
equalTo(true));
}
}
Loading