Skip to content

Commit 3ae2ddc

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 877563f + 9e0199f commit 3ae2ddc

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed
Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,46 @@
11
package com.fishercoder.solutions;
2+
import java.util.HashMap;
3+
import java.util.Map;
24

35
public class _3038 {
6+
7+
private static Map<String, Boolean> branchCoverage = new HashMap<>();
48
public static class Solution1 {
9+
10+
static {
11+
branchCoverage.put("flag1", false);
12+
branchCoverage.put("flag2", false);
13+
branchCoverage.put("flag3", false);
14+
branchCoverage.put("flag4", false);
15+
}
16+
17+
public void printCoverage() {
18+
for (Map.Entry<String, Boolean> entry : branchCoverage.entrySet()) {
19+
System.out.println(entry.getKey() + " was " + (entry.getValue() ? "hit" : "not hit"));
20+
}
21+
}
22+
523
public int maxOperations(int[] nums) {
624
int maxOps = 0;
7-
if (nums == null || nums.length < 2) {
25+
if (nums == null || nums.length < 2) { //1
26+
branchCoverage.put("flag1", true); //1 should not be hit
827
return maxOps;
928
}
1029
maxOps++;
1130
int sum = nums[0] + nums[1];
12-
for (int i = 2; i < nums.length - 1; i += 2) {
13-
if (nums[i] + nums[i + 1] == sum) {
31+
for (int i = 2; i < nums.length - 1; i += 2) { //2
32+
branchCoverage.put("flag2", true);
33+
if (nums[i] + nums[i + 1] == sum) { //3
34+
branchCoverage.put("flag3", true); //3 should not be hit
1435
maxOps++;
15-
} else {
36+
} else { //4
37+
branchCoverage.put("flag4", true);
1638
break;
1739
}
1840
}
41+
printCoverage();
1942
return maxOps;
2043
}
2144
}
2245
}
46+
Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,34 @@
11
package com.fishercoder.solutions;
2+
import java.util.HashMap;
3+
import java.util.Map;
24

35
public class _58 {
4-
56
public static class Solution1 {
7+
private static Map<String, Boolean> branchCoverage = new HashMap<>();
8+
9+
static {
10+
branchCoverage.put("flag1", false);
11+
branchCoverage.put("flag2", false);
12+
}
13+
614
public int lengthOfLastWord(String s) {
715
if (s == null || s.length() == 0) {
16+
branchCoverage.put("flag1", true);
817
return 0;
918
}
1019
s = s.trim();
1120
int n = s.length() - 1;
1221
while (n >= 0 && s.charAt(n) != ' ') {
22+
branchCoverage.put("flag2", true);
1323
n--;
1424
}
25+
printCoverage();
1526
return s.length() - n - 1;
1627
}
28+
public void printCoverage() {
29+
for (Map.Entry<String, Boolean> entry : branchCoverage.entrySet()) {
30+
System.out.println(entry.getKey() + " was " + (entry.getValue() ? "hit" : "not hit"));
31+
}
32+
}
1733
}
18-
1934
}

0 commit comments

Comments
 (0)