CS 585-001  Homework 2
Spring 2011
Graph Coverage: Due 2/3/11, before class


Never test for a bug you don't know how to fix.
- Mike McCracken


Answer the following questions. Bring hardcopies of your answers to class, hand written or printouts. All homeworks are due before class on the due date. Please remember that the UK Honor Code is in effect: Each student is expected to work alone and you may not share solutions or solution ideas.

Use the following main program for primes() for the questions below. The complete program primes.java is available for your reference.


// Finds and prints n prime integers
private static void printPrimes (int n)
{
   int curPrime;           // Value currently considered for primeness
   int numPrimes;          // Number of primes found so far.
   boolean isPrime;        // Is curPrime prime?
   int [] primes = new int [MAXPRIMES]; // The list of prime numbers.
 
   // Initialize 2 into the list of primes.
   primes [0] = 2;
   numPrimes = 1;
   curPrime  = 2;
   while (numPrimes < n)
   {
      curPrime++;  // next number to consider ...
      isPrime = true;
      for (int i = 0; i <= numPrimes-1; i++)
      {  // for each previous prime.
         if (isDivisible (primes[i], curPrime))
         {  // Found a divisor, curPrime is not prime.
            isPrime = false;
            break; // out of loop through primes.
         }
      }
      if (isPrime)
      {  // save it!
         primes[numPrimes] = curPrime;
         numPrimes++;
      }
   }  // End while
 
   // Print all the primes out.
   for (int i = 0; i <= numPrimes-1; i++)
   {
      System.out.println ("Prime: " + primes[i]);
   }
}  // end printPrimes

  1. (4 pts) Draw the control flow graph for the printPrimes() method.
  2. (4 pts) Please note correction: Consider test cases t1 = (n=3) and t2 = (n=5). Although these tour the same test path in printPrimes(), they do not necessarily find the same faults. Identify a simple fault that t1 would be more likely to discover than t2 would.
  3. (4 pts) For printPrimes(), find a test case such that the corresponding test path visits the edge that connects the beginning of the while statement to the for statement without going through the body of the while loop.
  4. (7 pts) Enumerate the test requirements for Node Coverage, Edge Coverage, and Loop-Free Path Coverage for the graph for printPrimes().
  5. (4 pts) Identify a set of test paths that achieves Node Coverage but not Edge Coverage on the graph.

© Paul Ammann and Jeff Offutt, 2003, all rights reserved. This document is made available for use by GMU graduate students of SWE 637. Copying, distribution or other use of this document without express permission of the author is forbidden. You may create links to pages in this web site, but may not copy all or part of the text without permission of the author.