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.
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;
}
}
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();
}