
CPSC 6178 Software Testing and Quality Assurance
Homework Set 4 Due Friday, November 18, 2005
KEY WITH ANSWERS AND COMMENTS.
1. We are asked to test a function that takes two pairs of points in a plane, (X1, Y1) and
(X2, Y2) and produces the slope of the line connecting the two points. The result refers
to the use of an equation of the form Y = MX + B to describe the line.
Devise a number of tests and specify them in the form (X1, Y1, X2, Y2, M) – that is,
the two points and the expected result – that will test the correct functioning of the
software. Allow for both positive and negative slopes. Hint: Only four test cases
are required, one of which cannot easily be specified by the 5–tuple.
ANSWERS: We begin with the expected answers and then continue the discussion.
For this discussion, consider four distinct real numbers (A, B, C, D), with no two equal.
The basic four scenarios (and an extra one) for testing are the following.
1. Let X1 = A, X2 = B, Y1 = C, Y2 = D and verify that M = (D – C) / (B – A),
2. Let X1 = B, X2 = A, Y1 = C, Y2 = D and verify that M = (D – C) / (A – B).
One might verify that this is the negative of the first slope.
3. Let X1 = A, X2 = B, Y1 = C, Y2 = C and verify that M = 0.
4. Let X1 = A, X2 = A, Y1 = C, Y2 = D and verify that an exception is raised properly.
5. Let X1 = A, X2 = A, Y1 = C, Y2 = C and investigate the return value.
For those who want to push the arithmetic precision issue, here is a test that might be run.
// Assume that x1 and y1 have been given numeric values at this point.
// Assume that all numeric variables are declared identically: either float or double.
// The sole exception to this rule is the integer counter n, declared as type int.
//
try { y2 = y1 + 1.0 ;
delta = 1.0 ;
x2 = x1 + 1.0 ; // Really x2 = x1 + (1.0 / delta )
n = 1 ;
while ( x2 > x1 ) // This allows for the precision of the type
{ slope (x1, x2, y1, y2, m ) ;
println ( format_string, n, delta, m ) ;
delta = delta * 8.0 ; // Later division by 10 introduces imprecision.
n = n + 1 ;
x2 = x1 + (1.0 / delta) ; // Shrink the X interval
} ;
println ( format_string, “Normal termination ”)
return ;
} ;
catch { // catch any numeric overflow here
println ( format_string, “Numeric overflow for delta = ” , delta ) ;
} ;