Reformat files to use 2 space indentation
This commit is contained in:
parent
82169b0a2e
commit
736b3c4da0
|
@ -39,7 +39,8 @@ public class Calc {
|
||||||
*/
|
*/
|
||||||
public double peekOperand(int n) {
|
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());
|
throw new IllegalArgumentException(
|
||||||
|
"Cannot peek at position " + n + " when the operand count is " + getOperandCount());
|
||||||
}
|
}
|
||||||
return operandStack.get(getOperandCount() - n - 1);
|
return operandStack.get(getOperandCount() - n - 1);
|
||||||
}
|
}
|
||||||
|
@ -65,8 +66,8 @@ public class Calc {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs the provided operation in the top operand, and
|
* Performs the provided operation in the top operand, and replaces it with the
|
||||||
* replaces it with the result.
|
* result.
|
||||||
*
|
*
|
||||||
* @param op the operation to perform
|
* @param op the operation to perform
|
||||||
* @return the result of performing the operation
|
* @return the result of performing the operation
|
||||||
|
@ -78,8 +79,8 @@ public class Calc {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs the provided operation in the two topmost operands, and
|
* Performs the provided operation in the two topmost operands, and replaces
|
||||||
* replaces them with the result.
|
* them with the result.
|
||||||
*
|
*
|
||||||
* @param op the operation to perform
|
* @param op the operation to perform
|
||||||
* @return the result of performing the operation
|
* @return the result of performing the operation
|
||||||
|
|
|
@ -64,11 +64,13 @@ public class AppTest extends ApplicationTest {
|
||||||
|
|
||||||
private void checkView(double... operands) {
|
private void checkView(double... operands) {
|
||||||
for (int i = 0; i < operands.length; i++) {
|
for (int i = 0; i < operands.length; i++) {
|
||||||
Assertions.assertEquals(operands[i], controller.getCalc().peekOperand(i), "Wrong value at #" + i + " of operand stack");
|
Assertions.assertEquals(operands[i], controller.getCalc().peekOperand(i),
|
||||||
|
"Wrong value at #" + i + " of operand stack");
|
||||||
}
|
}
|
||||||
List<Double> viewItems = getOperandsView().getItems();
|
List<Double> viewItems = getOperandsView().getItems();
|
||||||
for (int i = 0; i < operands.length; i++) {
|
for (int i = 0; i < operands.length; i++) {
|
||||||
Assertions.assertEquals(operands[i], viewItems.get(viewItems.size() - i - 1), "Wrong value at #" + i + " of operands view");
|
Assertions.assertEquals(operands[i], viewItems.get(viewItems.size() - i - 1),
|
||||||
|
"Wrong value at #" + i + " of operands view");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,12 +92,8 @@ public class AppTest extends ApplicationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Stream<Arguments> testClicksOperand() {
|
private static Stream<Arguments> testClicksOperand() {
|
||||||
return Stream.of(
|
return Stream.of(Arguments.of("2 7", "27"), Arguments.of("2 7 .", "27."), Arguments.of("2 7 . 5", "27.5"),
|
||||||
Arguments.of("2 7", "27"),
|
Arguments.of("2 7 . 5 .", "27."));
|
||||||
Arguments.of("2 7 .", "27."),
|
|
||||||
Arguments.of("2 7 . 5", "27.5"),
|
|
||||||
Arguments.of("2 7 . 5 .", "27.")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -108,18 +106,10 @@ public class AppTest extends ApplicationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Stream<Arguments> testClicksOperands() {
|
private static Stream<Arguments> testClicksOperands() {
|
||||||
return Stream.of(
|
return Stream.of(Arguments.of("2 7 . 5 \n", "27.5"), Arguments.of("2 7 \n", "27.0"),
|
||||||
Arguments.of("2 7 . 5 \n", "27.5"),
|
Arguments.of("2 \n 7 \n 5 \n", "5.0", "7.0", "2.0"), Arguments.of("2 7 . \n", "27.0"),
|
||||||
Arguments.of("2 7 \n", "27.0"),
|
Arguments.of("2 7 . 5 \n", "27.5"), Arguments.of("2 \n 7 +", "9.0"), Arguments.of("2 \n 7 -", "-5.0"),
|
||||||
Arguments.of("2 \n 7 \n 5 \n", "5.0", "7.0", "2.0"),
|
Arguments.of("2 \n 7 *", "14.0"), Arguments.of("6 \n 3 /", "2.0"), Arguments.of("2 5 \n √", "5.0"));
|
||||||
Arguments.of("2 7 . \n", "27.0"),
|
|
||||||
Arguments.of("2 7 . 5 \n", "27.5"),
|
|
||||||
Arguments.of("2 \n 7 +", "9.0"),
|
|
||||||
Arguments.of("2 \n 7 -", "-5.0"),
|
|
||||||
Arguments.of("2 \n 7 *", "14.0"),
|
|
||||||
Arguments.of("6 \n 3 /", "2.0"),
|
|
||||||
Arguments.of("2 5 \n √", "5.0")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -69,7 +69,6 @@ public class CalcTest {
|
||||||
Assertions.assertThrows(IllegalStateException.class, () -> new Calc().performOperation(n -> -n));
|
Assertions.assertThrows(IllegalStateException.class, () -> new Calc().performOperation(n -> -n));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPerformOperation2() {
|
public void testPerformOperation2() {
|
||||||
Calc calc = new Calc(1.0, 3.0);
|
Calc calc = new Calc(1.0, 3.0);
|
||||||
|
|
Loading…
Reference in New Issue