2012-05-10 65 views
0

我必須找到此代碼的控制流圖和圈複雜度,然後建議一些白盒測試用例和黑盒測試用例。但是我無法爲代碼製作CFG。控制流程圖和圈複雜度

希望對測試用例有所幫助。

private void downShift(int index) 
{ 
    // index of "child", which will be either index * 2 or index * 2 + 1 
    int childIndex; 

    // temp storage for item at index where shifting begins 
    Comparable temp = theItems[index]; 

    // shift items, as needed 
    while (index * 2 <= theSize) 
    { 
     // set childIndex to "left" child 
     childIndex = index * 2; 

     // move to "right" child if "right" child < "left" child 
     if (childIndex != theSize && theItems[childIndex + 1].compareTo(theItems[childIndex]) < 0) 
      childIndex++; 

     if (theItems[childIndex].compareTo(temp) < 0) 
     { 
     // shift "child" down if child < temp 
      theItems[index] = theItems[childIndex]; 
     } 
     else 
     { 
      // shifting complete 
      break; 
     } 

     // increment index 
     index = childIndex; 
    } 

    // position item that was originally at index where shifting began 
    theItems[index] = temp; 
} 

回答

1

這裏的基本圈複雜度爲4:而如果+ + +是否1.如果您考慮擴展圈複雜度是由完成的理解或CMTJava,您還需要添加1合取,所以它會爲5.無條件控制語句(如break)不會影響圈複雜度值。