前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >代码环复杂度的计算公式

代码环复杂度的计算公式

作者头像
Jerry Wang
发布2019-05-31 10:12:24
8610
发布2019-05-31 10:12:24
举报

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.

代码语言:javascript
复制
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:

[图片]

在这里插入图片描述
在这里插入图片描述
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019年03月09日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • i042416 commented on Feb 17, 2017
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档