A Complexity Measure THOMAS J. McCABE Presented by Sarochapol Rattanasopinswat.

Slides:



Advertisements
Similar presentations
Software Testing Technique. Introduction Software Testing is the process of executing a program or system with the intent of finding errors. It involves.
Advertisements

Chapter 8 Topics in Graph Theory
Path Analysis Why path analysis for test case design?
Chapter 6 Path Testing Software Testing
Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing.
1 Ivan Marsic Rutgers University LECTURE 15: Software Complexity Metrics.
CYCLOMATIC COMPLEXITY 1. Invented by Thomas McCabe (1974) to measure the complexity of a program ’ s conditional logic Cyclomatic complexity of graph.
SOFTWARE TESTING. INTRODUCTION  Software Testing is the process of executing a program or system with the intent of finding errors.  It involves any.
Lecture 21 Paths and Circuits CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.
David Woo (dxw07u).  What is “White Box Testing”  Data Processing and Calculation Correctness Tests  Correctness Tests:  Path Coverage  Line Coverage.
1 Static Testing: defect prevention SIM objectives Able to list various type of structured group examinations (manual checking) Able to statically.
1 Static Analysis Methods CSSE 376 Software Quality Assurance Rose-Hulman Institute of Technology March 20, 2007.
White Box Testing Techniques Dynamic Testing. White box testing(1) Source code is known and used for test design While executing the test cases, the internal.
BASIS PATH TESTING ● By Tom McCabe ● McCabe, T., "A Software Complexity Measure," IEEE Trans. Software Engineering, vol. SE-2, December 1976, pp
Chapter 18 Testing Conventional Applications
Unit Testing CS 414 – Software Engineering I Don Bagert Rose-Hulman Institute of Technology January 16, 2003.
Path testing Path testing is a “design structural testing” in that it is based on detailed design & the source code of the program to be tested. The methodology.
Cyclomatic Complexity Dan Fleck Fall 2009 Dan Fleck Fall 2009.
Software Reliability Model Deterministic Models Probabilistic Models Halstead’s software metric McCabe’s cyclomatic complexity metrix Error seeding Failure.
Software Systems Verification and Validation Laboratory Assignment 3
Zvi Kohavi and Niraj K. Jha 1 Capabilities, Minimization, and Transformation of Sequential Machines.
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 20 Slide 1 Defect testing l Testing programs to establish the presence of system defects.
Zvi Kohavi and Niraj K. Jha 1 Memory, Definiteness, and Information Losslessness of Finite Automata.
Agenda Introduction Overview of White-box testing Basis path testing
Software Metrics (Part II). Product Metrics  Product metrics are generally concerned with the structure of the source code (example LOC).  Product metrics.
INTRUDUCTION TO SOFTWARE TESTING TECHNIQUES BY PRADEEP I.
White-box Testing.
V Spanning Trees Spanning Trees v Minimum Spanning Trees Minimum Spanning Trees v Kruskal’s Algorithm v Example Example v Planar Graphs Planar Graphs v.
1 Program Testing (Lecture 14) Prof. R. Mall Dept. of CSE, IIT, Kharagpur.
BASIS PATH TESTING.
Agenda Review: –Planar Graphs Lecture Content:  Concepts of Trees  Spanning Trees  Binary Trees Exercise.
Software Testing White Box Testing. Agenda What is White Box Testing Correctness Tests and Path Coverage Correctness Tests and Line Coverage McCabe Cyclomatic.
Graph Theory and Applications
Chapter 8 Path Testing. Path testing Path testing is a “design structural testing” in that it is based on detailed design & the source code of the program.
1 Control Flow Analysis Topic today Representation and Analysis Paper (Sections 1, 2) For next class: Read Representation and Analysis Paper (Section 3)
White Box Testing Arun Lakhotia University of Southwestern Louisiana P.O. Box Lafayette, LA 70504, USA
Graph theory and networks. Basic definitions  A graph consists of points called vertices (or nodes) and lines called edges (or arcs). Each edge joins.
1 Ivan Marsic Rutgers University LECTURE 15: Software Complexity Metrics.
Theory and Practice of Software Testing
SOFTWARE TESTING. Introduction Software Testing is the process of executing a program or system with the intent of finding errors. It involves any activity.
 Quotient graph  Definition 13: Suppose G(V,E) is a graph and R is a equivalence relation on the set V. We construct the quotient graph G R in the follow.
Agent program is the one part(class)of Othello program. How many test cases do you have to test? Reversi [Othello]
Introduction to Graph Theory
White Box Testing by : Andika Bayu H.
Cyclomatic complexity (or conditional complexity) is a software metric (measurement). Its gives the number of indepented paths through strongly connected.
Cyclomatic Complexity Philippe CHARMAN Last update:
Chromatic Coloring with a Maximum Color Class Bor-Liang Chen Kuo-Ching Huang Chih-Hung Yen* 30 July, 2009.
COMPSCI 102 Introduction to Discrete Mathematics.
(CSC 102) Lecture 30 Discrete Structures. Graphs.
SOFTWARE TESTING LECTURE 9. OBSERVATIONS ABOUT TESTING “ Testing is the process of executing a program with the intention of finding errors. ” – Myers.
Trees.
Outline 1 Properties of Planar Graphs 5/4/2018.
BASIS PATH TESTING.
Software Testing.
Cyclomatic complexity
Software Engineering (CSI 321)
Graph Theory CSRU1400, Fall 2007 Ellen Zhang.
Data Coverage and Code Coverage
Structural testing, Path Testing
White Box Testing.
Constructing and Using
LECTURE 15: Software Complexity Metrics
Graph.
Discrete Math II Howon Kim
Sudipto Ghosh CS 406 Fall 99 November 16, 1999
Control Structure Testing
GRAPH THEORY Properties of Planar Graphs Ch9-1.
Agenda Review Lecture Content: Shortest Path Algorithm
GRAPH THEORY Properties of Planar Graphs Ch9-1.
Unit III – Chapter 3 Path Testing.
Presentation transcript:

A Complexity Measure THOMAS J. McCABE Presented by Sarochapol Rattanasopinswat

INTRODUCTION How to modularize a software system so the resulting modules are both testable and maintainable?  Currently is to limit programs by physical size Not adequate 50 line program consisting of 25 consecutive “IF- THEN” constructs.

A COMPLEXITY MEASURE Measure and control the number of paths through a program. Definition 1 The cyclomatic number V(G) of a graph G with n vertices, e edges, and p connected components is V(G) = e – n + 2p

A COMPLEXITY MEASURE THEOREM 1: In a strongly connected graph G, the cyclomatic number is equal to the maximum number of linearly independent circuits

A COMPLEXITY MEASURE Given a program we will associate with it a directed graph that has unique entry and exit nodes. Each node in the graph corresponds to a block of code in the program where the flow is sequential and the arcs correspond to branches taken in the program. Known as “program control graph”.

A COMPLEXITY MEASURE

From the graph, the maximum number of linearly independent circuits in G is One could choose the following 5 indepentdent circuits in G: B1: (abefa), (beb), (abea), (acfa), (adcfa).

A COMPLEXITY MEASURE Several properties of cyclomatic complexity:  v(G) ≥ 1.  v(G) is the maximum number of linearly independent paths in G; it is the size of a basis set.  Inserting or deleting functional statements to G does not affect v(G).  G has only one path if and only if v(G) = 1.

A COMPLEXITY MEASURE  Inserting a new edge in G increases v(G) by unity.  v(G) depends only on the decision structure of G.

DECOMPOSITION v = e – n + 2p P is the number of connected components. All control graphs will have only one connected component.

DECOMPOSITION

Now, since p = 3, we calculate complexity as v(M ∪ A ∪ B) = e – n + 2p = x3 = 6 Notice that v(M ∪ A ∪ B) = v(M) + v(A) + v(B) = 6.

SIMPLIFICATION 2 ways  Allows the complexity calculations to be done in terms of program syntactic constructs.  Calculate from the graph from.

SIMPLIFICATION First way, the cyclomatic complexity of a structured program equals the number of predicates plus one

SIMPLIFICATION

From the graph, v(G) = ¶ + 1 = = 4

SIMPLIFICATION The second way is by using Euler’s formula:  If G is a connected plane graph with n vertices, e edges, and r regions, then n – e + r = 2  So the number of regions is equal to the cyclomatic complexity.

SIMPLIFICATION

NONSTRUCTURED PROGRAMMING There are four control structures to generate all nonstructured programs.

NONSTRUCTURED PROGRAMMING

NONSTURCTURED PROGRAMMING

NONSTRUCTURED PROGRAMMING Result 1: A necessary and sufficient condition that a program is nonstructured is that it contains as a subgraph either a), b), or c). Result 2: A nonstructured program cannot be just a little nonstructured. That is any nonstructured program must contain at least 2 of the graphs a) – d).

NONSTRUCTURED PROGRAMMING Case 1: E is “before” the loop. E is on a path from entry to the loop so the program must have a graph as follows:

NONSTRUCTURED PROGRAMMING Case 2: E is “after” the loop. The control graph would appear as follows:

NONSTRUCTURED PROGRAMMING Case 3: E is independent of the loop. The graph c) must now be present with b). If there is another path that can go to a node after the loop from E then a type d) graph is also generated.

NONSTRUCTURED PROGRAMMING Result 3: A necessary and sufficient condition for a program to be nonstructured is that it contains at least one of: (a,b), (a,d), (b,c), (c,d).

NONSTRUCTURED PROGRAMMING Result 4: The cyclomatic complexity if a nonstructured program is at least 3. If the graphs (a,b) through (c,d) have their directions taken off, they are all isomorphic.

NONSTRUCTURED PROGRAMMING Result 5: A structured program can be written by not branching out of loops or into decisions - a) and c) provide a basis. Result 6: A structured program can be written by not branching into loops or out of decisions – b) and d) provide a basis. Result 7: A structured program is reducible( process of removing subgraphs (subroutines) with unique entry and exit nodes) to a program of unit complexity.

NONSTRUCTURED PROGRAMMING  Let m be the number of proper subgraphs with unique entry and exit nodes. The following definition of essential complexity ev is used to reflect the lack of structure. ev = v – m Result 8: The essential complexity of a structured program is one.

A TESTING METHODOLOGY Let a program p has been written, its complexity v has been calculated, and the number of paths tested is ac (actual complexity). If ac is less than v then one of the following conditions must be true:  There is more testing to be done (more paths to be tested);  The program flow graph can be reduced in complexity by v-ac (v-ac decisions can be taken out); and  Portions of the program can be reduced to in line code (complexity has increased to conserve space).

A TESTING METHODOLOGY Suppose that ac = 2 and the two tested paths are [E,a1,b,c2,x] and [E,a2,b,c1,x]. Then given that paths [E,a1,b,c1,x] and [E,a2,b,c2,x] cannot be executed.

A TESTING METHODOLOGY We have ac < c so case 2 holds and G can be reduced by removing decision b. Now v = ac and the new complexity is less than the previous one.

A TESTING METHODOLOGY It should be noted that v is only the minimal number of independent paths that should be tested. It should be noted that this procedure will by no means guarantee or prove the software- all it can do is surface more bugs and improve the quality of the software