Fikset feil i kode og test
This commit is contained in:
@@ -37,7 +37,7 @@ public class Calc {
|
||||
* @throws IllegalArgumentException if n is larger than the operand count
|
||||
*/
|
||||
public double peekOperand(int n) {
|
||||
if (n > getOperandCount()) {
|
||||
if (n >= getOperandCount()) {
|
||||
throw new IllegalArgumentException("Cannot peek at position " + n + " when the operand count is " + getOperandCount());
|
||||
}
|
||||
return operandStack.get(getOperandCount() - n - 1);
|
||||
|
||||
@@ -86,10 +86,11 @@ public class CalcTest {
|
||||
@Test
|
||||
public void testSwap() {
|
||||
Calc calc = new Calc(1.0, 3.14);
|
||||
calc.swap();
|
||||
checkCalc(calc, 3.14, 1.0);
|
||||
calc.swap();
|
||||
checkCalc(calc, 1.0, 3.14);
|
||||
calc.swap();
|
||||
checkCalc(calc, 3.14, 1.0);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user