background image
<< Block Code Coverage | Method Code Coverage >>
<< Block Code Coverage | Method Code Coverage >>

Logical Blocks

Runtime Analysis
catch ( UnLucky & u ) {
throw u;
} /* potentially terminal statement */
return 0; /* sequence block */
}
Each simple block is a branch. Every C++ function and method contains at least one
simple block corresponding to its main body.
Decisions (Implicit Blocks)
Implicit blocks are introduced by IF statements without an ELSE statement, and a
SWITCH statements without a DEFAULT statement.
/* Power_of_10 function */
/* -BLOCK=DECISION or -BLOCK=IMPLICIT */
int power_of_10 ( int value, int max )
{
int retval = value, i;
if ( value == 0 ) return 0; else ;
for ( i = 0; i < 10; i++ )
{
retval = ( max / 10 ) < retval ? retval * 10 : max;
}
return retval;
}
/* Near_color function */
ColorType near_color ( ColorType color )
{
switch ( color )
{
case WHITE :
case LIGHT_GRAY :
return WHITE;
case RED :
case PINK :
case BURGUNDY :
return RED;
/* etc ... with no default */
default : ;
}
}
Each implicit block represents a branch.
Since the sum of all possible decision paths includes implicit blocks as well as simple
blocks, reports provide the total number of simple and implicit blocks as a figure and
a percentage after the term decisions.
Loops (Logical Blocks)
Three branches are created in a for or while loop:
·
The first branch is the simple block contained within the loop, and that is
executed zero times (the entry condition is false from the start).
·
The second branch is the simple block executed exactly once (entry condition
true, then false the next time).
47