Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Application of Graph Criteria: Source Code  It is usually defined with the control flow graph (CFG)  Node coverage is used to execute every statement.

Similar presentations


Presentation on theme: "The Application of Graph Criteria: Source Code  It is usually defined with the control flow graph (CFG)  Node coverage is used to execute every statement."— Presentation transcript:

1 The Application of Graph Criteria: Source Code  It is usually defined with the control flow graph (CFG)  Node coverage is used to execute every statement  Edge coverage is used to execute every branch  Loops are used to execute looping structures such as for loops, while loops, etc.  Data flow coverage is the extended form of control flow graph (CFG) with defs and uses  defs are statements that assign values to variables  uses are statements that use variables

2 Tests with Data Flow Criteria  Data flow criteria require tests that tour subpaths from specific definitions of variables to specific uses  Nodes where a variable is assigned a value are called definitions (or defs)  Nodes where the value of a variable is accessed are called uses.

3 3 Data Flow Coverage for Source  def : A location where a value is stored into memory  x appears on the left side of an assignment ( x = 44 ;  x is an actual parameter in a call and the method changes its value  x is a formal parameter of a method (implicit def when method starts)  x is an input to a program  use : A location where variable’s value is accessed  x appears on the right side of an assignment  x appears in a conditional test  x is an actual parameter to a method  x is an output of the program  x is an output of a method in a return statement  If a def and a use appear on the same node, then it is only a DU-pair if the def occurs after the use and the node is in a loop

4  A definition d for a variable x reaches a use u if there is a path from d to u that has no other definitions of x (def-clear).  The all-uses (AU) criterion requires tests to tour at least one subpath from each definition to each reachable use. // EXAMPLE: return index of the last element in x that equals y. // if y is not in x, return -1. public int findLast (int []x, int y) { for (int i = x.length-1; i>=0; i--) { if (x[i] == y) return i; } return -1;

5 Annotated Control Graph  Nodes 4 and 6 are final nodes, corresponding to the return statements.  Node 2 is introduced to capture the for loop; it has no executable statements.  DU (def-use) pairs are shown as a variable name followed by the def node, then the use node. use(3)= def (5) = { i } use (5) = { i } Def -Use Pairs = { (1, 1,x), (1,3,x), (1,3,y), (1, 2,i), (1, 3,i), (1,5,i), (1,6,i), (5, 2,i), (5, 3,i), ( 5, 6,i), (5, 5,i)}

6 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 ]; } med = numbers [ length / 2]; mean = sum / (double) length; varsum = 0; for (int i = 0; i < length; i++) { varsum = varsum + ((numbers [ I ] - mean) * (numbers [ I ] - mean)); } var = varsum / ( length - 1.0 ); sd = Math.sqrt ( var ); System.out.println ("length: " + length); System.out.println ("mean: " + mean); System.out.println ("median: " + med); System.out.println ("variance: " + var); System.out.println ( "standard deviation: " + sd); } 6 i = 0 1 2 3 5 4 6 7 8 i >= length i < length i++

7 Edge Coverage 7 1 2 3 5 4 6 8 7 TR = {[ 1, 2 ],[ 2, 3 ],[ 3, 4 ], [ 3, 5 ], [ 4, 3 ], [ 5, 6 ], [ 6, 7 ], [ 6, 8 ],[ 7, 6 ]} Test Path, 3, 4, 3, 5, 6, 7, 6, 8 ] [ 1, 2, 3,4, 3, 5, 6, 7, 6, 8] ]

8 Edge-Pair Coverage TR={ [ 1, 2, 3 ], [ 2, 3, 4 ], [ 2, 3, 5 ], [ 3, 4, 3 ], [ 3, 5, 6 ], [ 4, 3, 5 ],[ 5, 6, 7 ],[ 5, 6, 8 ], [ 6, 7, 6 ], [ 7, 6, 8 ], [ 4, 3, 4 ], [ 7, 6, 7 ]} Test Paths i.[ 1, 2, 3, 4, 3, 5, 6, 7, 6, 8 ] ii. [ 1, 2, 3, 5, 6, 8 ] iii. [ 1, 2, 3, 4, 3, 4, 3, 5, 6, 7, 6, 7, 6, 8 ] Test Requirements Toured i.[ 1, 2, 3 ], [ 2, 3, 4 ], [ 3, 4, 3 ], [ 3, 5, 6 ], [ 4, 3, 5 ], [ 5, 6, 7], [ 6, 7, 6 ], [ 7, 6, 8 ] ii. [ 1, 2, 3 ], [ 2, 3, 5 ], [ 3, 5, 6 ], [ 5, 6, 8 ] iii. [ 1, 2, 3 ], [ 2, 3, 4 ], [ 3, 4, 3 ], [ 3, 5, 6 ], [ 4, 3, 5 ], [ 5, 6, 7 ],[ 6, 7, 6 ],[ 7, 6, 8 ], [ 4, 3, 4 ], [ 7, 6, 7 ] 8

9 Prime Path Coverage TR={ [ 3, 4, 3 ],[ 4, 3, 4 ],[ 7, 6, 7 ], [ 7, 6, 8 ], [ 6, 7, 6 ], [ 1, 2, 3, 4 ], [ 4, 3, 5, 6, 7 ], [ 4, 3, 5, 6, 8 ], [ 1, 2, 3, 5, 6, 7 ], [ 1, 2, 3, 5, 6, 8 ]} Test Paths i. [ 1, 2, 3, 4, 3, 5, 6, 7, 6, 8 ] ii. [ 1, 2, 3, 4, 3, 4, 3, 5, 6, 7, 6, 7, 6, 8 ] iii. [ 1, 2, 3, 4, 3, 5, 6, 8 ] iv. [ 1, 2, 3, 5, 6, 7, 6, 8 ] v.[ 1, 2, 3, 5, 6, 8 ] Test Requirements Toured i. [ 3, 4, 3 ], [ 7, 6, 8 ], [ 6, 7, 6 ], [ 1, 2, 3, 4 ], [ 4, 3, 5, 6, 7 ] ii. [ 3, 4, 3 ], [ 4, 3, 4 ], [ 7, 6, 7 ], [ 7, 6, 8 ], [ 6, 7, 6 ], [ 1, 2, 3, 4 ] [ 4, 3, 5, 6, 7 ] iii. [ 3, 4, 3 ], [ 1, 2, 3, 4 ], [ 4, 3, 5, 6, 8 ] iv. [ 7, 6, 8 ], [ 6, 7, 6 ], [ 1, 2, 3, 4 ], [ 1, 2, 3, 5, 6, 7 ] v.. [ 1, 2, 3, 5, 6, 8 ], 9


Download ppt "The Application of Graph Criteria: Source Code  It is usually defined with the control flow graph (CFG)  Node coverage is used to execute every statement."

Similar presentations


Ads by Google