In this technique, we do not use the code to determine a test suite; rather,
knowing the problem that we're trying to solve, we come up with four types of
test data:
Easy-to-compute data
Typical data
Boundary / extreme data
Bogus data
For example, suppose we are testing a function that uses the quadratic formula
to determine the two roots of a second-degree polynomial ax2+bx+c.
For simplicity, assume that we are going to work only with real numbers, and
print an error message if it turns out that the two roots are complex numbers
(numbers involving the square root of a negative number).
We can come up with test data for each of the four cases, based on values of
the polynomial's discriminant (b2-4ac):
Easy data (discriminant is a perfect square):
a
b
c
Roots
1
2
1
-1, -1
1
3
2
-1, -2
Typical data (discriminant is positive):
a
b
c
Roots
1
4
1
-3.73205, -0.267949
2
4
1
-1.70711, -0.292893
Boundary / extreme data (discriminant is zero):
a
b
c
Roots
2
-4
2
1, 1
2
-8
8
2, 2
Bogus data (discriminant is negative, or a is zero):
a
b
c
Roots
1
1
1
square root of negative number
0
1
1
division by zero
As with glass-box testing, you should test your code with each set of test
data. If the answers match, then your code passes the black-box test.