Activity: Graph coverage for design element

(no submission)

Purpose: Understand and apply graph coverage to test various parts of the software design; get ready for assignment 4; prepare for the final exam

You may make a copy of a worksheet and complete this activity, or simply type your answers in any text editor.

You may work alone or with at most two other students in this course.


Consider the trashgraph class

// Modified from https://cs.gmu.edu/~offutt/softwaretest/java/TrashAndTakeOut.java

   1.   public class trashgraph 
   2.   {
   3.      public static void trash(int x) 
   4.      {
   5.         int m, n;
   6.         m = 0;
   7.         if (x > 0)
   8.            m = 4;
   9.         if (x > 5)
  10.            n = 3 * m;
  11.         else
  12.            n = 4 * m;
  13.         int o = takeOut(m, n);
  14.         System.out.println("o is: " + o);
  15.      }
  16. 
  17.      public static int takeOut(int a, int b) 
  18.      {
  19.         int d, e;
  20.         d = 42 * a;
  21.         if (a > 0)
  22.            e = 2 * b + d;
  23.         else
  24.            e = b + d;
  25.         return(e);
  26.      }   
  27.   }    
  1. Locate a call site between trash() and takeOut() methods. You may circle directly in the source code.
    
    
  2. Write down all variables that are shared or passed between trash() and takeOut() methods.
  3. Find all coupling last-defs and first-uses. Circle directly in the source code. Write down whether that circle is for last-def or first-use.
       
             
  4. Draw a graph representation of the trash() and takeOut() method. Be sure to include coupling between the caller and the callee. (You may draw the graph by hand, take a screenshot of your graph, and embed it in your write-up)
          
            
  5. Find all the coupling DU-pairs.

    Write them down as pairs of triplets. Each triplet is a method name, variable name, and node. The pair has the last-def on the left and a first-use on the right. For example:
    (method1(), var1, node1) — (method2(), var2, node2)
    where last-def of a variable var1 is in method method1 at node node1 and
    first-use of a variable var1 appears as a variable var2 in method method2 at node node2.

    Note: in general, if a graph is unavailable or has not been created, each triplet can be written as
    (method1(), var1, line1) — (method2(), var2, line2)
    where last-def of a variable var1 is in method method1 at line number line1 and
    first-use of a variable var1 appears as a variable var2 in method method2 at line number line2.

            
            
  6. List test requirements (i.e., Coupling DU-paths for each variable) that satisfy All-Coupling-Defs coverage
            
            
  7. List test requirements (i.e., Coupling DU-paths for each variable) that satisfy All-Coupling-Uses coverage
            
            
  8. List test requirements (i.e., Coupling DU-paths for each variable) that satisfy All-Coupling-DU-Paths coverage
            
            
  9. Provide test inputs that satisfy All-Coupling-Uses (note that trash() only has one input)
            
            

[optional]
For more hands-on experience, take the test inputs you provided to satisfy All-Coupling-Uses, construct a set of test cases, and then automate your test set (in JUnit) and run it against the trashgraph class.


Copyright © 2025 Upsorn Praphamontripong
Released under the Creative Commons License CC-BY-NC-SA 4.0 license.
Last updated 2025-10-06 14:46