控制流程图&圈复杂度

时间:2012-05-10 15:13:33

标签: cyclomatic-complexity

我必须找到此代码的控制流图和圈复杂度,然后建议一些白盒测试用例和黑盒测试用例。但我无法为代码制作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 个答案:

答案 0 :(得分:1)

这里的基本圈复杂度是4:而+ if + if + 1.如果你考虑扩展的圈复杂度,就像通过理解或CMTJava所做的那样,你还需要为联合添加1,所以它将是5.无条件控制语句(如break)不会影响圈复杂度值。