i042416 commented on Feb 17, 2017

来了解一下软件工程中代码环复杂度的定义。

the cyclomatic complexity of a program is defined with reference to the control flow graph of the program, a directed graph containing the basic blocks of the program, with an edge between two basic blocks if control may pass from the first to the second. The complexity M is then defined as:
M = E − N + 2, where
E = the number of edges of the graph.
N = the number of nodes of the graph.
Take this very simple report for example, it has cyclomatic complexity calculated as 3 by code inspector.

IF lv_value = 1.
  WRITE: / 'always happend'.
ELSEIF lv_value = 2.
  WRITE: / 'not possible'.
ELSE.
  WRITE: / 'even not possible'.
ENDIF.

Why calculated as 3? See the directed graph for this simple report below:

[图片]

代码环复杂度的计算公式

要获取更多Jerry的原创文章,请关注公众号"汪子熙":

代码环复杂度的计算公式

相关文章:

  • 2021-09-29
  • 2021-07-15
  • 2021-10-11
  • 2022-12-23
  • 2021-08-09
  • 2021-12-19
  • 2021-08-27
猜你喜欢
  • 2021-08-27
  • 2021-12-14
  • 2021-08-24
  • 2021-11-12
  • 2021-10-15
  • 2021-05-16
相关资源
相似解决方案