diff options
| -rw-r--r-- | src/de/fhswf/in/inf/upnfx/view/MainView.fxml | 8 | ||||
| -rw-r--r-- | test/gui/CalculatorTest.java | 218 |
2 files changed, 222 insertions, 4 deletions
diff --git a/src/de/fhswf/in/inf/upnfx/view/MainView.fxml b/src/de/fhswf/in/inf/upnfx/view/MainView.fxml index a1b5add..8f5f990 100644 --- a/src/de/fhswf/in/inf/upnfx/view/MainView.fxml +++ b/src/de/fhswf/in/inf/upnfx/view/MainView.fxml @@ -14,12 +14,12 @@ <Button id="SIN" fx:id="btnSin" disable="true" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleOpSin" text="SIN" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="1" /> <Button id="COS" fx:id="btnCos" disable="true" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleOpCos" text="COS" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="1" /> <Button id="TAN" fx:id="btnTan" disable="true" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleOpTan" text="TAN" GridPane.columnIndex="3" GridPane.halignment="CENTER" GridPane.rowIndex="1" /> - <Button id="+/-" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleInvert" text="+/-" GridPane.halignment="CENTER" GridPane.rowIndex="2" /> - <Button id="1/X" fx:id="btn1DivX" disable="true" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handle1DivX" text="1/X" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="2" /> - <Button id="Y^X" fx:id="btnPow" disable="true" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleOpPow" text="Y^X" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="2" /> + <Button id="+-" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleInvert" text="+/-" GridPane.halignment="CENTER" GridPane.rowIndex="2" /> + <Button id="1divX" fx:id="btn1DivX" disable="true" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handle1DivX" text="1/X" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="2" /> + <Button id="YhochX" fx:id="btnPow" disable="true" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleOpPow" text="Y^X" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="2" /> <Button id="SQR" fx:id="btnSqr" disable="true" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleOpSqr" text="SQR" GridPane.columnIndex="3" GridPane.halignment="CENTER" GridPane.rowIndex="2" /> <Button id="LstX" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleLstX" text="LstX" GridPane.halignment="CENTER" GridPane.rowIndex="3" /> - <Button id="X<>Y" fx:id="btnXY" disable="true" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleXY" text="X<>Y" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="3" /> + <Button id="SwapXY" fx:id="btnXY" disable="true" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleXY" text="X<>Y" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="3" /> <Button id="CLR" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleClr" text="CLR" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="3" /> <Button id="CLX" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleClx" text="CLX" GridPane.columnIndex="3" GridPane.halignment="CENTER" GridPane.rowIndex="3" /> <Button id="7" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleNumber7" text="7" GridPane.halignment="CENTER" GridPane.rowIndex="4" /> diff --git a/test/gui/CalculatorTest.java b/test/gui/CalculatorTest.java index 98c6516..5946bd4 100644 --- a/test/gui/CalculatorTest.java +++ b/test/gui/CalculatorTest.java @@ -83,6 +83,224 @@ public class CalculatorTest extends GuiTest } @Test + public void testClr() + { + Button button = find("#1"); + click(button); + button = find("#2"); + click(button); + button = find("#3"); + click(button); + button = find("#ENT"); + click(button); + verifyThat("#display", hasText("123.0")); + button = find("#4"); + click(button); + button = find("#5"); + click(button); + button = find("#6"); + click(button); + verifyThat("#display", hasText("456")); + button = find("#CLR"); + click(button); + verifyThat("#display", hasText("")); + } + + @Test + public void testSwapXY() + { + Button button = find("#1"); + click(button); + button = find("#2"); + click(button); + button = find("#3"); + click(button); + button = find("#ENT"); + click(button); + verifyThat("#display", hasText("123.0")); + button = find("#4"); + click(button); + button = find("#5"); + click(button); + button = find("#6"); + click(button); + verifyThat("#display", hasText("456")); + button = find("#SwapXY"); + click(button); + verifyThat("#display", hasText("123.0")); + click(button); + verifyThat("#display", hasText("456.0")); + } + + @Test + public void testLstX() + { + Button button = find("#1"); + click(button); + button = find("#0"); + click(button); + click(button); + button = find("#ENT"); + click(button); + verifyThat("#display", hasText("100.0")); + button = find("#2"); + click(button); + button = find("#0"); + click(button); + click(button); + verifyThat("#display", hasText("200")); + button = find("#+"); + click(button); + verifyThat("#display", hasText("300.0")); + button = find("#LstX"); + click(button); + verifyThat("#display", hasText("200.0")); + button = find("#+"); + click(button); + verifyThat("#display", hasText("500.0")); + } + + @Test + public void testSqr() + { + Button button = find("#9"); + click(button); + button = find("#SQR"); + click(button); + verifyThat("#display", hasText("3.0")); + } + + @Test + public void testYhochX() + { + Button button = find("#2"); + click(button); + button = find("#ENT"); + click(button); + verifyThat("#display", hasText("2.0")); + button = find("#3"); + click(button); + verifyThat("#display", hasText("3")); + button = find("#YhochX"); + click(button); + verifyThat("#display", hasText("8.0")); + click(button); + verifyThat("#display", hasText("8.0")); + } + + @Test + public void test1div0() + { + Button button = find("#0"); + click(button); + button = find("#ENT"); + click(button); + verifyThat("#display", hasText("0.0")); + button = find("#1divX"); + click(button); + verifyThat("#display", hasText("")); + } + + @Test + public void test1divX() + { + Button button = find("#2"); + click(button); + verifyThat("#display", hasText("2")); + button = find("#1divX"); + click(button); + verifyThat("#display", hasText("0.5")); + } + + @Test + public void testInverseNoEnt() + { + Button button = find("#2"); + click(button); + verifyThat("#display", hasText("2")); + button = find("#+-"); + click(button); + verifyThat("#display", hasText("-2")); + } + + @Test + public void testInverseWithEnt() + { + Button button = find("#2"); + click(button); + button = find("#ENT"); + click(button); + verifyThat("#display", hasText("2.0")); + button = find("#+-"); + click(button); + verifyThat("#display", hasText("-2.0")); + } + + @Test + public void testLn() + { + String strE = Double.toString(Math.E); + Button button; + + for (int i = 0; i < strE.length(); ++i) + { + button = find(("#" + strE.charAt(i)).replace(".", ",")); + click(button); + } + button = find("#LN"); + click(button); + verifyThat("#display", hasText(Double.toString(Math.log(Math.E)))); + } + + @Test + public void testSin() + { + String strPi = Double.toString(Math.PI); + Button button; + + for (int i = 0; i < strPi.length(); ++i) + { + button = find(("#" + strPi.charAt(i)).replace(".", ",")); + click(button); + } + button = find("#SIN"); + click(button); + verifyThat("#display", hasText(Double.toString(Math.sin(Math.PI)))); + } + + @Test + public void testCos() + { + String strPi = Double.toString(Math.PI); + Button button; + + for (int i = 0; i < strPi.length(); ++i) + { + button = find(("#" + strPi.charAt(i)).replace(".", ",")); + click(button); + } + button = find("#COS"); + click(button); + verifyThat("#display", hasText(Double.toString(Math.cos(Math.PI)))); + } + + @Test + public void testTan() + { + String strPi = Double.toString(Math.PI); + Button button; + + for (int i = 0; i < strPi.length(); ++i) + { + button = find(("#" + strPi.charAt(i)).replace(".", ",")); + click(button); + } + button = find("#TAN"); + click(button); + verifyThat("#display", hasText(Double.toString(Math.tan(Math.PI)))); + } + + @Test public void testNumbers() { Button button = find("#0"); |
