【问题标题】:Control flow graph & cyclomatic complexity控制流图和圈复杂度
【发布时间】:2012-05-10 15:13:33
【问题描述】:

我必须找到这段代码的控制流图和圈复杂度,然后提出一些白盒测试用例和黑盒测试用例。但我无法为代码制作 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;
}

【问题讨论】:

    标签: cyclomatic-complexity


    【解决方案1】:

    这里的基本圈复杂度是4:while + if + if + 1。如果你考虑用Understand或CMTJava做的扩展圈复杂度,你还需要为合取加1,所以它是5。无条件break 等控制语句不会影响圈复杂度值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多