SWE 637 Quiz Number 5
February 25, 2009


Note: This is the version of the quiz given in class:

Consider the following code:

   1: public void trash (int x) {
   2:    int n, m;
   3:    m = 0;
   4:    if (x>0)  m = 4;
   5:    if (x > 5) 
   6:       n = 3*m 
   7:    else 
   8:       n = 4*m;
   9:    int o = takeOut(n, m);            // Note Order
   10:     System.out.println("o is: " + o);
   11: }
   12: public int takeOut (int a, int b) {
   13:   int d, e;
   14:   d = 42*a;
   15:   if (a>0) 
   16:      e = 2*b+d; 
   17:   else 
   18:      e = b+d;
   19:   return e;
   20: }
  1. Give all last-def / first-use pairs. You don't have to name the interface; variable names and line numbers are sufficient. Hint: You should get a total of 8 associations.
    Answer:
       1: (m,3) -> (b,16)
       2: (m,3) -> (b,18)
       3: (m,4) -> (b,16)
       4: (m,4) -> (b,18)
       5: (n,6) -> (a,14)
       6: (n,8) -> (a,14)
       7: (e,16) -> (o,10)
       8: (e,18) -> (o,10)
    
  2. Provide test inputs that satisfy all-coupling-uses. Note that trash() only has one input.
    Answer: The key to note here is that there really only 3 possible tests here as far as coupling relations are concerned:
       x = 0 covers 2, 6, and 8
       x = 1 covers 3, 6, and 7
       x = 6 covers 3, 5, and 7
       
    Note that the second test doesn't add anything in terms of coverage.
  3. One of the associations cannot be covered. Which one?
    Answer: Actually, for the typo quiz, 2 associations are infeasible.
    They are (m,3) to (b,16) and (m,4) to (b,18).
Grading Notes: