Cyclomatic complexity IF ((A> B) AND (C> D)) and IF ((A> B) OR (C> D))

I want to know the cyclic complexity of two sections of code,

IF((A>B) AND (C>D)) 
{ a=a+b;c=c+d;}

As far as I know, cyclomatic complexity above code = 2 + 1 = 3,

Other code

IF((A>B) OR (C>D))
{a=a+b;c=c+d;}

The complexity of the above code is = 4 + 1 = 5,

Are the indicated difficulties correct or not?

+5
source share
2 answers

Both difficulties are the same and equal to 3, they are counted in 4 ways. I agree with Neil in using De Morgan, proving that they are the same, I think that this can be seen in the graphs, where it is important for calculating complexity.

Counts

Let's start with graphs for both parts of the code.

if + or

if + and

Explanation Word:

  • McCabe , , , .
  • , , .
  • , . , , McCabe, , , , , , , / .
  • , , (, ).
  • , : while, for, if ..
  • , AND OR +1 , if and if if or if, ifs. , node node.

, . , , . , node node, , . , .

.

- + 2 * ()

= 5; = 4; = 1;

= 5-4 + 2 * (1) = 3 . , .

- +

= 6; = 4; = 1;

= 6-4 + 1 = 3 . ( ). , /, . , . .

: 3.

, + - = 2 : = - + 2

, ( , ). .

+ 1

,

, IF "c1 AND c2" THEN, , IF c1 THEN IF c2 THEN .

, Decisions = 2;

= 2 + 1 = 3.

, , .

McCabe: http://www.literateprogramming.com/mccabe.pdf

, , , :

, Chambers: http://www.chambers.com.au/glossary/mc_cabe_cyclomatic_complexity.php

" " 8 ( , , 8.7).

http://books.google.pl/books?id=M-mhFtxaaskC&lpg=PA385&ots=jB8P0avJU7&d&hl=pl&pg=PR1#v=onepage

+10

, 3; , .

IF((A>B) OR (C>D)) {a=a+b;c=c+d;} ELSE {}

IF(!((A>B) OR (C>D))) {} ELSE {a=a+b;c=c+d;}

IF(!(A>B) AND !(C>D)) {} ELSE {a=a+b;c=c+d;}

- ( ), OR .

+3

All Articles