Instrument a method to measure branch coverage. The method under test is StudyBuddy's reminder rule:
static String reminder(int hoursLeft, boolean submitted, boolean optedOut) {
if (submitted) { // decision D1
return "NONE";
}
if (optedOut) { // decision D2
return "NONE";
}
if (hoursLeft <= 0) { // decision D3
return "OVERDUE";
}
if (hoursLeft <= 24) { // decision D4
return "URGENT";
}
return "NORMAL";
}
Each decision has two outcomes, so there are 8 branch outcomes: D1T D1F D2T D2F D3T D3F D4T D4F (a decision that is never reached has neither outcome covered).
Input: lines hoursLeft submitted optedOut (true/false) until the end of input. For each, print h s o -> RESULT. Then print:
Covered: D1T D1F ... (in the fixed order above, only covered ones)
Missing: ... (in the same order), or "Missing: none"
Branch coverage: c/8 (P%) P = c * 100 / 8, integer division
Input:
10 false false
5 true false
Output:
10 false false -> URGENT
5 true false -> NONE
Covered: D1T D1F D2F D3F D4T
Missing: D2T D3T D4F
Branch coverage: 5/8 (62%)