Cyclomatic Complexity Philippe CHARMAN Last update: 04-02-2013.

Slides:



Advertisements
Similar presentations
Chapter 14 Software Testing Techniques - Testing fundamentals - White-box testing - Black-box testing - Object-oriented testing methods (Source: Pressman,
Advertisements

Chapter 6 Path Testing Software Testing
Some Properties of SSA Mooly Sagiv. Outline Why is it called Static Single Assignment form What does it buy us? How much does it cost us? Open questions.
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.
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.
SOFTWARE TESTING WHITE BOX TESTING 1. GLASS BOX/WHITE BOX TESTING 2.
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.
Exercise Computing the cyclomatic complexity Philippe CHARMAN Last update:
A Complexity Measure THOMAS J. McCABE Presented by Sarochapol Rattanasopinswat.
Cyclomatic Complexity Dan Fleck Fall 2009 Dan Fleck Fall 2009.
Software Systems Verification and Validation Laboratory Assignment 3
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 20 Slide 1 Defect testing l Testing programs to establish the presence of system defects.
Path Testing + Coverage Chapter 9 Assigned reading from Binder.
Agenda Introduction Overview of White-box testing Basis path testing
White-box Testing.
Software Testing and Reliability Southern Methodist University CSE 7314.
Introduction to VSTS Introduction to Visual Studio 2008 Development Edition Understanding code complexity using Code Metrics.
1 Program Testing (Lecture 14) Prof. R. Mall Dept. of CSE, IIT, Kharagpur.
BASIS PATH TESTING.
Creator: ACSession No: 7 Slide No: 1Reviewer: SS CSE300Advanced Software EngineeringSeptember 2005 Software Measurement – Estimation and Productivity CSE300.
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
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.
Agent program is the one part(class)of Othello program. How many test cases do you have to test? Reversi [Othello]
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.
Software Testing Techniques Presented By Dr. Shazzad Hosain.
Software Dynamic White-box Testing Part 2: Data-flow Testing Lecture 7 Prof. Mostafa Abdel Aziem Mostafa.
White-Box Testing Statement coverage Branch coverage Path coverage
SOFTWARE TESTING LECTURE 9. OBSERVATIONS ABOUT TESTING “ Testing is the process of executing a program with the intention of finding errors. ” – Myers.
White Box Testing. Agenda White-box vs Black-box Program Flow Controls White-box Test Methods Exercises Complexity Q&A.
Software Test Metrics When you can measure what you are speaking about and express it in numbers, you know something about it; but when you cannot measure,
Software TestIng White box testing.
BASIS PATH TESTING.
Metrics of Software Quality
Cyclomatic Complexity
Software Testing.
White-Box Testing Pfleeger, S. Software Engineering Theory and Practice 2nd Edition. Prentice Hall, Ghezzi, C. et al., Fundamentals of Software Engineering.
Software Testing.
Cyclomatic complexity
Software Engineering (CSI 321)
Data Coverage and Code Coverage
Structural testing, Path Testing
Types of Testing Visit to more Learning Resources.
White Box Testing.
Cyclomatic Complexity
Cyclomatic Complexity
Software Testing (Lecture 11-a)
Cyclomatic Complexity
LECTURE 15: Software Complexity Metrics
Network Notes Ms Allan 2012 AS91260 (2.5) Designed to teach from,
Cyclomatic Complexity
Solution to problem 4. a) Control flow graph art Start k = i + 2 * j
How does the complexity of the flow of control affect test cases?
White-Box Testing Techniques I
Cyclomatic Complexity
Control Structure Testing
Program Flow.
1. Cyclomatic complexity
Unit III – Chapter 3 Path Testing.
Presentation transcript:

Cyclomatic Complexity Philippe CHARMAN Last update:

Control Flow Graph Definition: representation, using graph notation, of all paths that might be traversed through a program during its execution Node –Function node: –Predicate node: –Empty nodes: Edge: –connection between 2 nodes, –represents the flow of control between 2 nodes c entryexit f

Control Flow Graph c entry exit f f f

Cyclomatic Complexity Cyclomatic complexity is a software metric developed by McCabe in 1976 and is used to indicate the complexity of a program The cyclomatic complexity v(G) of a single function/method is equal to: v(G) = E − N + 2 where E = the number of edges N = the number of nodes

Example #1 int f1(int x){ return x+1; } E = 2 N = 3 v(G) = 2 – = 1 entry exit x+1

Example #2 int f2(int x, int y) { x = a(); y = b(); return x+y; } E = 4 N = 5 v(G) = 1 entry exit x=a() y=b() x+y

Example #3 void f3(int x) { if (x == 0) g(); else h(); } E = 6 N = 6 v(G) = 2 entry exit if true false g() h()

Example #4 void f4(int x) { if (x == 0) g(); } E = 5 N = 5 v(G) = 2 entry exit if truefalse g()

Example #5 void f5(int x) { if (x == 0) return; else h(); } E = 5 N = 5 v(G) = 2 entry exit if true false h()

Example #6 void f6(int x) { if (x > 0) a(); else b(); if (odd (x)) c(); else d(); } E = 11 N = 10 v(G) = 3 if entry exit true false true false a() b() d() c()

Example #7 void f7(int x, int y) { if (x > 0) { if (y > 0) a(); else b(); } else { if (y > 0) c(); else d(); } E = 14 N = 12 v(G) = 4 if entry if exit true false true false true false a() b() c() d()

Example #8 void f8(int x) { switch (x) { case 0: a(); break; case 1: b(); break(); case 2: c(); break; } E = 10 N = 8 v(G) = 4 switch entry exit a() b()c()

Example #9 void f9(int x) { if (x == 0) a(); if (x == 1) b(); if (x == 2) c(); } E = 13 N = 11 v(G) = 4 entry if exit a() b() c()

Example #10 void f10(int n) { for (int i = 0 ; i < n ; i++) { a(); } E = 5 N = 5 v(G) = 2 entry exit i < n true false a() i = 0

Example #11 E = 13 N = 10 v(G) = 5

Cyclomatic Complexity for a single function/method Cyclomatic complexity = #edges - #nodes +2 Cyclomatic complexity = number of linearly independent paths Cyclomatic complexity = number of decision points + 1 Cyclomatic complexity = numbers of regions of the flow graph providing edges are not crossing each other Be careful with simple rules such as add 1 to each if, add 1 to each switch/case, add 1 to each switch/default, et.

v(G) = Number of regions entry a() exit b() x+y a()b() if c()d() if entry exit

Cyclomatic Complexity Cyclomatic Risk Complexity 1-10A simple, low risk program 11-20Moderate complexity, risk complexity 21-50Complex, high risk > 50High risk, detestable program