SWE 637 Homework 1 Solution
Fall 2006
Preliminary Concepts: Due 9/5, beginning of class


The true subject matter of the tester is not testing, but the design of test cases.

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 GMU Honor Code is in effect: Each student is expected to work alone and you may not share solutions or solution ideas.

Consider the following program:
     public class firsthwk
     {
     public static int nameCheck (char[] names)
     {
     // Effects: Checks a list of names and counts how many blanks
        int blankCount = 0;
        for (int i = names.length; i > 1; i--)
        {
           if (names[i-1] == ' ')
           {
              blankCount++;
           }
        }
        return blankCount;
     }

     public static void main (String args[])
     {
        // Test driver -- method calls to nameCheck()
     }
     }
  1. Compile this program using a Java compiler. You will need to modify the main() method to contain calls to the nameCheck() method and print the result. (Each call to the method represents one test case.) Submit a hard-copy printout of your complete program, with your main().
  2. This program contains a fault. What is it? Does executing the program necessarily result in either incorrect output or in failure?
    The loop is controlled by the length of the array names. The first element names[0] is not checked, so the method only fails if element 0 is a blank.
  3. Find a test case that results in failure. Verify by executing this test case.
    char arr1 [] = {' ', ' ', ' ', 'c', 'd'};
    System.out.println ("num blanks: " + nameCheck (arr1) + " ... expected output: 3");
  4. Identify another test case that does not result in failure. Verify by executing this test case.
    char arr2 [] = {'a', 'b', ' ', 'c', ' '};
    System.out.println ("num blanks: " + nameCheck (arr2) + " ... expected output: 2");
  5. Find tests to execute every statement in the method nameCheck(). Find the minimal set, that is, turn in a set of tests such that if any one test was removed, the remaining tests would no longer execute every statement.
    Both tests above execute every statement, so either one without the other answers the question.