Cyclomatic Complexity
17.4.2 Cyclomatic Complexity
Cyclomatic complexity is a software metric that provides a quantitative measure of the logical complexity of a program. When used in the context of the basis path testing method, the value computed for cyclomatic complexity defines the number of inde- pendent paths in the basis set of a program and provides us with an upper bound for the number of tests that must be conducted to ensure that all statements have been executed at least once.
An independent path is any path through the program that introduces at least one new set of processing statements or a new condition. When stated in terms of a flow
4 A more-detailed discussion of graphs and their use in testing is contained in Section 17.6.1.
F I G U R E 17.2
Flowchart, (A) and flow graph (B)
9 R 1 Region R 4
11 (B)
PA R T T H R E E C O N V E N T I O N A L M E T H O D S F O R S O F T WA R E E N G I N E E R I N G
F I G U R E 17.3
Compound logic
Predicate
node
. IF a OR b then procedure x
else procedure y ENDIF
graph, an independent path must move along at least one edge that has not been tra- versed before the path is defined. For example, a set of independent paths for the flow graph illustrated in Figure 17.2B is
path 1: 1-11 path 2: 1-2-3-4-5-10-1-11 path 3: 1-2-3-6-8-9-10-1-11 path 4: 1-2-3-6-7-9-10-1-11
Note that each new path introduces a new edge. The path Cyclomatic complexity
1-2-3-4-5-10-1-2-3-6-8-9-10-1-11 is a useful metric for
is not considered to be an independent path because it is simply a combination of predicting those modules that are likely already specified paths and does not traverse any new edges.
to be error prone. It Paths 1, 2, 3, and 4 constitute a basis set for the flow graph in Figure 17.2B. That can be used for test
is, if tests can be designed to force execution of these paths (a basis set), every state- planning as well as
ment in the program will have been guaranteed to be executed at least one time and test case design. every condition will have been executed on its true and false sides. It should be noted
that the basis set is not unique. In fact, a number of different basis sets can be derived for a given procedural design.
How do we know how many paths to look for? The computation of cyclomatic complexity provides the answer. Cyclomatic complexity has a foundation in graph theory and provides us with an extremely useful software metric. Complexity is computed in one of three ways:
? 1. The number of regions of the flow graph correspond to the cyclomatic com-
How is
cyclomatic
plexity.
complexity computed?
2. Cyclomatic complexity, V(G), for a flow graph, G, is defined as 2. Cyclomatic complexity, V(G), for a flow graph, G, is defined as
Cyclomatic complexity
3. Cyclomatic complexity, V(G), for a flow graph, G, is also defined as provides the upper
V(G) = P + 1
bound on the number of test cases that must
where P is the number of predicate nodes contained in the flow graph G.
be executed to guarantee that every
Referring once more to the flow graph in Figure 17.2B, the cyclomatic complexity statement in a
can be computed using each of the algorithms just noted: component has been executed at least once.
1. The flow graph has four regions.
3. V(G) = 3 predicate nodes + 1 = 4. Therefore, the cyclomatic complexity of the flow graph in Figure 17.2B is 4.
More important, the value for V(G) provides us with an upper bound for the num- ber of independent paths that form the basis set and, by implication, an upper bound on the number of tests that must be designed and executed to guarantee coverage of all program statements.
Parts
» The Concurrent Development Model
» SUMMARY Software engineering is a discipline that integrates process, methods, and tools for
» PEOPLE In a study published by the IEEE [CUR88], the engineering vice presidents of three
» THE PROCESS The generic phases that characterize the software process—definition, development,
» THE PROJECT In order to manage a successful software project, we must understand what can go
» METRICS IN THE PROCESS AND PROJECT DOMAINS
» Extended Function Point Metrics
» METRICS FOR SOFTWARE QUALITY
» INTEGRATING METRICS WITHIN THE SOFTWARE PROCESS
» METRICS FOR SMALL ORGANIZATIONS
» ESTABLISHING A SOFTWARE METRICS PROGRAM
» Obtaining Information Necessary for Scope
» An Example of LOC-Based Estimation
» QUALITY CONCEPTS 1 It has been said that no two snowflakes are alike. Certainly when we watch snow
» SUMMARY Software quality assurance is an umbrella activity that is applied at each step in the
» R diagram 1.4 <part-of> data model; data model <part-of> design specification;
» SYSTEM MODELING Every computer-based system can be modeled as an information transform using an
» Facilitated Application Specification Techniques
» Data Objects, Attributes, and Relationships
» Entity/Relationship Diagrams
» Hatley and Pirbhai Extensions
» Creating an Entity/Relationship Diagram
» SUMMARY Design is the technical kernel of software engineering. During design, progressive
» Data Modeling, Data Structures, Databases, and the Data Warehouse
» Data Design at the Component Level
» A Brief Taxonomy of Styles and Patterns
» Quantitative Guidance for Architectural Design
» Isolate the transform center by specifying incoming and outgoing
» SUMMARY Software architecture provides a holistic view of the system to be built. It depicts the
» The User Interface Design Process
» Defining Interface Objects and Actions
» D E S I G N E VA L U AT I O N
» Testing for Real-Time Systems
» Organizing for Software Testing
» Criteria for Completion of Testing
» The Transition to a Quantitative View
» The Attributes of Effective Software Metrics
» Architectural Design Metrics
» Component-Level Design Metrics
» SUMMARY Software metrics provide a quantitative way to assess the quality of internal product
» Encapsulation, Inheritance, and Polymorphism
» Identifying Classes and Objects
» The Common Process Framework for OO
» OO Project Metrics and Estimation
» Event Identification with Use-Cases
» SUMMARY Object-oriented analysis methods enable a software engineer to model a problem by
» Partitioning the Analysis Model
» Designing Algorithms and Data Structures
» Program Components and Interfaces
» SUMMARY Object-oriented design translates the OOA model of the real world into an
» Testing Surface Structure and Deep Structure
» Deficiencies of Less Formal Approaches 1
» What Makes Cleanroom Different?
» Design Refinement and Verification
» SUMMARY Cleanroom software engineering is a formal approach to software development that
» Structural Modeling and Structure Points
» Describing Reusable Components
» SUMMARY Component-based software engineering offers inherent benefits in software quality,
» Guidelines for Distributing Application Subsystems
» Middleware and Object Request Broker Architectures
» An Overview of a Design Approach
» Consider expert Web developer will create a complete design, but time and cost can be appropriate
» A Software Reengineering Process Model
» Reverse Engineering to Understand Data
» Forward Engineering for Client/Server Architectures
» SUMMARY Reengineering occurs at two different levels of abstraction. At the business level,
Show more