# McCabe's criterion example

Ir para: navegação, pesquisa

## Example 1

### Test requirements

The cyclomatic complexity of the graph is 7. So, seven test requirements, thus seven complete paths, must be devised for the graph.

Path 1: ABDEGKMQS

Path 2: ACDEGKMQS

Path 3: ABDFILORS

Path 4: ABDEHKMQS

Path 5: ABDEGKNQS

Path 6: ACDFJLORS

Path 7: ACDFILPRS

## Example 2

```boolean evaluateBuySell (TickerSymbol ts) {
s1;
s2;
s3;
if (c1) {s4; s5; s6;}
else {s7; s8;}
while (c2) {
s9;
s10;
switch (c3) {
case-A:
s20;
s21;
s22;
break; // End of Case-A
case-B:
s30;
s31;
if (c4) {
s32;
s33;
s34;
}
else {
s35;
}
break; // End of Case-B
case-C:
s40;
s41;
break; // End of Case-C
case-D:
s50;
break; // End of Case-D
} // End Switch
s60;
s61;
s62;
if (c5) {s70; s71; }
s80;
s81;
} // End While
s90;
s91;
s92;
return result;
```

### Test requirements

• Cyclomatic Complexity Calculation:
```C = edges - nodes + 2
C = 22-16+2
C = 8
```

Basis paths:

1. ABDP
2. ACDP
3. ABDEFGMODP
4. ABDEFHKMODP
5. ABDEFIMODP
6. ABDEFJMODP
7. ABDEFHLMODP
8. ABDEFIMNODP

### Test cases

Test case c1 c2 c3 c4 c5
1 False False N/A N/A N/A
2 True False N/A N/A N/A
3 False True A N/A False
4 False True B False False
5 False True C N/A False
6 False True D N/A False
7 False True B True False
8 False True C N/A True

## Example 3

### Source code

```if (c1) {
while (c2) {
if (c3) {
s1; s2;
if (c4) s3;
else s4;
}
else
if (c5) { s5; }
else {
s6;
s7;
break;
}
} // End of while
} // End of if
s8;
if (c6)
s9;
s10;
s11;
```