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

前端 未结 2 1458
故里飘歌
故里飘歌 2020-12-11 07:09

I want to know the cyclomatic complexity of two section of code,

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

as far my knowledge the cycloma

2条回答
  •  失恋的感觉
    2020-12-11 07:53

    I think they have the same cyclomatic complexity of 3; this can be shown using De Morgan's Law.

    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;}
    

    Another way of looking at it is to take the graph and swap the conditional block and the exit point (and reverse the edge between them) and this transforms it from an AND to an OR without changing the number of nodes or edges.

提交回复
热议问题