Should the boolean expressions joined using && be considered as separate statements while computing number of independent paths? For example, Line 3 has two conditions, and if the first expression was false, then the subsequent expression would be evaluated.

1 float calc(float sp, Boolean bt, int r)  { 
2    float c = .060; 
3    if ((sp > 300000) && bt) 
4      c = .050; 
5    if (r > 3) 
6      c = c * .9; 
7    return (sp * c); 
8  } 
有帮助吗?

解决方案

No, assuming you are computing paths of execution.

If you are computing number of conditional paths, then yes.

Typically when you are calculating cyclomatic complexity you are doing the latter, so YES you should count the number of SIMPLE conditions in the function.

What I mean by simple conditions is that the above function is equivalent to:

float calc(float sp, Boolean bt, int r)  { 
   float c = .060; 
   if ((sp > 300000)) 
    if (bt)
     c = .050; 
   if (r > 3) 
     c = c * .9; 
   return (sp * c); 
 } 
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top