Fikset feil i kode og test

This commit is contained in:
Hallvard Trætteberg
2021-08-27 09:29:07 +00:00
parent 84bd1ee37f
commit 6de15986b3
11 changed files with 25 additions and 154 deletions

View File

@@ -38,7 +38,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);
@@ -102,7 +102,7 @@ public class Calc {
* @throws IllegalStateException if the operand count is less than two
*/
public void swap() {
// TODO
}
/**

View File

@@ -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