Skip to content

Commit 1210b5c

Browse files
committed
Fixed code coverage and updated build parameters
Fixed code coverage and updated build parameters
1 parent 3c9348c commit 1210b5c

File tree

4 files changed

+131
-19
lines changed

4 files changed

+131
-19
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33

44
Leetcode/target/**
55

6-
Leetcode/target/classes/**
6+
/Leetcode/target/classes/**
7+
/Leetcode/target/test-classes/**
8+
Leetcode/target/classes/dev/leetcode/ArrayProblems.class

Leetcode/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
<artifactId>Leetcode</artifactId>
1313

1414
<properties>
15-
<maven.compiler.source>21</maven.compiler.source>
16-
<maven.compiler.target>21</maven.compiler.target>
15+
<maven.compiler.source>17</maven.compiler.source>
16+
<maven.compiler.target>17</maven.compiler.target>
1717
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1818
</properties>
1919

Leetcode/src/test/java/dev/leetcode/StringProblemsTest.java

Lines changed: 124 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
import org.javatuples.Pair;
44
import org.javatuples.Triplet;
5-
import org.junit.jupiter.api.Assertions;
65
import org.junit.jupiter.api.DisplayName;
76
import org.junit.jupiter.api.Test;
87

8+
import static org.junit.jupiter.api.Assertions.*;
9+
910
import java.util.List;
1011
import java.util.Map;
1112

@@ -21,7 +22,7 @@ public void testValidIpAddress() {
2122
);
2223

2324
testcases.forEach(test ->
24-
Assertions.assertEquals(
25+
assertEquals(
2526
test.getValue0(),
2627
problems.defangIpAddress(test.getValue1())
2728
)
@@ -36,7 +37,7 @@ public void testFourOperationsMixed() {
3637
0, List.of("X++","++X","--X","X--"),
3738
3, List.of("++X","++X","X++")
3839
);
39-
testcases.forEach((key, value) -> Assertions.assertEquals(key,
40+
testcases.forEach((key, value) -> assertEquals(key,
4041
problems.finalValueAfterOperations(value.toArray(new String[0]))));
4142
}
4243

@@ -49,7 +50,7 @@ public void testJewelsExists() {
4950
Triplet.with(0, "z", "ZZ")
5051
);
5152
testCases.forEach(t ->
52-
Assertions.assertEquals(
53+
assertEquals(
5354
t.getValue(0),
5455
problems.numJewelsInStones(t.getValue1(), t.getValue2()))
5556
);
@@ -66,7 +67,7 @@ public void testAllWordsContainingChar() {
6667
);
6768

6869
testcases.forEach(test ->
69-
Assertions.assertEquals(
70+
assertEquals(
7071
test.getValue0(),
7172
problems.findWordsContaining(
7273
test.getValue1().toArray(new String[0]),
@@ -82,7 +83,7 @@ public void testParseCommand1() {
8283
Pair.with("alGalooG", "(al)G(al)()()G")
8384
);
8485
testcases.forEach(test ->
85-
Assertions.assertEquals(test.getValue0(), problems.interpret(test.getValue1()))
86+
assertEquals(test.getValue0(), problems.interpret(test.getValue1()))
8687
);
8788
}
8889

@@ -95,7 +96,7 @@ public void testMaxWordsInSentences1() {
9596
Pair.with(3, List.of("please wait", "continue to fight", "continue to win"))
9697
);
9798
tests.forEach(test ->
98-
Assertions.assertEquals(
99+
assertEquals(
99100
test.getValue0(),
100101
problems.mostWordsFound(test.getValue1().toArray(new String[0]))));
101102
}
@@ -111,7 +112,7 @@ public void testValidAcronymn1() {
111112
);
112113

113114
testcases.forEach(test ->
114-
Assertions.assertEquals(
115+
assertEquals(
115116
test.getValue0(),
116117
problems.isAcronymOfWords(
117118
test.getValue1().toArray(new String[0]),
@@ -128,7 +129,7 @@ public void testValidCount1() {
128129
Pair.with(2, "l|*e*et|c**o|*de|")
129130
);
130131
testcases.forEach(test ->
131-
Assertions.assertEquals(
132+
assertEquals(
132133
test.getValue0(),
133134
problems.countAsterisks(test.getValue1())));
134135
}
@@ -143,7 +144,7 @@ public void testValidString2() {
143144
Pair.with(0, "words and 987")
144145
);
145146
testcases.forEach(test ->
146-
Assertions.assertEquals(test.getValue0(), problems.myAtoi(test.getValue1())));
147+
assertEquals(test.getValue0(), problems.myAtoi(test.getValue1())));
147148
}
148149

149150
@Test
@@ -156,7 +157,7 @@ public void testRegexMatching() {
156157
Triplet.with(false, "mississippi", "mis*is*p*.")
157158
);
158159

159-
cases.forEach(test -> Assertions.assertEquals(test.getValue0(),
160+
cases.forEach(test -> assertEquals(test.getValue0(),
160161
problems.isMatch(test.getValue1(), test.getValue2())));
161162
}
162163

@@ -169,7 +170,7 @@ public void testAddBinary() {
169170
);
170171

171172
tests.forEach(test ->
172-
Assertions.assertEquals(
173+
assertEquals(
173174
test.getValue0(),
174175
problems.addBinary(test.getValue1(), test.getValue2())));
175176
}
@@ -190,14 +191,123 @@ public void testGroupAnagrams() {
190191
List.of("a")
191192
)
192193
);
193-
tests.forEach(
194-
test -> Assertions.assertEquals(
194+
tests.forEach(test -> assertEquals(
195195
test.getValue0(),
196196
problems.groupAnagrams(test.getValue1().toArray(new String[0]))
197197
)
198198
);
199199
}
200200

201+
@Test
202+
@DisplayName("1832. Check if the Sentence Is Pangram")
203+
public void testCheckIfPangram() {
204+
List<Pair<Boolean, String>> tests = List.of(
205+
Pair.with(Boolean.TRUE, "thequickbrownfoxjumpsoverthelazydog"),
206+
Pair.with(Boolean.FALSE, "leetcode")
207+
);
208+
209+
tests.forEach(test ->
210+
assertEquals(test.getValue0(), problems.checkIfPangram(test.getValue1())));
211+
}
212+
213+
@Test
214+
@DisplayName("2864. Maximum Odd Binary Number")
215+
public void testMaximumOddBinaryNumber() {
216+
List<Pair<String, String>> tests = List.of(
217+
Pair.with("001", "010"),
218+
Pair.with("1001", "0101")
219+
);
220+
221+
tests.forEach(test -> assertEquals(
222+
test.getValue0(), problems.maximumOddBinaryNumber(test.getValue1())
223+
));
224+
}
225+
226+
@Test
227+
@DisplayName("1614. Maximum Nesting Depth of the Parentheses")
228+
public void testMaxDepth() {
229+
List<Pair<Integer, String>> tests = List.of(
230+
Pair.with(3, "(1+(2*3)+((8)/4))+1"),
231+
Pair.with(3, "(1)+((2))+(((3)))")
232+
);
233+
234+
tests.forEach(test -> assertEquals(test.getValue0(), problems.maxDepth(test.getValue1())));
235+
}
236+
237+
@Test
238+
@DisplayName("2129. Capitalize the Title")
239+
public void testCapitalizeTitle() {
240+
List<Pair<String, String>> tests = List.of(
241+
Pair.with("Capitalize The Title", "capiTalIze tHe titLe"),
242+
Pair.with("First Letter of Each Word", "First leTTeR of EACH Word"),
243+
Pair.with("i Love Leetcode", "i lOve leetcode"),
244+
Pair.with("", ""),
245+
Pair.with(null, null)
246+
);
247+
248+
tests.forEach(test -> assertEquals(test.getValue0(), problems.capitalizeTitle(test.getValue1())));
249+
}
250+
251+
@Test
252+
@DisplayName("2325. Decode the Message")
253+
public void testDecodeMessage() {
254+
List<Triplet<String, String, String>> tests = List.of(
255+
Triplet.with("the five boxing wizards jump quickly",
256+
"eljuxhpwnyrdgtqkviszcfmabo",
257+
"zwx hnfx lqantp mnoeius ycgk vcnjrdb"),
258+
Triplet.with("this is a secret",
259+
"the quick brown fox jumps over the lazy dog",
260+
"vkbs bs t suepuv")
261+
);
262+
263+
tests.forEach(test ->
264+
assertEquals(
265+
test.getValue0(),
266+
problems.decodeMessage(test.getValue1(), test.getValue2())
267+
));
268+
}
269+
270+
@Test
271+
@DisplayName("2194. Cells in a Range on an Excel Sheet")
272+
public void testCellsInRange() {
273+
List<Pair<List<String>, String>> tests = List.of(
274+
Pair.with(List.of("K1","K2","L1","L2"), "K1:L2"),
275+
Pair.with(List.of("A1","B1","C1","D1","E1","F1"), "A1:F1")
276+
);
277+
278+
tests.forEach(test -> assertEquals(
279+
test.getValue0(), problems.cellsInRange(test.getValue1())
280+
));
281+
}
282+
283+
@Test
284+
@DisplayName("2108. Find First Palindromic String in the Array")
285+
public void testFirstPalindrome() {
286+
List<Pair<String, List<String>>> tests = List.of(
287+
Pair.with("ada", List.of("abc","car","ada","racecar","cool")),
288+
Pair.with("racecar", List.of("notapalindrome","racecar")),
289+
Pair.with("", List.of("def","ghi"))
290+
);
291+
292+
tests.forEach(test ->
293+
assertEquals(
294+
test.getValue0(),
295+
problems.firstPalindrome(test.getValue1().toArray(new String[0])))
296+
);
297+
}
298+
299+
@Test
300+
@DisplayName("1816. Truncate Sentence")
301+
public void testTruncateSentence() {
302+
List<Triplet<String, String, Integer>> tests = List.of(
303+
Triplet.with("Hello how are you", "Hello how are you Contestant", 4),
304+
Triplet.with("What is the solution", "What is the solution to this problem", 4),
305+
Triplet.with("chopper is not a tanuki", "chopper is not a tanuki", 5)
306+
);
307+
308+
tests.forEach(test -> assertEquals(test.getValue0(),
309+
problems.truncateSentence(test.getValue1(), test.getValue2())));
310+
}
201311

202312

203313
}

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
</modules>
1414

1515
<properties>
16-
<maven.compiler.source>21</maven.compiler.source>
17-
<maven.compiler.target>21</maven.compiler.target>
16+
<maven.compiler.source>17</maven.compiler.source>
17+
<maven.compiler.target>17</maven.compiler.target>
1818
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1919

2020
</properties>

0 commit comments

Comments
 (0)