Circle complexity Basics

Source: Internet
Author: User
Tags case statement

What is sphere complexity:

A more general explanation:CodeThe measure of complexity. The Chinese name is "circle complexity. In the concept of software testing, the circle complexity is used to measure the complexity of a module's decision structure. The number is represented by the number of independent current paths, that is, the minimum number of paths required for testing to prevent errors reasonably, which is highly complex.ProgramThe code may be of low quality and difficult to test and maintain. Based on experience, the possible errors of the program and the high complexity of the circle are closely related ".

Circle complexity is a software measure that provides quantitative measurement for the complexity of program logic. It is used to calculate the basic number of independent paths of a program, the upper limit of the number of tests executed at least once for all statements. An independent path must contain an edge that is not used before the definition.

There are three methods to calculate the complexity of the circle:

1. The number of areas in the flow chart corresponds to the complexity of the cycle;

2. Given the sphere complexity of Flow Graph g v (G), defined as V (G) = E-N + 2, e is the number of edges in the flow graph, N indicates the number of nodes in the flow chart;

3. for a given flow graph G, the circle complexity V (G) is defined as V (G) = p + 1, and P is the number of nodes identified in the flow graph G.

No FlowchartAlgorithm:

Add 1 to the following items:

Number of branches (such as if, while, And do while)

Number of case statements in the switch

If the condition is two composite conditions, the addition of 1 is not 2.

Reprinted from: http://blog.csdn.net/jichuanchun/archive/2010/03/19/5396997.aspx

 

Circle complexity of software measurement
A standard for measuring Code complexity. The Chinese name is "circle complexity. In the concept of software testing, the circle complexity is used to measure the complexity of a module's decision structure. The number is represented by the number of independent current paths, that is, the minimum number of paths required for testing to prevent errors reasonably. The large complexity indicates that the program code may be of low quality and difficult to test and maintain. Based on experience, the possible errors of the program are highly correlated with the complexity of the circle ".

The control flow chart is the basis for McCabe complexity calculation. The McCabe metric is to convert the software flowchart into a directed graph, and then the quality of the software is measured by the knowledge and Calculation Method of graph theory. McCabe complexity includes cyclomatic complexity, basic complexity, module complexity, design complexity, and integration complexity. Control Flow chart analysis is a static analysis process. It provides static measurement standards and is generally used in white box testing.

An important property of a control flow chart is its atomcibility ). If the program does not have a GOTO statement that jumps from outside the loop to the loop, the control flow diagram corresponding to this program can be normalized (ible cible ), on the other hand, this control flow chart is undefinable ). Therefore, the module conforms to the rules of structured program design, which is the foundation of the control flow diagram.

The complexity of a program loop is also a measurement of McCabe complexity. It is generally described by the circle complexity and recorded as V (G ). It is used to measure the complexity of the decision structure contained in a program module. The number is represented by the number of independent paths, that is, the minimum number of paths required for testing to reasonably prevent errors, the code may be of low quality and difficult to test and maintain. Experience shows that the number of bugs that may exist in the program is highly correlated with the complexity of the circle.

The calculation method of the circle complexity is very simple. The formula is V (G) = E-N + 2. E indicates the number of edges in the control flow diagram and N indicates the number of nodes in the control flow diagram. In fact, there is a more intuitive way to calculate the complexity of the circle, because the complexity of the circle reflects the number of "judgment conditions", so the complexity of the circle is actually equal to the number of judgment nodes plus 1, that is, the number of regions in the control flow chart. The calculation formula is as follows: V (G) = number of regions = number of decision nodes + 1.

For the case structure or IF-ELSEIF-ELSE structure of multiple branches, pay special attention to the number of nodes in statistical determination, it is required to count all the actual number of decision nodes, that is, each elseif statement, and each case statement should be regarded as a judgment node. It is easy to identify the nodes in the control flow diagram of the module. Therefore, when calculating the circle complexity V (G) for the control flow diagram of the program, it is best to use the first formula, that is, V (G) = E-N + 2. When the control flow diagram of the module is used, you can directly count and determine the number of nodes, which is simpler.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.