圈复杂度的计算

发布于 2025-01-01 00:59:53 字数 1455 浏览 0 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

眼中杀气 2025-01-08 00:59:53

您需要更加小心地将值正确插入到公式中。

在示例 1 中,您说

这里,E = 8,N = 9,P = 1

但实际上,情况正好相反:9 个边 (=E)、8 个节点 (=N),因此 CC 为 3。

在示例 2 中,您有右边的值:E=11,N=10,P=1。但是您在公式中插入它们的顺序错误;它实际上应该是11 - 10 + (2x1) = 3

快捷方式:如果您有图表的图片,您可以非常轻松地确定圈复杂度。只需计算背景被边缘划分为的区域数量即可。在第一个示例中,您有 2 个内部区域(由边缘包围)和一个周围区域,CC 为 3。第二个示例也是如此。 (显然,此方法要求边缘不相互交叉。)

You need to take more care to correctly insert the values into the formula.

In example 1, you say

Here, E = 8, N = 9 and P = 1

But actually, it's the other way round: 9 edges (=E), 8 nodes (=N), so you get a CC of 3.

In example 2, you have the values right: E=11, N=10, P=1. But you insert them in the wrong order in the formula; it actually should be 11 - 10 + (2x1) = 3.

Shortcut: If you have a picture of your graph, you can very easily determine the cyclomatic complexity. Just count the number of regions the background is divided into by the edges. In your first example, you have 2 inner regions (bordered by the edges) and one surrounding region, giving a CC of 3. Same goes with the second example. (This method requires that edges are not crossing each other, obviously.)

生生不灭 2025-01-08 00:59:53

另外,如果这有帮助,则条件(If、while、for)语句的数量+1。所以在上面的例子中,有2个条件语句。所以2+1=3。本例中的圈复杂度为 3

Also if this helps, it the number of conditional (If, while, for) statements +1. So in the above example, there are 2 conditional statements . so 2+1=3. Cyclomatic complexity in this case is 3

与酒说心事 2025-01-08 00:59:53

只需计算封闭区域的数量并加 1 即可。

在上面的示例中,闭合区域的数量 = 2,因此 CC = 2+1 = 3

Just count the number of closed region and add 1 to it.

In your example above, number of closed region = 2, so the CC = 2+1 = 3

疑心病 2025-01-08 00:59:53

P = 连接组件的数量

换句话说

P = 具有退出点的节点数量

源< /a>

P = the number of connected components

IN OTHER WORDS

P = the number of nodes that have exit points

Source

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文