Ch2-3-sourceCode

# Ch2-3-sourceCode - Overview Introduction to Software...

This preview shows pages 1–3. Sign up to view the full content.

Introduction to Software Testing Chapter 2.3 Graph Coverage for Source Code www.introsoftwaretesting.com Introduction to Software Testing (Ch 2), www.introsoftwaretesting.com 2 Overview The most usual application of graph criteria is to program source Graph : Usually the control flow graph (CFG) Node coverage : execute every statement Edge coverage : execute every branch Loops : looping structures such as for loops, while loops, etc. Data flow coverage : augment the CFG defs are statements that assign values to variables uses are statements that use variables Introduction to Software Testing (Ch 2), www.introsoftwaretesting.com 3 Control Flow Graphs A CFG models all executions of a method by describing control structures Nodes : statements or sequences of statements (basic blocks) Edges : transfers of control Basic Block : A sequence of statements such that if the first statement is executed, all statements will be (no branches) CFGs are sometimes annotated with extra information branch predicates defs uses Rules for translating statements into graphs … Introduction to Software Testing (Ch 2), www.introsoftwaretesting.com 4 CFG : The if Statement if (x < y) { y = 0; x = x + 1; } else { x = y; } 4 1 2 3 x >= y x < y x = y y = 0 x = x + 1 if (x < y) { y = 0; x = x + 1; } 3 1 2 x >= y x < y y = 0 x = x + 1 Introduction to Software Testing (Ch 2), www.introsoftwaretesting.com 5 CFG : The if-Return Statement if (x < y) { return; } print (x); return; 3 1 2 x >= y x < y return print (x) return NO edge from node 2 to 3. The return nodes must be distinct. Introduction to Software Testing (Ch 2), www.introsoftwaretesting.com 6 Loops Loops require “ extra ” nodes to be added Nodes that do not represent statements or basic blocks

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Introduction to Software Testing (Ch 2), www.introsoftwaretesting.com 7 CFG : while and for Loops x = 0; while (x < y) { y = f (x, y); x = x + 1; } 1 x = 0 4 3 y =f(x,y) x = x + 1 x >= y x < y for (x = 0; x < y; x++) { y = f (x, y); } 1 x = x + 1 2 3 5 x >= y x < y y = f (x, y) 4 2 dummy node x = 0 implicitly initializes loop implicitly increments loop Introduction to Software Testing (Ch 2), www.introsoftwaretesting.com 8 CFG : The case (switch) Structure read ( c) ; switch ( c ) { case ‘N’: y = 25; break; case ‘Y’: y = 50; break; default: y = 0; break; } print (y); 5 1 read ( c ); c == ‘N’ y = 0; break; 2 4 3 c == ‘Y’ default y = 50; break; y = 25; break; print (y); Introduction to Software Testing (Ch 2), www.introsoftwaretesting.com 9 Example Control Flow – Stats public static void computeStats (int [ ] numbers) { int length = numbers.length; double med, var, sd, mean, sum, varsum; sum = 0; for (int i = 0; i < length; i++) { sum += numbers [ i ];
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 05/29/2010 for the course CS 514 taught by Professor Prof.j.bieman during the Fall '09 term at Colorado State.

### Page1 / 4

Ch2-3-sourceCode - Overview Introduction to Software...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online