Content deleted Content added
→Cohesion: rm predatory journal and claims sourced only to it |
m →Implications for software testing: format code |
||
Line 113:
For example, consider a program that consists of two sequential if-then-else statements.
<source lang="c">
if (
f1();
else
f2();
if (
f3();
else
f4();
</source>
[[File:Control flow graph of function with two if else statements.svg|thumb|250px|right|The control flow graph of the source code above; the red circle is the entry point of the function, and the blue circle is the exit point. The exit has been connected to the entry to make the graph strongly connected.]]
In this example, two test cases are sufficient to achieve a complete branch coverage, while four are necessary for complete path coverage. The cyclomatic complexity of the program is 3 (as the strongly connected graph for the program contains 9 edges, 7 nodes and 1 connected component) (
In general, in order to fully test a module, all execution paths through the module should be exercised. This implies a module with a high complexity number requires more testing effort than a module with a lower value since the higher complexity number indicates more pathways through the code. This also implies that a module with higher complexity is more difficult for a programmer to understand since the programmer must understand the different pathways and the results of those pathways.
|