Control Structure Testing Homework

Problem #1

A data analysis program calculates the high and low temperatures from 24 hourly temperature readings.  The program is described in Nell Dale, et. al. "Programming and Problem Solving in C++" p 292.  The Java version is here: HiLoTemps.java

Use the Branch Testing method to derive a set of system test cases for the entire application.  Use the white box test worksheet form to record your planned test data.   

Problem #2

Use the Branch Testing method to derive a set of unit test cases for the public method below.   Use the white box test worksheet form to record your planned test data.   


/**
 *  Greatest Common Divisor utility class
 */
public class GCD
{
   /** Find the GCD of two integers.  */
   public static int findGCD(int num1, int num2)
   {
      while (num1 != num2)
      {
         if (num1 > num2)
         {
            num1 = num1 - num2;
         }
         else
         {
            num2 = num2 - num1;
         }
      }
      return num1;
   }
}

Problem #3

Complete the Utility Bill testing problem.

Problem #4

Use the Loop Testing method to derive a set of unit test cases for the loop in the public method below.   Use the white box test worksheet form to record your planned test data. 
Assume that Sentence is a string of maximum length 25.

    public static String sanitize(Sentence suspect)
    {
       // allow alphanumerics or period or underline
       final String kAllowedCharacters = "abcdefghijklmnopqrstuvwxyz"
        + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "0123456789" + "._";

        StringBuffer result = new StringBuffer();
	// Examine each character in the suspect string
        for (int i=0; i<suspect.length(); i++)
        {
            char current = suspect.charAt(i);
            // Is the character allowed?
            if (kAllowedCharacters.indexOf(current) >= 0)
            {
                result.append(current);
            }
        }
        return result.toString();
    }