Some fixes, create initial test class
This commit is contained in:
parent
324dc23cf7
commit
b4c45dabce
|
@ -13,8 +13,6 @@ import java.io.IOException;
|
||||||
*/
|
*/
|
||||||
public class App extends Application {
|
public class App extends Application {
|
||||||
|
|
||||||
private static Scene scene;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage stage) throws IOException {
|
public void start(Stage stage) throws IOException {
|
||||||
FXMLLoader fxmlLoader = new FXMLLoader(this.getClass().getResource("App.fxml"));
|
FXMLLoader fxmlLoader = new FXMLLoader(this.getClass().getResource("App.fxml"));
|
||||||
|
|
|
@ -2,6 +2,8 @@ package app;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.BinaryOperator;
|
import java.util.function.BinaryOperator;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.UnaryOperator;
|
||||||
|
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
|
@ -91,27 +93,37 @@ public class AppController {
|
||||||
void handlePoint() {
|
void handlePoint() {
|
||||||
var operandString = getOperandString();
|
var operandString = getOperandString();
|
||||||
if (operandString.contains(".")) {
|
if (operandString.contains(".")) {
|
||||||
setOperand(operandString.substring(operandString.indexOf(".") + 1));
|
setOperand(operandString.substring(0, operandString.indexOf(".") + 1));
|
||||||
} else {
|
} else {
|
||||||
appendToOperand(".");
|
appendToOperand(".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void performOperation(boolean swap, BinaryOperator<Double> op) {
|
@FXML
|
||||||
|
void handleClear() {
|
||||||
|
clearOperand();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void withOperand(Runnable proc) {
|
||||||
if (hasOperand()) {
|
if (hasOperand()) {
|
||||||
calc.pushOperand(getOperand());
|
calc.pushOperand(getOperand());
|
||||||
clearOperand();
|
clearOperand();
|
||||||
}
|
}
|
||||||
if (swap) {
|
proc.run();
|
||||||
calc.swap();
|
|
||||||
}
|
|
||||||
calc.performOperation(op);
|
|
||||||
updateOperandsView();
|
updateOperandsView();
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
private void performOperation(UnaryOperator<Double> op) {
|
||||||
void handlePi() {
|
withOperand(() -> calc.performOperation(op));
|
||||||
setOperand(Math.PI);
|
}
|
||||||
|
|
||||||
|
private void performOperation(boolean swap, BinaryOperator<Double> op) {
|
||||||
|
withOperand(() -> {
|
||||||
|
if (swap) {
|
||||||
|
calc.swap();
|
||||||
|
}
|
||||||
|
calc.performOperation(op);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
|
@ -133,4 +145,18 @@ public class AppController {
|
||||||
void handleOpDiv() {
|
void handleOpDiv() {
|
||||||
performOperation(true, (op1, op2) -> op1 / op2);
|
performOperation(true, (op1, op2) -> op1 / op2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
void handleOpSquareRoot() {
|
||||||
|
performOperation(op1 -> Math.sqrt(op1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
void handlePi() {
|
||||||
|
withOperand(() -> calc.pushOperand(Math.PI));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println("\u221A");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
GridPane.rowIndex="5" GridPane.columnIndex="0"/>
|
GridPane.rowIndex="5" GridPane.columnIndex="0"/>
|
||||||
<Button text="." onAction="#handlePoint"
|
<Button text="." onAction="#handlePoint"
|
||||||
GridPane.rowIndex="5" GridPane.columnIndex="1"/>
|
GridPane.rowIndex="5" GridPane.columnIndex="1"/>
|
||||||
<Button text="π" onAction="#handlePi"
|
<Button text="C" onAction="#handleClear"
|
||||||
GridPane.rowIndex="5" GridPane.columnIndex="2"/>
|
GridPane.rowIndex="5" GridPane.columnIndex="2"/>
|
||||||
|
|
||||||
<Button text="+" onAction="#handleOpAdd"
|
<Button text="+" onAction="#handleOpAdd"
|
||||||
|
@ -49,4 +49,8 @@
|
||||||
GridPane.rowIndex="6" GridPane.columnIndex="2"/>
|
GridPane.rowIndex="6" GridPane.columnIndex="2"/>
|
||||||
<Button text="/" onAction="#handleOpDiv"
|
<Button text="/" onAction="#handleOpDiv"
|
||||||
GridPane.rowIndex="6" GridPane.columnIndex="3"/>
|
GridPane.rowIndex="6" GridPane.columnIndex="3"/>
|
||||||
|
<Button text="√" onAction="#handleOpSquareRoot"
|
||||||
|
GridPane.rowIndex="7" GridPane.columnIndex="0"/>
|
||||||
|
<Button text="π" onAction="#handlePi"
|
||||||
|
GridPane.rowIndex="7" GridPane.columnIndex="1"/>
|
||||||
</GridPane>
|
</GridPane>
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package app;
|
||||||
|
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.scene.Parent;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.testfx.framework.junit5.ApplicationTest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TestFX App test
|
||||||
|
*/
|
||||||
|
public class AppTest extends ApplicationTest {
|
||||||
|
|
||||||
|
@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();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue