diff --git a/oysteikt-calc/pom.xml b/oysteikt-calc/pom.xml
index 010f57c..66bb246 100644
--- a/oysteikt-calc/pom.xml
+++ b/oysteikt-calc/pom.xml
@@ -1,51 +1,51 @@
- 4.0.0
- it1901
- javafx-template
- 0.0.1-SNAPSHOT
+ 4.0.0
+ it1901
+ javafx-template
+ 0.0.1-SNAPSHOT
-
- UTF-8
- 16
- 16
-
+
+ UTF-8
+ 16
+ 16
+
-
+
-
-
- org.openjfx
- javafx-controls
- 16
-
-
- org.openjfx
- javafx-fxml
- 16
-
+
+
+ org.openjfx
+ javafx-controls
+ 16
+
+
+ org.openjfx
+ javafx-fxml
+ 16
+
-
-
- org.junit.jupiter
- junit-jupiter-api
- 5.7.2
- test
-
-
- org.junit.jupiter
- junit-jupiter-engine
- 5.7.2
- test
-
-
- org.junit.jupiter
- junit-jupiter-params
- 5.7.2
- test
-
+
+
+ org.junit.jupiter
+ junit-jupiter-api
+ 5.7.2
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ 5.7.2
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-params
+ 5.7.2
+ test
+
-
+
org.testfx
testfx-core
@@ -57,42 +57,42 @@
testfx-junit5
4.0.16-alpha
test
-
-
- org.hamcrest
- hamcrest
- 2.2
- test
-
+
+
+ org.hamcrest
+ hamcrest
+ 2.2
+ test
+
-
+
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- 3.8.1
-
- 16
-
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
- 3.0.0-M5
-
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.8.1
+
+ 16
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 3.0.0-M5
+
-
- org.openjfx
- javafx-maven-plugin
- 0.0.6
-
-
-
- app.App
-
-
-
-
+
+ org.openjfx
+ javafx-maven-plugin
+ 0.0.6
+
+
+
+ app.App
+
+
+
+
diff --git a/oysteikt-calc/src/main/java/app/App.java b/oysteikt-calc/src/main/java/app/App.java
index b27d095..4d2dc02 100644
--- a/oysteikt-calc/src/main/java/app/App.java
+++ b/oysteikt-calc/src/main/java/app/App.java
@@ -13,15 +13,15 @@ import java.io.IOException;
*/
public class App extends Application {
- @Override
- public void start(Stage stage) throws IOException {
- FXMLLoader fxmlLoader = new FXMLLoader(this.getClass().getResource("App.fxml"));
- Parent parent = fxmlLoader.load();
- stage.setScene(new Scene(parent));
- stage.show();
- }
+ @Override
+ public void start(Stage stage) throws IOException {
+ FXMLLoader fxmlLoader = new FXMLLoader(this.getClass().getResource("App.fxml"));
+ Parent parent = fxmlLoader.load();
+ stage.setScene(new Scene(parent));
+ stage.show();
+ }
- public static void main(String[] args) {
- launch();
- }
+ public static void main(String[] args) {
+ launch();
+ }
}
\ No newline at end of file
diff --git a/oysteikt-calc/src/main/java/app/AppController.java b/oysteikt-calc/src/main/java/app/AppController.java
index d47da69..e72afad 100644
--- a/oysteikt-calc/src/main/java/app/AppController.java
+++ b/oysteikt-calc/src/main/java/app/AppController.java
@@ -12,122 +12,122 @@ import javafx.scene.control.ListView;
public class AppController {
- private Calc calc;
+ private Calc calc;
- public AppController() {
- calc = new Calc(0.0, 0.0, 0.0);
+ public AppController() {
+ calc = new Calc(0.0, 0.0, 0.0);
+ }
+
+ public Calc getCalc() {
+ return calc;
+ }
+
+ public void setCalc(Calc calc) {
+ this.calc = calc;
+ updateOperandsView();
+ }
+
+ @FXML
+ private ListView operandsView;
+
+ @FXML
+ private Label operandView;
+
+ @FXML
+ void initialize() {
+ updateOperandsView();
+ }
+
+ private void updateOperandsView() {
+ List operands = operandsView.getItems();
+ operands.clear();
+ int elementCount = Math.min(calc.getOperandCount(), 3);
+ for (int i = 0; i < elementCount; i++) {
+ operands.add(calc.peekOperand(elementCount - i - 1));
}
+ }
- public Calc getCalc() {
- return calc;
+ private String getOperandString() {
+ return operandView.getText();
+ }
+
+ private boolean hasOperand() {
+ return !getOperandString().isBlank();
+ }
+
+ private double getOperand() {
+ return Double.valueOf(operandView.getText());
+ }
+
+ private void setOperand(String operandString) {
+ operandView.setText(operandString);
+ }
+
+ @FXML
+ void handleEnter() {
+ if (hasOperand()) {
+ calc.pushOperand(getOperand());
+ } else {
+ calc.dup();
}
+ setOperand("");
+ updateOperandsView();
+ }
- public void setCalc(Calc calc) {
- this.calc = calc;
- updateOperandsView();
+ private void appendToOperand(String s) {
+ // TODO
+ }
+
+ @FXML
+ void handleDigit(ActionEvent ae) {
+ if (ae.getSource()instanceof Labeled l) {
+ // TODO append button label to operand
}
+ }
- @FXML
- private ListView operandsView;
-
- @FXML
- private Label operandView;
-
- @FXML
- void initialize() {
- updateOperandsView();
+ @FXML
+ void handlePoint() {
+ var operandString = getOperandString();
+ if (operandString.contains(".")) {
+ // TODO remove characters after point
+ } else {
+ // TODO append point
}
+ }
- private void updateOperandsView() {
- List operands = operandsView.getItems();
- operands.clear();
- int elementCount = Math.min(calc.getOperandCount(), 3);
- for (int i = 0; i < elementCount; i++) {
- operands.add(calc.peekOperand(elementCount - i - 1));
- }
- }
+ @FXML
+ void handleClear() {
+ // TODO clear operand
+ }
- private String getOperandString() {
- return operandView.getText();
- }
+ @FXML
+ void handleSwap() {
+ // TODO clear operand
+ }
- private boolean hasOperand() {
- return ! getOperandString().isBlank();
- }
+ private void performOperation(UnaryOperator op) {
+ // TODO
+ }
- private double getOperand() {
- return Double.valueOf(operandView.getText());
- }
-
- private void setOperand(String operandString) {
- operandView.setText(operandString);
+ private void performOperation(boolean swap, BinaryOperator op) {
+ if (hasOperand()) {
+ // TODO push operand first
}
+ // TODO perform operation, but swap first if needed
+ }
- @FXML
- void handleEnter() {
- if (hasOperand()) {
- calc.pushOperand(getOperand());
- } else {
- calc.dup();
- }
- setOperand("");
- updateOperandsView();
- }
+ @FXML
+ void handleOpAdd() {
+ // TODO
+ }
- private void appendToOperand(String s) {
- // TODO
- }
+ @FXML
+ void handleOpSub() {
+ // TODO
+ }
- @FXML
- void handleDigit(ActionEvent ae) {
- if (ae.getSource() instanceof Labeled l) {
- // TODO append button label to operand
- }
- }
-
- @FXML
- void handlePoint() {
- var operandString = getOperandString();
- if (operandString.contains(".")) {
- // TODO remove characters after point
- } else {
- // TODO append point
- }
- }
-
- @FXML
- void handleClear() {
- // TODO clear operand
- }
-
- @FXML
- void handleSwap() {
- // TODO clear operand
- }
-
- private void performOperation(UnaryOperator op) {
- // TODO
- }
-
- private void performOperation(boolean swap, BinaryOperator op) {
- if (hasOperand()) {
- // TODO push operand first
- }
- // TODO perform operation, but swap first if needed
- }
-
- @FXML
- void handleOpAdd() {
- // TODO
- }
-
- @FXML
- void handleOpSub() {
- // TODO
- }
-
- @FXML
- void handleOpMult() {
- // TODO
- }
+ @FXML
+ void handleOpMult() {
+ // TODO
+ }
}
diff --git a/oysteikt-calc/src/main/java/app/Calc.java b/oysteikt-calc/src/main/java/app/Calc.java
index 6c740f4..f769f6f 100644
--- a/oysteikt-calc/src/main/java/app/Calc.java
+++ b/oysteikt-calc/src/main/java/app/Calc.java
@@ -6,111 +6,112 @@ import java.util.function.BinaryOperator;
import java.util.function.UnaryOperator;
public class Calc {
-
- private final List operandStack;
- public Calc(double... operands) {
- operandStack = new ArrayList<>(operands.length + 2);
- for (var d : operands) {
- operandStack.add(d);
- }
- }
+ private final List operandStack;
- /**
- * @return the number of operands on the stack
- */
- public int getOperandCount() {
- return operandStack.size();
+ public Calc(double... operands) {
+ operandStack = new ArrayList<>(operands.length + 2);
+ for (var d : operands) {
+ operandStack.add(d);
}
+ }
- /**
- * Pushes a new operand onto top of the stack.
- *
- * @param d the new operand
- */
- public void pushOperand(double d) {
- operandStack.add(d);
- }
+ /**
+ * @return the number of operands on the stack
+ */
+ public int getOperandCount() {
+ return operandStack.size();
+ }
- /**
- * @param n the place (from the top) to peek
- * @return the n'th operand from the top
- * @throws IllegalArgumentException if n is larger than the operand count
- */
- public double peekOperand(int n) {
- if (n >= getOperandCount()) {
- throw new IllegalArgumentException("Cannot peek at position " + n + " when the operand count is " + getOperandCount());
- }
- return operandStack.get(getOperandCount() - n - 1);
- }
+ /**
+ * Pushes a new operand onto top of the stack.
+ *
+ * @param d the new operand
+ */
+ public void pushOperand(double d) {
+ operandStack.add(d);
+ }
- /**
- * @return the top operand
- */
- public double peekOperand() {
- return peekOperand(0);
+ /**
+ * @param n the place (from the top) to peek
+ * @return the n'th operand from the top
+ * @throws IllegalArgumentException if n is larger than the operand count
+ */
+ public double peekOperand(int n) {
+ if (n >= getOperandCount()) {
+ throw new IllegalArgumentException(
+ "Cannot peek at position " + n + " when the operand count is " + getOperandCount());
}
+ return operandStack.get(getOperandCount() - n - 1);
+ }
- /**
- * Removes and returns the top operand.
- *
- * @return the top operand
- * @throws IllegalStateException if the stack is empty
- */
- public double popOperand() {
- if (getOperandCount() == 0) {
- throw new IllegalStateException("Cannot pop from an empty stack");
- }
- return operandStack.remove(operandStack.size() - 1);
- }
-
- /**
- * Performs the provided operation in the top operand, and
- * replaces it with the result.
- *
- * @param op the operation to perform
- * @return the result of performing the operation
- * @throws IllegalStateException if the operand stack is empty
- */
- public double performOperation(UnaryOperator op) throws IllegalStateException {
- // TODO
- return 0.0;
- }
+ /**
+ * @return the top operand
+ */
+ public double peekOperand() {
+ return peekOperand(0);
+ }
- /**
- * Performs the provided operation in the two topmost operands, and
- * replaces them with the result.
- *
- * @param op the operation to perform
- * @return the result of performing the operation
- * @throws IllegalStateException if the operand count is less than two
- */
- public double performOperation(BinaryOperator op) throws IllegalStateException {
- if (getOperandCount() < 2) {
- throw new IllegalStateException("Too few operands (" + getOperandCount() + ") on the stack");
- }
- var op2 = popOperand();
- var op1 = popOperand();
- var result = op.apply(op1, op2);
- pushOperand(result);
- return result;
+ /**
+ * Removes and returns the top operand.
+ *
+ * @return the top operand
+ * @throws IllegalStateException if the stack is empty
+ */
+ public double popOperand() {
+ if (getOperandCount() == 0) {
+ throw new IllegalStateException("Cannot pop from an empty stack");
}
+ return operandStack.remove(operandStack.size() - 1);
+ }
- /**
- * Swaps the two topmost operands.
- *
- * @throws IllegalStateException if the operand count is less than two
- */
- public void swap() {
-
- }
+ /**
+ * Performs the provided operation in the top operand, and replaces it with the
+ * result.
+ *
+ * @param op the operation to perform
+ * @return the result of performing the operation
+ * @throws IllegalStateException if the operand stack is empty
+ */
+ public double performOperation(UnaryOperator op) throws IllegalStateException {
+ // TODO
+ return 0.0;
+ }
- /**
- * Duplicates the top operand.
- *
- * @throws IllegalStateException if the operand stack is empty
- */
- public void dup() {
- // TODO
+ /**
+ * Performs the provided operation in the two topmost operands, and replaces
+ * them with the result.
+ *
+ * @param op the operation to perform
+ * @return the result of performing the operation
+ * @throws IllegalStateException if the operand count is less than two
+ */
+ public double performOperation(BinaryOperator op) throws IllegalStateException {
+ if (getOperandCount() < 2) {
+ throw new IllegalStateException("Too few operands (" + getOperandCount() + ") on the stack");
}
+ var op2 = popOperand();
+ var op1 = popOperand();
+ var result = op.apply(op1, op2);
+ pushOperand(result);
+ return result;
+ }
+
+ /**
+ * Swaps the two topmost operands.
+ *
+ * @throws IllegalStateException if the operand count is less than two
+ */
+ public void swap() {
+
+ }
+
+ /**
+ * Duplicates the top operand.
+ *
+ * @throws IllegalStateException if the operand stack is empty
+ */
+ public void dup() {
+ // TODO
+ }
}
\ No newline at end of file
diff --git a/oysteikt-calc/src/main/resources/app/App.fxml b/oysteikt-calc/src/main/resources/app/App.fxml
index 7356474..5e9e25f 100644
--- a/oysteikt-calc/src/main/resources/app/App.fxml
+++ b/oysteikt-calc/src/main/resources/app/App.fxml
@@ -6,59 +6,59 @@
+ alignment="CENTER" hgap="10.0" vgap="10.0" >
-
-
+
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
-
-
-
-
+
+
+
+
diff --git a/oysteikt-calc/src/test/java/app/AppTest.java b/oysteikt-calc/src/test/java/app/AppTest.java
index 209ebfc..96bfde2 100644
--- a/oysteikt-calc/src/test/java/app/AppTest.java
+++ b/oysteikt-calc/src/test/java/app/AppTest.java
@@ -24,107 +24,97 @@ import org.testfx.matcher.control.LabeledMatchers;
*/
public class AppTest extends ApplicationTest {
- private AppController controller;
- private Parent root;
+ private AppController controller;
+ private Parent root;
- @Override
- public void start(Stage stage) throws IOException {
- FXMLLoader fxmlLoader = new FXMLLoader(this.getClass().getResource("App.fxml"));
- root = fxmlLoader.load();
- controller = fxmlLoader.getController();
- stage.setScene(new Scene(root));
- stage.show();
+ @Override
+ public void start(Stage stage) throws IOException {
+ FXMLLoader fxmlLoader = new FXMLLoader(this.getClass().getResource("App.fxml"));
+ root = fxmlLoader.load();
+ controller = fxmlLoader.getController();
+ stage.setScene(new Scene(root));
+ stage.show();
+ }
+
+ public Parent getRootNode() {
+ return root;
+ }
+
+ private String enterLabel = """
+ E
+ n
+ t
+ e
+ r
+ """.stripTrailing();
+
+ private void click(String... labels) {
+ for (var label : labels) {
+ clickOn(LabeledMatchers.hasText(label));
}
+ }
- public Parent getRootNode() {
- return root;
+ private String getOperandString() {
+ return ((Label) getRootNode().lookup("#operandView")).getText();
+ }
+
+ private ListView getOperandsView() {
+ return (ListView) getRootNode().lookup("#operandsView");
+ }
+
+ private void checkView(double... operands) {
+ for (int i = 0; i < operands.length; i++) {
+ Assertions.assertEquals(operands[i], controller.getCalc().peekOperand(i),
+ "Wrong value at #" + i + " of operand stack");
}
-
- private String enterLabel = """
- E
- n
- t
- e
- r
- """.stripTrailing();
-
- private void click(String... labels) {
- for (var label : labels) {
- clickOn(LabeledMatchers.hasText(label));
- }
+ List viewItems = getOperandsView().getItems();
+ 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");
}
+ }
- private String getOperandString() {
- return ((Label) getRootNode().lookup("#operandView")).getText();
- }
+ private void checkView(String operandString, double... operands) {
+ Assertions.assertEquals(operandString, getOperandString());
+ checkView(operands);
+ }
- private ListView getOperandsView() {
- return (ListView) getRootNode().lookup("#operandsView");
- }
+ // see https://www.baeldung.com/parameterized-tests-junit-5
+ // about @ParameterizedTest
- private void checkView(double... operands) {
- for (int i = 0; i < operands.length; i++) {
- Assertions.assertEquals(operands[i], controller.getCalc().peekOperand(i), "Wrong value at #" + i + " of operand stack");
- }
- List viewItems = getOperandsView().getItems();
- 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");
- }
+ @ParameterizedTest
+ @MethodSource
+ public void testClicksOperand(String labels, String operandString) {
+ for (var label : labels.split(" ")) {
+ click(label);
}
+ checkView(operandString);
+ }
- private void checkView(String operandString, double... operands) {
- Assertions.assertEquals(operandString, getOperandString());
- checkView(operands);
- }
+ private static Stream testClicksOperand() {
+ return Stream.of(Arguments.of("2 7", "27"), Arguments.of("2 7 .", "27."), Arguments.of("2 7 . 5", "27.5"),
+ Arguments.of("2 7 . 5 .", "27."));
+ }
- // see https://www.baeldung.com/parameterized-tests-junit-5
- // about @ParameterizedTest
+ @ParameterizedTest
+ @MethodSource
+ public void testClicksOperands(String labels, String operandsString) {
+ for (var label : labels.split(" ")) {
+ click(label.equals("\n") ? enterLabel : label);
+ }
+ checkView("", Stream.of(operandsString.split(" ")).mapToDouble(Double::valueOf).toArray());
+ }
- @ParameterizedTest
- @MethodSource
- public void testClicksOperand(String labels, String operandString) {
- for (var label : labels.split(" ")) {
- click(label);
- }
- checkView(operandString);
- }
+ private static Stream testClicksOperands() {
+ return Stream.of(Arguments.of("2 7 . 5 \n", "27.5"), Arguments.of("2 7 \n", "27.0"),
+ 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 . 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"));
+ }
- private static Stream testClicksOperand() {
- return Stream.of(
- Arguments.of("2 7", "27"),
- Arguments.of("2 7 .", "27."),
- Arguments.of("2 7 . 5", "27.5"),
- Arguments.of("2 7 . 5 .", "27.")
- );
- }
-
- @ParameterizedTest
- @MethodSource
- public void testClicksOperands(String labels, String operandsString) {
- for (var label : labels.split(" ")) {
- click(label.equals("\n") ? enterLabel : label);
- }
- checkView("", Stream.of(operandsString.split(" ")).mapToDouble(Double::valueOf).toArray());
- }
-
- private static Stream testClicksOperands() {
- return Stream.of(
- Arguments.of("2 7 . 5 \n", "27.5"),
- Arguments.of("2 7 \n", "27.0"),
- 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 . 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
- public void testPi() {
- click("π");
- checkView("", Math.PI);
- }
+ @Test
+ public void testPi() {
+ click("π");
+ checkView("", Math.PI);
+ }
}
diff --git a/oysteikt-calc/src/test/java/app/CalcTest.java b/oysteikt-calc/src/test/java/app/CalcTest.java
index 150778d..d6a9443 100644
--- a/oysteikt-calc/src/test/java/app/CalcTest.java
+++ b/oysteikt-calc/src/test/java/app/CalcTest.java
@@ -5,111 +5,110 @@ import org.junit.jupiter.api.Test;
public class CalcTest {
- private static void checkCalc(Calc calc, double... operands) {
- Assertions.assertEquals(operands.length, calc.getOperandCount(), "Wrong operand count");
- for (int i = 0; i < operands.length; i++) {
- Assertions.assertEquals(operands[i], calc.peekOperand(i), "Wrong value at #" + i + " of operand stack");
- }
+ private static void checkCalc(Calc calc, double... operands) {
+ Assertions.assertEquals(operands.length, calc.getOperandCount(), "Wrong operand count");
+ for (int i = 0; i < operands.length; i++) {
+ Assertions.assertEquals(operands[i], calc.peekOperand(i), "Wrong value at #" + i + " of operand stack");
}
+ }
- @Test
- public void testCalc() {
- checkCalc(new Calc());
- checkCalc(new Calc(1.0), 1.0);
- checkCalc(new Calc(3.14, 1.0), 1.0, 3.14);
- }
+ @Test
+ public void testCalc() {
+ checkCalc(new Calc());
+ checkCalc(new Calc(1.0), 1.0);
+ checkCalc(new Calc(3.14, 1.0), 1.0, 3.14);
+ }
- @Test
- public void testPushOperand() {
- Calc calc = new Calc();
- calc.pushOperand(1.0);
- checkCalc(calc, 1.0);
- calc.pushOperand(3.14);
- checkCalc(calc, 3.14, 1.0);
- }
+ @Test
+ public void testPushOperand() {
+ Calc calc = new Calc();
+ calc.pushOperand(1.0);
+ checkCalc(calc, 1.0);
+ calc.pushOperand(3.14);
+ checkCalc(calc, 3.14, 1.0);
+ }
- @Test
- public void testPeekOperand() {
- Calc calc = new Calc(1.0, 3.14);
- Assertions.assertEquals(3.14, calc.peekOperand());
- Assertions.assertThrows(IllegalArgumentException.class, () -> new Calc().peekOperand());
- }
+ @Test
+ public void testPeekOperand() {
+ Calc calc = new Calc(1.0, 3.14);
+ Assertions.assertEquals(3.14, calc.peekOperand());
+ Assertions.assertThrows(IllegalArgumentException.class, () -> new Calc().peekOperand());
+ }
- @Test
- public void testPeekOperandN() {
- Calc calc = new Calc(1.0, 3.14);
- Assertions.assertEquals(3.14, calc.peekOperand(0));
- Assertions.assertEquals(1.0, calc.peekOperand(1));
- Assertions.assertThrows(IllegalArgumentException.class, () -> calc.peekOperand(2));
- }
+ @Test
+ public void testPeekOperandN() {
+ Calc calc = new Calc(1.0, 3.14);
+ Assertions.assertEquals(3.14, calc.peekOperand(0));
+ Assertions.assertEquals(1.0, calc.peekOperand(1));
+ Assertions.assertThrows(IllegalArgumentException.class, () -> calc.peekOperand(2));
+ }
- @Test
- public void testPopOperand() {
- Calc calc = new Calc(1.0, 3.14);
- Assertions.assertEquals(3.14, calc.popOperand());
- checkCalc(calc, 1.0);
- Assertions.assertEquals(1.0, calc.popOperand());
- checkCalc(calc);
- }
+ @Test
+ public void testPopOperand() {
+ Calc calc = new Calc(1.0, 3.14);
+ Assertions.assertEquals(3.14, calc.popOperand());
+ checkCalc(calc, 1.0);
+ Assertions.assertEquals(1.0, calc.popOperand());
+ checkCalc(calc);
+ }
- @Test
- public void testPopOperand_emptyStack() {
- Assertions.assertThrows(IllegalStateException.class, () -> new Calc().popOperand());
- }
+ @Test
+ public void testPopOperand_emptyStack() {
+ Assertions.assertThrows(IllegalStateException.class, () -> new Calc().popOperand());
+ }
- @Test
- public void testPerformOperation1() {
- Calc calc = new Calc(1.0);
- Assertions.assertEquals(-1.0, calc.performOperation(n -> -n));
- checkCalc(calc, -1.0);
- }
+ @Test
+ public void testPerformOperation1() {
+ Calc calc = new Calc(1.0);
+ Assertions.assertEquals(-1.0, calc.performOperation(n -> -n));
+ checkCalc(calc, -1.0);
+ }
- @Test
- public void testPerformOperation1_emptyOperandStack() {
- Assertions.assertThrows(IllegalStateException.class, () -> new Calc().performOperation(n -> -n));
- }
+ @Test
+ public void testPerformOperation1_emptyOperandStack() {
+ Assertions.assertThrows(IllegalStateException.class, () -> new Calc().performOperation(n -> -n));
+ }
+ @Test
+ public void testPerformOperation2() {
+ Calc calc = new Calc(1.0, 3.0);
+ Assertions.assertEquals(-2.0, calc.performOperation((n1, n2) -> n1 - n2));
+ checkCalc(calc, -2.0);
+ }
- @Test
- public void testPerformOperation2() {
- Calc calc = new Calc(1.0, 3.0);
- Assertions.assertEquals(-2.0, calc.performOperation((n1, n2) -> n1 - n2));
- checkCalc(calc, -2.0);
- }
+ @Test
+ public void testPerformOperation2_lessThanTwoOperands() {
+ Assertions.assertThrows(IllegalStateException.class, () -> new Calc(1.0).performOperation((n1, n2) -> n1 - n2));
+ Assertions.assertThrows(IllegalStateException.class, () -> new Calc().performOperation((n1, n2) -> n1 - n2));
+ }
- @Test
- public void testPerformOperation2_lessThanTwoOperands() {
- Assertions.assertThrows(IllegalStateException.class, () -> new Calc(1.0).performOperation((n1, n2) -> n1 - n2));
- Assertions.assertThrows(IllegalStateException.class, () -> new Calc().performOperation((n1, n2) -> n1 - n2));
- }
+ @Test
+ public void testSwap() {
+ Calc calc = new Calc(1.0, 3.14);
+ checkCalc(calc, 3.14, 1.0);
+ calc.swap();
+ checkCalc(calc, 1.0, 3.14);
+ calc.swap();
+ checkCalc(calc, 3.14, 1.0);
+ }
- @Test
- public void testSwap() {
- Calc calc = new Calc(1.0, 3.14);
- checkCalc(calc, 3.14, 1.0);
- calc.swap();
- checkCalc(calc, 1.0, 3.14);
- calc.swap();
- checkCalc(calc, 3.14, 1.0);
- }
+ @Test
+ public void testSwap_lessThanTwoOperands() {
+ Assertions.assertThrows(IllegalStateException.class, () -> new Calc(1.0).swap());
+ Assertions.assertThrows(IllegalStateException.class, () -> new Calc().swap());
+ }
- @Test
- public void testSwap_lessThanTwoOperands() {
- Assertions.assertThrows(IllegalStateException.class, () -> new Calc(1.0).swap());
- Assertions.assertThrows(IllegalStateException.class, () -> new Calc().swap());
- }
+ @Test
+ public void testDup() {
+ Calc calc = new Calc(1.0, 3.14);
+ Assertions.assertEquals(3.14, calc.popOperand());
+ checkCalc(calc, 1.0);
+ Assertions.assertEquals(1.0, calc.popOperand());
+ checkCalc(calc);
+ }
- @Test
- public void testDup() {
- Calc calc = new Calc(1.0, 3.14);
- Assertions.assertEquals(3.14, calc.popOperand());
- checkCalc(calc, 1.0);
- Assertions.assertEquals(1.0, calc.popOperand());
- checkCalc(calc);
- }
-
- @Test
- public void testDup_emptyOperandStack() {
- Assertions.assertThrows(IllegalStateException.class, () -> new Calc().dup());
- }
+ @Test
+ public void testDup_emptyOperandStack() {
+ Assertions.assertThrows(IllegalStateException.class, () -> new Calc().dup());
+ }
}