Testing 圈复杂度-为此java语句绘制控制流图

Testing 圈复杂度-为此java语句绘制控制流图,testing,metrics,control-flow-graph,Testing,Metrics,Control Flow Graph,有人能帮忙吗 while (x > level) x = x – 1; x = 0 圈复杂度可以使用提供的公式计算 对于您的情况,图表应如下所示: --------------- ---------- | x > level |----- NO ------>| x = x-1| |-------------| ----|----- | |---------------------

有人能帮忙吗

while (x > level)
    x = x – 1;
x = 0

圈复杂度可以使用提供的公式计算

对于您的情况,图表应如下所示:

---------------                ----------
|  x > level  |----- NO ------>| x = x-1|
|-------------|                ----|-----
       |      |---------------------
       |
      Yes
       |
-------|----------
| End while (if) |
-------|----------
       |
       |
   ---------
   |  x = 0 |
   ----------
(非艺术人士)

因此,
圈复杂度应为:

E = 4, N = 4, P = 2 => Complexity = 4 - 4 + 2 = 2
[编辑]
Ira Baxter
很好地指出了如何简化诸如
Java
C#
C++
等语言的计算。但是,必须仔细识别条件,如图所示:


对于像Java这样的结构化语言,可以将其计算为#条件加1。(本例中为1+1==>2)。考虑到中断和继续总是伴随着一个条件(否则循环将立即退出),您是否只计算条件?@nonconvergent-我猜
if
+
中断
计算为一个,而不是两个。如果我在OP中重写while,比如:
while(true)。。如果(x>=level)break
,根据规则我将获得+2(
if
break
)。我的感觉是如果。。break
和dummy
while
应该是例外,因为复杂性似乎相同。无论如何,我不是很确定,这对程序员来说是一个好问题。我认为SE.
if(condition){return;}
也可以算作1而不是2。
E = 4, N = 4, P = 2 => Complexity = 4 - 4 + 2 = 2
- Start with a count of one for the method.
- Add one for each of the following flow-related elements that are found in the method.
    Returns - Each return that isn't the last statement of a method.
    Selection - if, else, case, default.
    Loops - for, while, do-while, break, and continue.
    Operators - &&, ||, ?, and :
    Exceptions - catch, finally, throw, or throws clause.