Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1d51e97

Browse files
authored
Added tests for tasks 558-3548
1 parent0c847b5 commit1d51e97

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
newSolution().intersect(node1,node2).toString(),
2727
equalTo("[0,0][1,1][1,1][1,1][1,0]"));
2828
}
29+
30+
@Test
31+
voidintersect2() {
32+
Noden1 =newNode(true,true);
33+
Noden2 =newNode(true,true);
34+
assertThat(newSolution().intersect(n1,n2),equalTo(n1));
35+
}
36+
37+
@Test
38+
voidintersect3() {
39+
Noden1 =newNode(true,true);
40+
Noden2 =newNode(false,false);
41+
assertThat(newSolution().intersect(n1,n2),equalTo(n1));
42+
}
43+
44+
@Test
45+
voidintersect4() {
46+
Noden1 =newNode(false,false);
47+
Noden2 =newNode(true,true);
48+
assertThat(newSolution().intersect(n1,n2),equalTo(n2));
49+
}
50+
51+
@Test
52+
voidintersect5() {
53+
Noden1 =newNode(true,false);
54+
Noden2 =newNode(true,true);
55+
assertThat(newSolution().intersect(n1,n2),equalTo(n2));
56+
}
57+
58+
@Test
59+
voidintersect6() {
60+
Nodea =newNode(true,true);
61+
Noden1 =newNode(false,false);
62+
n1.topLeft =a;
63+
n1.topRight =a;
64+
n1.bottomLeft =a;
65+
n1.bottomRight =a;
66+
67+
Noden2 =newNode(false,false);
68+
n2.topLeft =newNode(true,true);
69+
n2.topRight =newNode(true,true);
70+
n2.bottomLeft =newNode(true,true);
71+
n2.bottomRight =newNode(true,true);
72+
73+
Noderesult =newSolution().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+
voidsolutionTest2() {
21+
RangeModulerm =newRangeModule();
22+
rm.addRange(5,10);
23+
rm.addRange(10,15);
24+
assertThat(rm.queryRange(6,14),equalTo(true));
25+
}
26+
27+
@Test
28+
voidsolutionTest3() {
29+
RangeModulerm =newRangeModule();
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+
voidsolutionTest4() {
39+
RangeModulerm =newRangeModule();
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+
voidsolutionTest5() {
49+
RangeModulerm =newRangeModule();
50+
rm.addRange(5,8);
51+
rm.removeRange(0,20);
52+
assertThat(rm.queryRange(5,7),equalTo(false));
53+
}
54+
55+
@Test
56+
voidsolutionTest6() {
57+
RangeModulerm =newRangeModule();
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+
voidsolutionTest7() {
66+
RangeModulerm =newRangeModule();
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+
voidsolutionTest8() {
75+
RangeModulerm =newRangeModule();
76+
rm.removeRange(5,10);
77+
assertThat(rm.queryRange(5,6),equalTo(false));
78+
}
79+
80+
@Test
81+
voidsolutionTest9() {
82+
RangeModulerm =newRangeModule();
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+
voidsolutionTest10() {
92+
RangeModulerm =newRangeModule();
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
importstaticorg.hamcrest.MatcherAssert.assertThat;
55

66
importjava.util.Arrays;
7+
importjava.util.Collections;
78
importorg.junit.jupiter.api.Test;
89

910
classSolutionTest {
@@ -20,4 +21,46 @@ void maxNumOfSubstrings2() {
2021
newSolution().maxNumOfSubstrings("abbaccd"),
2122
equalTo(Arrays.asList("bb","cc","d")));
2223
}
24+
25+
@Test
26+
voidmaxNumOfSubstrings3() {
27+
assertThat(newSolution().maxNumOfSubstrings("a"),equalTo(Arrays.asList("a")));
28+
}
29+
30+
@Test
31+
voidmaxNumOfSubstrings4() {
32+
assertThat(newSolution().maxNumOfSubstrings("abc"),equalTo(Arrays.asList("a","b","c")));
33+
}
34+
35+
@Test
36+
voidmaxNumOfSubstrings5() {
37+
assertThat(newSolution().maxNumOfSubstrings("abac"),equalTo(Arrays.asList("b","c")));
38+
}
39+
40+
@Test
41+
voidmaxNumOfSubstrings6() {
42+
assertThat(newSolution().maxNumOfSubstrings("bba"),equalTo(Arrays.asList("bb","a")));
43+
}
44+
45+
@Test
46+
voidmaxNumOfSubstrings7() {
47+
assertThat(newSolution().maxNumOfSubstrings("abcabc"),equalTo(Arrays.asList("abcabc")));
48+
}
49+
50+
@Test
51+
voidmaxNumOfSubstrings8() {
52+
assertThat(newSolution().maxNumOfSubstrings("aaaa"),equalTo(Arrays.asList("aaaa")));
53+
}
54+
55+
@Test
56+
voidmaxNumOfSubstrings9() {
57+
assertThat(newSolution().maxNumOfSubstrings(""),equalTo(Collections.emptyList()));
58+
}
59+
60+
@Test
61+
voidmaxNumOfSubstrings10() {
62+
assertThat(
63+
newSolution().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
newSolution().getCommon(newint[] {1,2,3,6},newint[] {2,3,4,5}),
1818
equalTo(2));
1919
}
20+
21+
@Test
22+
voidgetCommon3() {
23+
assertThat(newSolution().getCommon(newint[] {1,2,3},newint[] {4,5,6}),equalTo(-1));
24+
}
25+
26+
@Test
27+
voidgetCommon4() {
28+
assertThat(
29+
newSolution().getCommon(newint[] {1,3,5,7},newint[] {0,2,4,7}),
30+
equalTo(7));
31+
}
32+
33+
@Test
34+
voidgetCommon5() {
35+
assertThat(newSolution().getCommon(newint[] {2,3,4},newint[] {2,5,6}),equalTo(2));
36+
}
37+
38+
@Test
39+
voidgetCommon6() {
40+
assertThat(newSolution().getCommon(newint[] {5},newint[] {5}),equalTo(5));
41+
}
42+
43+
@Test
44+
voidgetCommon7() {
45+
assertThat(newSolution().getCommon(newint[] {5},newint[] {6}),equalTo(-1));
46+
}
47+
48+
@Test
49+
voidgetCommon8() {
50+
assertThat(
51+
newSolution().getCommon(newint[] {1,2,3,4},newint[] {2,3,4}),equalTo(2));
52+
}
53+
54+
@Test
55+
voidgetCommon9() {
56+
assertThat(newSolution().getCommon(newint[] {1,2},newint[] {100,200}),equalTo(-1));
57+
}
58+
59+
@Test
60+
voidgetCommon10() {
61+
assertThat(newSolution().getCommon(newint[] {50,60},newint[] {1,2,3}),equalTo(-1));
62+
}
63+
64+
@Test
65+
voidgetCommon11() {
66+
assertThat(newSolution().getCommon(newint[] {1,2,5},newint[] {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
newSolution().findIndices(newint[] {1,2,3},2,4),equalTo(newint[] {-1, -1}));
2525
}
26+
27+
@Test
28+
voidfindIndices4() {
29+
int[]big =newint[100000];
30+
assertThat(
31+
newSolution().findIndices(big,1,1_000_000_000),
32+
equalTo(newint[] {49998,50000}));
33+
}
34+
35+
@Test
36+
voidfindIndices5() {
37+
int[]big =newint[100001];
38+
assertThat(newSolution().findIndices(big,2,100000),equalTo(newint[] {-1, -1}));
39+
}
40+
41+
@Test
42+
voidfindIndices6() {
43+
int[]big =newint[100001];
44+
assertThat(newSolution().findIndices(big,5,1_000_000_000),equalTo(newint[] {-1, -1}));
45+
}
46+
47+
@Test
48+
voidfindIndices7() {
49+
assertThat(
50+
newSolution().findIndices(newint[] {1,1,10},1,5),equalTo(newint[] {0,2}));
51+
}
52+
53+
@Test
54+
voidfindIndices8() {
55+
assertThat(
56+
newSolution().findIndices(newint[] {7,7,7},3,1),equalTo(newint[] {-1, -1}));
57+
}
58+
59+
@Test
60+
voidfindIndices9() {
61+
assertThat(
62+
newSolution().findIndices(newint[] {9,3,5},0,0),equalTo(newint[] {0,0}));
63+
}
64+
65+
@Test
66+
voidfindIndices10() {
67+
assertThat(
68+
newSolution().findIndices(newint[] {3,10,3},1,7),equalTo(newint[] {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
newint[][] {{2,40,2}, {4,2,3}, {5,1,6}, {7,8,9}}),
7575
equalTo(true));
7676
}
77+
78+
@Test
79+
voidcanPartitionGrid12() {
80+
assertThat(
81+
newSolution().canPartitionGrid(newint[][] {{1,5}, {2,4}, {3,3}}),
82+
equalTo(false));
83+
}
84+
85+
@Test
86+
voidcanPartitionGrid13() {
87+
assertThat(newSolution().canPartitionGrid(newint[][] {{1,1}, {2,0}}),equalTo(true));
88+
}
89+
90+
@Test
91+
voidcanPartitionGrid14() {
92+
assertThat(newSolution().canPartitionGrid(newint[][] {{5,2}, {1,1}}),equalTo(true));
93+
}
94+
95+
@Test
96+
voidcanPartitionGrid15() {
97+
assertThat(newSolution().canPartitionGrid(newint[][] {{4}, {1}, {3}}),equalTo(true));
98+
}
99+
100+
@Test
101+
voidcanPartitionGrid16() {
102+
assertThat(newSolution().canPartitionGrid(newint[][] {{5}, {3}, {2}}),equalTo(true));
103+
}
104+
105+
@Test
106+
voidcanPartitionGrid17() {
107+
assertThat(newSolution().canPartitionGrid(newint[][] {{2,2,4}}),equalTo(true));
108+
}
109+
110+
@Test
111+
voidcanPartitionGrid18() {
112+
assertThat(newSolution().canPartitionGrid(newint[][] {{3,3,1}}),equalTo(false));
113+
}
114+
115+
@Test
116+
voidcanPartitionGrid19() {
117+
int[][]grid = {{100000,100000}, {100000,100000}};
118+
assertThat(newSolution().canPartitionGrid(grid),equalTo(true));
119+
}
120+
121+
@Test
122+
voidcanPartitionGrid20() {
123+
assertThat(newSolution().canPartitionGrid(newint[][] {{1,2}, {4,6}}),equalTo(false));
124+
}
125+
126+
@Test
127+
voidcanPartitionGrid21() {
128+
assertThat(newSolution().canPartitionGrid(newint[][] {{1,2}, {4,5}}),equalTo(true));
129+
}
130+
131+
@Test
132+
voidcanPartitionGrid22() {
133+
assertThat(newSolution().canPartitionGrid(newint[][] {{9,1,8}}),equalTo(true));
134+
}
135+
136+
@Test
137+
voidcanPartitionGrid23() {
138+
assertThat(
139+
newSolution().canPartitionGrid(newint[][] {{2,2}, {2,2}, {1,1}}),
140+
equalTo(true));
141+
}
77142
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp