Content deleted Content added
make whitespace consistent in the example code |
The examples used a definition of decision that is wrong. an assignment to a boolean expression is a decision, so the statement in the text was wrong. this is a common misconception and a defect of most code coverage tools that needs to be addressed, |
||
Line 18:
;Condition: A condition is a leaf-level [[Boolean algebra (logic)|Boolean]] [[Expression (programming)|expression]] (it cannot be broken down into simpler Boolean expressions).
;Decision: A Boolean expression composed of conditions and zero or more [[Boolean operator (computer programming)|Boolean operator]]s. A decision without a Boolean operator is a condition.: A decision does not imply a change of control flow, e.g. an assignment of a boolean expression to a variable is a decision for MC/DC.
;Condition coverage: Every condition in a decision in the program has taken all possible outcomes at least once.
Line 30:
==Criticism==
{{Dubious|date=January 2018}}
Purely syntactic rearrangements of decisions (breaking them into several independently evaluated conditions using temporary variables, the values of which are then used in the decision) which do not change the semantics of a program can lower the difficulty of obtaining complete MC/DC coverage.<ref>{{cite journal | title = The Effect of Program and Model Structure on MC⁄DC Test Adequacy Coverage | last1 = Rajan | first1 = Ajitha | last2 = Heimdahl | first2 = Mats | last3 = Whalen | first3 = Michael | date = March 2003 | url = http://se.inf.ethz.ch/old/teaching/2009-S/0276/slides/fiva.pdf }}</ref> This is because MC/DC is driven by the program syntax. However, this kind of "cheating" can be done to simplify expressions, not simply to avoid MC/DC complexities. For example, assignment of the number of days in a month (excluding leap years) could be achieved by using either a switch statement or by using a table with an enumeration value as an index. The number of tests required based on the source code could be considerably different depending upon the coverage required, although semantically we would want to test both approaches with a minimum number of tests.▼
▲
Another example which demonstrates "cheating" to achieve higher MC/DC is:<syntaxhighlight lang="c" line="1">▼
This is because MC/DC is driven by the program syntax. However, this kind of "cheating" can be done to simplify expressions, not simply to avoid MC/DC complexities. For example, assignment of the number of days in a month (excluding leap years) could be achieved by using either a switch statement or by using a table with an enumeration value as an index. The number of tests required based on the source code could be considerably different depending upon the coverage required, although semantically we would want to test both approaches with a minimum number of tests.
▲Another example
/* Function A */
Line 64 ⟶ 67:
}
}
</syntaxhighlight>
However, what is wrong in the previous statement is the definition of decision. A decision includes 'any' boolean expression, even for assignments to variables. In this case, the three assignments should be treated as a decision for MC/DC purposes and therefore the changed code needs exactly the same tests and number of tests to achieve MC/DC than the first one. Some code coverage tools do not use this strict interpretation of a decision and may produce false positives (reporting 100% code coverage when indeed this is not the case).
==RC/DC==
|