Condition Coverage
Description
Conditions are simple C/C++ Boolean expressions that contain:
Relation operators, such as
<,>,<=, or>=Equation operators, such as
!=or==The logical negation operator (
!)
Conditions do not contain logical operators such as
&& or ||.
Each condition in your code has two outcomes: true and
false. This metric indicates the percentage of condition outcomes in
your source code that the current test cases evaluate. A condition coverage of 50% indicates
that the current test cases evaluate only half of the condition outcomes in your code. To
increase condition coverage, add test cases that evaluate the unevaluated condition
outcomes.
Polyspace Implementation
To calculate condition coverage, Polyspace®
Test™ counts the total number of possible condition outcomes
(n_outcome) and the condition outcomes that the current test cases
evaluate (n_evaluated):
Condition coverage = (n_evaluated / n_outcomes) *100false. If a simple Boolean expression is the only condition in a
branching or looping statement, Polyspace
Test considers the expression a decision rather than a condition.Consider this code:
int foo(int x)
{
int y = (x >= 5 && x != 7); //1,2
if (x < 0)//Not a condition, but a decision
return 1;
else if (x > 0 && y)//3,4
return 2;
else
return -1;
}(x >= 5)(x != 7)(x > 0)(y == 1)
The Boolean expression (x < 0) is the only one in the
if statement and Polyspace
Test considers the expression a decision. Each of the preceding four conditions can
be either true or false, resulting in
n_outcomes = 8. Polyspace calculates how many of these outcomes the test cases evaluate. If you test
foo() with x == 0, then Polyspace
Test evaluates these condition outcomes:
(x >= 5) == false(x > 0) == false
Resulting in n_outcomes = 2 and a condition coverage of
2/8 × 100 or 25%.
Examples
Version History
Introduced in R2023b