froglogic logo

MCC Code Coverage Example

A C/C++ function with a decision based on a composed set of conditions highlights the difference between MCC and Condition Coverage:

1
2
3
4
5
6
7
bool isValidPosition(int x, int y, int z)
{
    if ((x < 10 || y > 20) && z > 0)
        return true;
    else
        return false;
}

For 100% coverage all combinations of truth table values for the three Boolean expressions x > 10, y > 20 and z > 0 need to be exercised. One might expect 23 = 8 tests to be required. Languages like C, C++, C# and JavaScript perform a so called short-circuit evaluation: If x > 10 evaluates to TRUE the expression y > 20 won’t be evaluated anymore. Likewise, if neither x > 10 nor y > 20 is TRUE z > 0 won’t be valuated anymore as it cannot change the decision anymore.

As a result the number of possible combinations and number of needed tests for 100% Multiple Condition Coverage is reduced to these five:

x > 10 y > 20 z > 0
FALSE TRUE TRUE
TRUE TRUE
FALSE TRUE FALSE
TRUE FALSE
FALSE FALSE

From the truth table shown the major drawback of this approach becomes immediately obvious in that number of possible combinations that need to be tested can ‘explode’ in light of big numbers of conditions. To mitigate this problem the Modified Condition/Decision Coverage metric was created.

About froglogic

froglogic was founded to create a best-of-breed cross-platform test automation tools. The froglogic Squish Testing Suite consists of the cross-platform and multi-language code coverage analysis tool Squish Coco and the GUI Test Automation Tool Squish GUI Tester. More details…

Find out more…

For more information on how to use MCC to determine code coverage within your application and how Squish Coco can generate the metrics you require please complete the form below.

 

Full Name (required):

Company Name (required):

Your Email (required)