Skip to content

Commit 1d51e97

Browse files
authored
Added tests for tasks 558-3548
1 parent 0c847b5 commit 1d51e97

File tree

6 files changed

+331
-0
lines changed

6 files changed

+331
-0
lines changed

src/test/java/g0501_0600/s0558_logical_or_of_two_binary_grids_represented_as_quad_trees/SolutionTest.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,52 @@ void intersect() {
2626
new Solution().intersect(node1, node2).toString(),
2727
equalTo("[0,0][1,1][1,1][1,1][1,0]"));
2828
}
29+
30+
@Test
31+
void intersect2() {
32+
Node n1 = new Node(true, true);
33+
Node n2 = new Node(true, true);
34+
assertThat(new Solution().intersect(n1, n2), equalTo(n1));
35+
}
36+
37+
@Test
38+
void intersect3() {
39+
Node n1 = new Node(true, true);
40+
Node n2 = new Node(false, false);
41+
assertThat(new Solution().intersect(n1, n2), equalTo(n1));
42+
}
43+
44+
@Test
45+
void intersect4() {
46+
Node n1 = new Node(false, false);
47+
Node n2 = new Node(true, true);
48+
assertThat(new Solution().intersect(n1, n2), equalTo(n2));
49+
}
50+
51+
@Test
52+
void intersect5() {
53+
Node n1 = new Node(true, false);
54+
Node n2 = new Node(true, true);
55+
assertThat(new Solution().intersect(n1, n2), equalTo(n2));
56+
}
57+
58+
@Test
59+
void intersect6() {
60+
Node a = new Node(true, true);
61+
Node n1 = new Node(false, false);
62+
n1.topLeft = a;
63+
n1.topRight = a;
64+
n1.bottomLeft = a;
65+
n1.bottomRight = a;
66+
67+
Node n2 = new Node(false, false);
68+
n2.topLeft = new Node(true, true);
69+
n2.topRight = new Node(true, true);
70+
n2.bottomLeft = new Node(true, true);
71+
n2.bottomRight = new Node(true, true);
72+
73+
Node result = new Solution().intersect(n1, n2);
74+
assertThat(result.isLeaf, equalTo(true));
75+
assertThat(result.val, equalTo(true));
76+
}
2977
}

src/test/java/g0701_0800/s0715_range_module/RangeModuleTest.java

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,87 @@ void solutionTest() {
1515
assertThat(rangeModule.queryRange(13, 15), equalTo(false));
1616
assertThat(rangeModule.queryRange(16, 17), equalTo(true));
1717
}
18+
19+
@Test
20+
void solutionTest2() {
21+
RangeModule rm = new RangeModule();
22+
rm.addRange(5, 10);
23+
rm.addRange(10, 15);
24+
assertThat(rm.queryRange(6, 14), equalTo(true));
25+
}
26+
27+
@Test
28+
void solutionTest3() {
29+
RangeModule rm = new RangeModule();
30+
rm.addRange(1, 5);
31+
rm.addRange(3, 7);
32+
rm.addRange(6, 10);
33+
assertThat(rm.queryRange(2, 9), equalTo(true));
34+
assertThat(rm.queryRange(0, 2), equalTo(false));
35+
}
36+
37+
@Test
38+
void solutionTest4() {
39+
RangeModule rm = new RangeModule();
40+
rm.addRange(0, 10);
41+
rm.removeRange(3, 7);
42+
assertThat(rm.queryRange(1, 3), equalTo(true));
43+
assertThat(rm.queryRange(7, 9), equalTo(true));
44+
assertThat(rm.queryRange(4, 6), equalTo(false));
45+
}
46+
47+
@Test
48+
void solutionTest5() {
49+
RangeModule rm = new RangeModule();
50+
rm.addRange(5, 8);
51+
rm.removeRange(0, 20);
52+
assertThat(rm.queryRange(5, 7), equalTo(false));
53+
}
54+
55+
@Test
56+
void solutionTest6() {
57+
RangeModule rm = new RangeModule();
58+
rm.addRange(10, 20);
59+
rm.removeRange(5, 12);
60+
assertThat(rm.queryRange(10, 12), equalTo(false));
61+
assertThat(rm.queryRange(12, 15), equalTo(true));
62+
}
63+
64+
@Test
65+
void solutionTest7() {
66+
RangeModule rm = new RangeModule();
67+
rm.addRange(10, 20);
68+
rm.removeRange(18, 30);
69+
assertThat(rm.queryRange(17, 18), equalTo(true));
70+
assertThat(rm.queryRange(18, 19), equalTo(false));
71+
}
72+
73+
@Test
74+
void solutionTest8() {
75+
RangeModule rm = new RangeModule();
76+
rm.removeRange(5, 10);
77+
assertThat(rm.queryRange(5, 6), equalTo(false));
78+
}
79+
80+
@Test
81+
void solutionTest9() {
82+
RangeModule rm = new RangeModule();
83+
rm.addRange(5, 7);
84+
rm.addRange(10, 12);
85+
assertThat(rm.queryRange(6, 7), equalTo(true));
86+
assertThat(rm.queryRange(8, 9), equalTo(false));
87+
assertThat(rm.queryRange(11, 12), equalTo(true));
88+
}
89+
90+
@Test
91+
void solutionTest10() {
92+
RangeModule rm = new RangeModule();
93+
rm.addRange(1, 5);
94+
rm.addRange(10, 15);
95+
rm.removeRange(3, 12);
96+
97+
assertThat(rm.queryRange(2, 3), equalTo(true));
98+
assertThat(rm.queryRange(3, 4), equalTo(false));
99+
assertThat(rm.queryRange(12, 14), equalTo(true));
100+
}
18101
}

src/test/java/g1501_1600/s1520_maximum_number_of_non_overlapping_substrings/SolutionTest.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static org.hamcrest.MatcherAssert.assertThat;
55

66
import java.util.Arrays;
7+
import java.util.Collections;
78
import org.junit.jupiter.api.Test;
89

910
class SolutionTest {
@@ -20,4 +21,46 @@ void maxNumOfSubstrings2() {
2021
new Solution().maxNumOfSubstrings("abbaccd"),
2122
equalTo(Arrays.asList("bb", "cc", "d")));
2223
}
24+
25+
@Test
26+
void maxNumOfSubstrings3() {
27+
assertThat(new Solution().maxNumOfSubstrings("a"), equalTo(Arrays.asList("a")));
28+
}
29+
30+
@Test
31+
void maxNumOfSubstrings4() {
32+
assertThat(new Solution().maxNumOfSubstrings("abc"), equalTo(Arrays.asList("a", "b", "c")));
33+
}
34+
35+
@Test
36+
void maxNumOfSubstrings5() {
37+
assertThat(new Solution().maxNumOfSubstrings("abac"), equalTo(Arrays.asList("b", "c")));
38+
}
39+
40+
@Test
41+
void maxNumOfSubstrings6() {
42+
assertThat(new Solution().maxNumOfSubstrings("bba"), equalTo(Arrays.asList("bb", "a")));
43+
}
44+
45+
@Test
46+
void maxNumOfSubstrings7() {
47+
assertThat(new Solution().maxNumOfSubstrings("abcabc"), equalTo(Arrays.asList("abcabc")));
48+
}
49+
50+
@Test
51+
void maxNumOfSubstrings8() {
52+
assertThat(new Solution().maxNumOfSubstrings("aaaa"), equalTo(Arrays.asList("aaaa")));
53+
}
54+
55+
@Test
56+
void maxNumOfSubstrings9() {
57+
assertThat(new Solution().maxNumOfSubstrings(""), equalTo(Collections.emptyList()));
58+
}
59+
60+
@Test
61+
void maxNumOfSubstrings10() {
62+
assertThat(
63+
new Solution().maxNumOfSubstrings("cabcccbaa"),
64+
equalTo(Arrays.asList("cabcccbaa")));
65+
}
2366
}

src/test/java/g2501_2600/s2540_minimum_common_value/SolutionTest.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,52 @@ void getCommon2() {
1717
new Solution().getCommon(new int[] {1, 2, 3, 6}, new int[] {2, 3, 4, 5}),
1818
equalTo(2));
1919
}
20+
21+
@Test
22+
void getCommon3() {
23+
assertThat(new Solution().getCommon(new int[] {1, 2, 3}, new int[] {4, 5, 6}), equalTo(-1));
24+
}
25+
26+
@Test
27+
void getCommon4() {
28+
assertThat(
29+
new Solution().getCommon(new int[] {1, 3, 5, 7}, new int[] {0, 2, 4, 7}),
30+
equalTo(7));
31+
}
32+
33+
@Test
34+
void getCommon5() {
35+
assertThat(new Solution().getCommon(new int[] {2, 3, 4}, new int[] {2, 5, 6}), equalTo(2));
36+
}
37+
38+
@Test
39+
void getCommon6() {
40+
assertThat(new Solution().getCommon(new int[] {5}, new int[] {5}), equalTo(5));
41+
}
42+
43+
@Test
44+
void getCommon7() {
45+
assertThat(new Solution().getCommon(new int[] {5}, new int[] {6}), equalTo(-1));
46+
}
47+
48+
@Test
49+
void getCommon8() {
50+
assertThat(
51+
new Solution().getCommon(new int[] {1, 2, 3, 4}, new int[] {2, 3, 4}), equalTo(2));
52+
}
53+
54+
@Test
55+
void getCommon9() {
56+
assertThat(new Solution().getCommon(new int[] {1, 2}, new int[] {100, 200}), equalTo(-1));
57+
}
58+
59+
@Test
60+
void getCommon10() {
61+
assertThat(new Solution().getCommon(new int[] {50, 60}, new int[] {1, 2, 3}), equalTo(-1));
62+
}
63+
64+
@Test
65+
void getCommon11() {
66+
assertThat(new Solution().getCommon(new int[] {1, 2, 5}, new int[] {3, 4, 6}), equalTo(-1));
67+
}
2068
}

src/test/java/g2901_3000/s2905_find_indices_with_index_and_value_difference_ii/SolutionTest.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,48 @@ void findIndices3() {
2323
assertThat(
2424
new Solution().findIndices(new int[] {1, 2, 3}, 2, 4), equalTo(new int[] {-1, -1}));
2525
}
26+
27+
@Test
28+
void findIndices4() {
29+
int[] big = new int[100000];
30+
assertThat(
31+
new Solution().findIndices(big, 1, 1_000_000_000),
32+
equalTo(new int[] {49998, 50000}));
33+
}
34+
35+
@Test
36+
void findIndices5() {
37+
int[] big = new int[100001];
38+
assertThat(new Solution().findIndices(big, 2, 100000), equalTo(new int[] {-1, -1}));
39+
}
40+
41+
@Test
42+
void findIndices6() {
43+
int[] big = new int[100001];
44+
assertThat(new Solution().findIndices(big, 5, 1_000_000_000), equalTo(new int[] {-1, -1}));
45+
}
46+
47+
@Test
48+
void findIndices7() {
49+
assertThat(
50+
new Solution().findIndices(new int[] {1, 1, 10}, 1, 5), equalTo(new int[] {0, 2}));
51+
}
52+
53+
@Test
54+
void findIndices8() {
55+
assertThat(
56+
new Solution().findIndices(new int[] {7, 7, 7}, 3, 1), equalTo(new int[] {-1, -1}));
57+
}
58+
59+
@Test
60+
void findIndices9() {
61+
assertThat(
62+
new Solution().findIndices(new int[] {9, 3, 5}, 0, 0), equalTo(new int[] {0, 0}));
63+
}
64+
65+
@Test
66+
void findIndices10() {
67+
assertThat(
68+
new Solution().findIndices(new int[] {3, 10, 3}, 1, 7), equalTo(new int[] {0, 1}));
69+
}
2670
}

src/test/java/g3501_3600/s3548_equal_sum_grid_partition_ii/SolutionTest.java

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,69 @@ void canPartitionGrid11() {
7474
new int[][] {{2, 40, 2}, {4, 2, 3}, {5, 1, 6}, {7, 8, 9}}),
7575
equalTo(true));
7676
}
77+
78+
@Test
79+
void canPartitionGrid12() {
80+
assertThat(
81+
new Solution().canPartitionGrid(new int[][] {{1, 5}, {2, 4}, {3, 3}}),
82+
equalTo(false));
83+
}
84+
85+
@Test
86+
void canPartitionGrid13() {
87+
assertThat(new Solution().canPartitionGrid(new int[][] {{1, 1}, {2, 0}}), equalTo(true));
88+
}
89+
90+
@Test
91+
void canPartitionGrid14() {
92+
assertThat(new Solution().canPartitionGrid(new int[][] {{5, 2}, {1, 1}}), equalTo(true));
93+
}
94+
95+
@Test
96+
void canPartitionGrid15() {
97+
assertThat(new Solution().canPartitionGrid(new int[][] {{4}, {1}, {3}}), equalTo(true));
98+
}
99+
100+
@Test
101+
void canPartitionGrid16() {
102+
assertThat(new Solution().canPartitionGrid(new int[][] {{5}, {3}, {2}}), equalTo(true));
103+
}
104+
105+
@Test
106+
void canPartitionGrid17() {
107+
assertThat(new Solution().canPartitionGrid(new int[][] {{2, 2, 4}}), equalTo(true));
108+
}
109+
110+
@Test
111+
void canPartitionGrid18() {
112+
assertThat(new Solution().canPartitionGrid(new int[][] {{3, 3, 1}}), equalTo(false));
113+
}
114+
115+
@Test
116+
void canPartitionGrid19() {
117+
int[][] grid = {{100000, 100000}, {100000, 100000}};
118+
assertThat(new Solution().canPartitionGrid(grid), equalTo(true));
119+
}
120+
121+
@Test
122+
void canPartitionGrid20() {
123+
assertThat(new Solution().canPartitionGrid(new int[][] {{1, 2}, {4, 6}}), equalTo(false));
124+
}
125+
126+
@Test
127+
void canPartitionGrid21() {
128+
assertThat(new Solution().canPartitionGrid(new int[][] {{1, 2}, {4, 5}}), equalTo(true));
129+
}
130+
131+
@Test
132+
void canPartitionGrid22() {
133+
assertThat(new Solution().canPartitionGrid(new int[][] {{9, 1, 8}}), equalTo(true));
134+
}
135+
136+
@Test
137+
void canPartitionGrid23() {
138+
assertThat(
139+
new Solution().canPartitionGrid(new int[][] {{2, 2}, {2, 2}, {1, 1}}),
140+
equalTo(true));
141+
}
77142
}

0 commit comments

Comments
 (0)