From 09e970553f6c32b52a927aa882b3ac282797c0a8 Mon Sep 17 00:00:00 2001 From: Stefan Suhren Date: Mon, 15 Jun 2015 15:04:26 +0200 Subject: Add various tests for the FXML interface --- test/gui/CalculatorTest.java | 218 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 218 insertions(+) (limited to 'test/gui/CalculatorTest.java') 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 @@ -82,6 +82,224 @@ public class CalculatorTest extends GuiTest verifyThat("#display", hasText("")); } + @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() { -- cgit v1.2.3-70-g09d2