|
1 | 1 | package com.fishercoder.solutions;
|
| 2 | +import java.util.HashMap; |
| 3 | +import java.util.Map; |
2 | 4 |
|
3 | 5 | public class _3038 {
|
| 6 | + |
| 7 | + private static Map<String, Boolean> branchCoverage = new HashMap<>(); |
4 | 8 | 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 | + |
5 | 23 | public int maxOperations(int[] nums) {
|
6 | 24 | 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 |
8 | 27 | return maxOps;
|
9 | 28 | }
|
10 | 29 | maxOps++;
|
11 | 30 | 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 |
14 | 35 | maxOps++;
|
15 |
| - } else { |
| 36 | + } else { //4 |
| 37 | + branchCoverage.put("flag4", true); |
16 | 38 | break;
|
17 | 39 | }
|
18 | 40 | }
|
| 41 | + printCoverage(); |
19 | 42 | return maxOps;
|
20 | 43 | }
|
21 | 44 | }
|
|
0 commit comments