Java Reference
In-Depth Information
6.4.4
Test
We have two main components in the architecture and we test them sepa-
rately. Table 6.4 describes a test case; it presents a list of commands issued
to the calculator, the resulting values of the first and second operands and
the format being used.
First we test the calculator component invoking the methods of class
Calculator directly. The following test method implements the first three
lines of Table 6.4.
public class TestCalculator extends TestCase {
//...
public void testOperations(){
Calculator calc # new Calculator();
try {
calc.addOperand("3.2");
assertEquals("0.0",calc.firstOperand());
assertEquals("3.2",calc.secondOperand());
calc.addOperand("2.8");
assertEquals("3.2",calc.firstOperand());
assertEquals("2.8",calc.secondOperand());
calc.add();
assertEquals("0.0",calc.firstOperand());
assertEquals("6.0",calc.secondOperand());
} catch (FormatException e){
fail("Unexpected format exception");
}
}
}
The same test case is used to test the command line component. There
are two significant differences from the previous test: first, the command
line component takes the input from the standard input and writes the
Table 6.4 Test case
Command
First operand
Second operand
Format
Op 3.2
0.0
3.2
Fixed point
Op 2.8
3.2
2.8
Fixed point
0.0
6.0
Fixed point
!
Op 1
6.0
1.0
Fixed point
0.0
5.0
Fixed point
0
Op 2
5.0
2.0
Fixed point
(
0.0
10.0
Fixed point
Op 111
10.0
111.0
Fixed point
0.0
0.09009009009009009
Fixed point
Rat
0.0 1.0
10.0 111.0
Rational
Float
0.0 + 10^1
9.009009009009008 + 10^02.0
Floating point
 
Search WWH ::




Custom Search