Condition coverage is about testing that any operands which are part of the if
expression can be evaluated to both true
and false
without issues. In this type of coverage, you don't care about what would be executed inside the braces, nor about the result of the operand used in a condition.
Take the following code:
bool a = ...;
bool b = ...;
if (a && b)
{
...
}
Condition coverage of this code would require to test:
a
for both true and false, and:
b
for both true and false.
In languages which require both operands to evaluate in a logical operation, condition coverage of the code above is satisfied with:
a = true; b = false
a = false; b = true
This is what is illustrated in your question.
Some languages evaluate the second operand of a logical AND only if the first operand is true (or evaluate the second operand of OR only if the first operand evaluates to false). In this case, three tests are required instead of two:
a = true; b = true
a = true; b = false
a = false
As you can note, we don't care about the value of b
in the third test, since the program will never compute it when a
is false.