SWE 437 In Class Exercise # 13
Test Coverage Criteria


Names:

Instructions: Work with your neighbors in groups. This is an exercise designed to motivate the coverage criteria that we'll be studying in the second half of this semester.
public static int oddOrPos (int[] x) {  
   // If x is null throw NPE else return # of elements that are odd or pos
   int count = 0;
   
   for (int i = 0; i < x.length; i++) {
      // Faulty "odd rule" that doesn't handle negative values
      if (x[i]%2 == 1 || x[i] > 0) { count++; }

      // One possible correction is:
      // if (!(x[i]%2) == 0) || x[i] > 0) { count++; }

      // A refactored correction is:
      // if (!(x[i]%2) == 0)) { count++; }
      // else if (x[i] > 0) { count ++; }
   }
   return count;
}
  1. What is the input domain, and what are some relevant properties for characterizing that input domain? Try to turn these properties into tests. What decisions are you making during this process?


  2. What is a possible graph model for this code? Try to derive some tests from this graph model. What decisions are you making during this process? What happens to your tests if you refactor the code?


  3. What is a logic model for this program? Try to derive tests from this logic model. What decisions are you making during this process? What happens to the tests if you refactor the code?


  4. What is a possible syntactic structure model for this program? Try to derive tests from this structural model. What decisions are you making during this process? What happens to the tests if you refactor the code?