Computing number of independent paths

133 views Asked by At

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

There are 1 answers

0
75inchpianist On BEST ANSWER

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