From dd6aebdfae88275ce6e291603e925ec14fdc8600 Mon Sep 17 00:00:00 2001 From: Vineh1 Date: Wed, 17 Apr 2024 19:57:39 +0200 Subject: [PATCH 1/4] Teilaufgabe1 --- .../htw/berlin/prog2/ha1/CalculatorTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app/src/test/java/htw/berlin/prog2/ha1/CalculatorTest.java b/app/src/test/java/htw/berlin/prog2/ha1/CalculatorTest.java index ddff0daf..efdf4fb9 100644 --- a/app/src/test/java/htw/berlin/prog2/ha1/CalculatorTest.java +++ b/app/src/test/java/htw/berlin/prog2/ha1/CalculatorTest.java @@ -90,5 +90,23 @@ void testMultipleDecimalDots() { //TODO hier weitere Tests erstellen + + @Test + @DisplayName("should display result after subtracting two positive multi-digit numbers") + void testPositiveSubtraction() { + Calculator calc = new Calculator(); + + calc.pressDigitKey(2); + calc.pressDigitKey(0); + calc.pressBinaryOperationKey("-"); + calc.pressDigitKey(2); + calc.pressDigitKey(0); + calc.pressEqualsKey(); + + String expected = "0"; + String actual = calc.readScreen(); + + assertEquals(expected, actual); + } } From ecdc6aba382038093eda800de51b85d0956df3ae Mon Sep 17 00:00:00 2001 From: Vineh1 Date: Wed, 24 Apr 2024 19:59:16 +0200 Subject: [PATCH 2/4] Teilaufgabe2 (two red tests) --- .../htw/berlin/prog2/ha1/CalculatorTest.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/app/src/test/java/htw/berlin/prog2/ha1/CalculatorTest.java b/app/src/test/java/htw/berlin/prog2/ha1/CalculatorTest.java index efdf4fb9..401d650d 100644 --- a/app/src/test/java/htw/berlin/prog2/ha1/CalculatorTest.java +++ b/app/src/test/java/htw/berlin/prog2/ha1/CalculatorTest.java @@ -108,5 +108,39 @@ void testPositiveSubtraction() { assertEquals(expected, actual); } + + @Test + @DisplayName("should display result after adding three positive multi-digit numbers") + void testdoublePositiveAddition() { + Calculator calc = new Calculator(); + + calc.pressDigitKey(2); + calc.pressBinaryOperationKey("+"); + calc.pressDigitKey(3); + calc.pressBinaryOperationKey("+"); + calc.pressDigitKey(5); + calc.pressEqualsKey(); + + String expected = "10"; + String actual = calc.readScreen(); + + assertEquals(expected, actual); + } + + @Test + @DisplayName("should display Error when attempting an unsupported operation") + void testUnsupportedOperation() { + Calculator calc = new Calculator(); + + calc.pressDigitKey(2); + calc.pressBinaryOperationKey("^"); + calc.pressDigitKey(2); + calc.pressEqualsKey(); + + String expected = "4"; + String actual = calc.readScreen(); + + assertEquals(expected, actual); + } } From d1ac2dceee265ca445d41baa2a5c4f4557bec958 Mon Sep 17 00:00:00 2001 From: Vineh1 Date: Wed, 24 Apr 2024 19:59:16 +0200 Subject: [PATCH 3/4] Teilaufgabe2 (two red tests) --- .../htw/berlin/prog2/ha1/CalculatorTest.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/app/src/test/java/htw/berlin/prog2/ha1/CalculatorTest.java b/app/src/test/java/htw/berlin/prog2/ha1/CalculatorTest.java index efdf4fb9..bb06f053 100644 --- a/app/src/test/java/htw/berlin/prog2/ha1/CalculatorTest.java +++ b/app/src/test/java/htw/berlin/prog2/ha1/CalculatorTest.java @@ -108,5 +108,37 @@ void testPositiveSubtraction() { assertEquals(expected, actual); } + + @Test + @DisplayName("should display result after adding three positive multi-digit numbers") + void testdoublePositiveAddition() { + Calculator calc = new Calculator(); + + calc.pressDigitKey(2); + calc.pressBinaryOperationKey("+"); + calc.pressDigitKey(3); + calc.pressBinaryOperationKey("+"); + calc.pressDigitKey(5); + calc.pressEqualsKey(); + + String expected = "10"; + String actual = calc.readScreen(); + + assertEquals(expected, actual); + } + + @Test + @DisplayName("should display Error when attempting an unsupported operation") + void testUnsupportedOperation() { + Calculator calc = new Calculator(); + + calc.pressDigitKey(2); + calc.pressBinaryOperationKey("^"); + + String expected = "Error"; + String actual = calc.readScreen(); + + assertEquals(expected, actual); + } } From 8bffb77bb13512a49e5a55ff71fd9ec93194fb98 Mon Sep 17 00:00:00 2001 From: Vineh1 Date: Thu, 25 Apr 2024 18:40:44 +0200 Subject: [PATCH 4/4] Teilaufgabe3 (one red test changed and both red tests fixed) --- .../main/java/htw/berlin/prog2/ha1/Calculator.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/htw/berlin/prog2/ha1/Calculator.java b/app/src/main/java/htw/berlin/prog2/ha1/Calculator.java index 84c04f21..00bf6146 100644 --- a/app/src/main/java/htw/berlin/prog2/ha1/Calculator.java +++ b/app/src/main/java/htw/berlin/prog2/ha1/Calculator.java @@ -60,10 +60,19 @@ public void pressClearKey() { * @param operation "+" für Addition, "-" für Substraktion, "x" für Multiplikation, "/" für Division */ public void pressBinaryOperationKey(String operation) { - latestValue = Double.parseDouble(screen); - latestOperation = operation; + if(!latestOperation.isEmpty()) { //fix1 + pressEqualsKey(); + } + if (operation.equals("+") || operation.equals("-") || operation.equals("x") || operation.equals("/")) { //fix2 + latestValue = Double.parseDouble(screen); + latestOperation = operation; + } else { + screen = "Error"; + } } + + /** * Empfängt den Wert einer gedrückten unären Operationstaste, also eine der drei Operationen * Quadratwurzel, Prozent, Inversion, welche nur einen Operanden benötigen.