Skip to content

Commit 415665a

Browse files
committed
Added flags to _3038.java
1 parent 1d82f14 commit 415665a

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

src/main/java/com/fishercoder/solutions/_3038.java

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,44 @@
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
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy