Java Reference
In-Depth Information
// restore original standard input and output
System.setOut(oldOut);
System.setIn(oldIn);
// copy the output into a string
String output # buffer.toString();
String[] expected # { "0.0","3.2","3.2",
"2.8","0.0","6.0" };
// verify the output contains the expected strings
assertContainsInOrder(output,expected);
}
protected void assertContainsInOrder(String output,
String[] strings){
int lastIndex # -1;
int currentIndex # -1;
for ( int i # 0; i < strings.length; i !! ) {
currentIndex # output.indexOf(strings[i],lastIndex ! 1);
assertTrue("Couldn't find [" ! i ! "]:" ! strings[i],
currentIndex>-1);
lastIndex # currentIndex;
}
}
}
6.5
Prototype 2: Number bases
The focus of this prototype is on the introduction of different number bases
to the calculator.
6.5.1
Analysis
The main feature that is added in this development iteration is the capabil-
ity of handling different number bases. Analogous with what we've done with
the representation formats, we can represent the concepts involved in this
issue as a set of related classes. The result of this analysis is presented in
Figure 6.7 as a class diagram.
We start from the generic concept of number base; it involves the capa-
bility of parsing operands in a given base and printing the result in a given
base. This abstract concept can be separated into three concrete number
bases: decimal, binary and hexadecimal. Each number base is characterized
by the base in the proper sense (e.g. 2 for the binary base) and by the set of
digits that can be used (e.g. 0 and 1 for the binary base).
The command line must therefore accommodate new commands: to
manage number bases and to read commands from a file. The new commands
are described in Table 6.5.
 
Search WWH ::




Custom Search