Skip to content

Commit 937ec78

Browse files
committed
Added flags to _3038.java
1 parent 9e0199f commit 937ec78

File tree

1 file changed

+37
-7
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+37
-7
lines changed

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

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,30 @@
11
package com.fishercoder.solutions;
2+
import java.util.HashMap;
3+
import java.util.Map;
4+
25

36
public class _29 {
47

58
public static class Solution1 {
9+
10+
private static Map<String, Boolean> branchCoverage = new HashMap<>();
11+
12+
static {
13+
branchCoverage.put("flag1", false);
14+
branchCoverage.put("flag2", false);
15+
branchCoverage.put("flag3", false);
16+
branchCoverage.put("flag4", false);
17+
branchCoverage.put("flag5", false);
18+
branchCoverage.put("flag6", false);
19+
branchCoverage.put("flag7", false);
20+
}
21+
22+
public void printCoverage() {
23+
for (Map.Entry<String, Boolean> entry : branchCoverage.entrySet()) {
24+
System.out.println(entry.getKey() + " was " + (entry.getValue() ? "hit" : "not hit"));
25+
}
26+
}
27+
628
/**
729
* credit: https://leetcode.com/problems/divide-two-integers/solution/ solution 1
830
* <p>
@@ -16,29 +38,37 @@ public static class Solution1 {
1638
* Space: O(1)
1739
*/
1840
public int divide(int dividend, int divisor) {
19-
if (dividend == Integer.MIN_VALUE && divisor == -1) {
41+
if (dividend == Integer.MIN_VALUE && divisor == -1) { //1
42+
branchCoverage.put("flag1", true);
2043
return Integer.MAX_VALUE;
2144
}
2245
int negativeCount = 0;
23-
if (dividend < 0) {
46+
if (dividend < 0) { //2
47+
branchCoverage.put("flag2", true);
2448
negativeCount++;
25-
} else {
49+
} else { //3
50+
branchCoverage.put("flag3", true);
2651
dividend = -dividend;
2752
}
28-
if (divisor < 0) {
53+
if (divisor < 0) { //4
54+
branchCoverage.put("flag4", true);
2955
negativeCount++;
30-
} else {
56+
} else { //5
57+
branchCoverage.put("flag5", true);
3158
divisor = -divisor;
3259
}
3360

3461
int quotient = 0;
35-
while (dividend <= divisor) {
62+
while (dividend <= divisor) { //6
63+
branchCoverage.put("flag6", true);
3664
dividend -= divisor;
3765
quotient++;
3866
}
39-
if (negativeCount == 1) {
67+
if (negativeCount == 1) { //7
68+
branchCoverage.put("flag7", true);
4069
quotient = -quotient;
4170
}
71+
printCoverage();
4272
return quotient;
4373
}
4474
}

0 commit comments

Comments
 (0)