07.12.2012 Views

Structured Testing - McCabe and Associates

Structured Testing - McCabe and Associates

Structured Testing - McCabe and Associates

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

4.2 Counting flow graph regions<br />

When the flow graph is planar (no edges cross) <strong>and</strong> divides the plane into R regions (including<br />

the infinite region “outside” the graph), the simplified formula for cyclomatic complexity is<br />

just R. This follows from Euler’s formula, which states that for planar graphs n - e + R = 2.<br />

Re-arranging the terms, R = e - n + 2, which is the definition of cyclomatic complexity. Thus,<br />

for a planar flow graph, counting the regions gives a quick visual method for determining<br />

complexity. Figure 4-8 shows a planar flow graph with complexity 7, with the regions numbered<br />

from 1 to 7 to illustrate this counting technique. Region number 1 is the infinite region,<br />

<strong>and</strong> otherwise the regions are labeled in no particular order.<br />

28<br />

1<br />

2 3 4<br />

5 6 7<br />

Figure 4-8. Planar graph with complexity 7, regions numbered.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!