Decision Coverage
Description
Decisions are Boolean expressions that can combine multiple conditions by using logical operators such as && or ||. For a definition of a condition, see Condition Coverage. Conditions within branching constructs (if-else, while,
do-while, switch-case) are decisions.
Each decision in your code has two outcomes: true and
false. This metric indicates the percentage of decision outcomes in
your source code that the current test cases evaluate. For instance, a decision coverage of
50% indicates that the test cases evaluate half of the decision outcomes in your code at
least once. To increase decision coverage, add test cases to evaluate any unevaluated
decision outcomes.
Polyspace Implementation
To calculate the decision coverage, Polyspace® counts the total number of possible decision outcomes
(n_outcome) and the decision outcomes the test cases evaluate
(n_evaluated):
Decision coverage = (n_evaluated / n_outcomes) *100int foo(int x)
{
int y = (x >= 5 && x != 7); //1
if (x < 0)//2
return 1;
else if (x > 0 && y)//3
return 2;
else
return -1;
}(x >= 5 && x != 7)(x < 0)(x > 0 && y)
Each of these decisions can be either true or
false, resulting in n_outcomes = 6. Polyspace counts how many of these outcomes the test case evaluates. For instance, if
you test foo() with x == 0, then the test case
evaluates only the false outcome of all three decisions, resulting in
coverage of 3/6×100, or 50%.
Examples
Version History
Introduced in R2023b