From a15d7836caefd3b2ab05274b229cb12df0895b53 Mon Sep 17 00:00:00 2001 From: jacob Date: Wed, 17 Apr 2024 19:54:39 +0200 Subject: [PATCH 1/5] =?UTF-8?q?erster=20gr=C3=BCner=20Test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../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 ddff0daf..48307889 100644 --- a/app/src/test/java/htw/berlin/prog2/ha1/CalculatorTest.java +++ b/app/src/test/java/htw/berlin/prog2/ha1/CalculatorTest.java @@ -88,6 +88,40 @@ void testMultipleDecimalDots() { assertEquals(expected, actual); } + @Test + @DisplayName("should display the correct result after inverting a non-zero number") + void testInversion() { + Calculator calc = new Calculator(); + + calc.pressDigitKey(2); + calc.pressUnaryOperationKey("1/x"); + + String expected = "0.5"; + String actual = calc.readScreen(); + + assertEquals(expected, actual); + } + + @Test + @DisplayName("should display error when trying to add two decimal dots in a number") + void testDoubleDecimalDotError() { + Calculator calc = new Calculator(); + + calc.pressDigitKey(3); + calc.pressDotKey(); + calc.pressDigitKey(1); + calc.pressDotKey(); // Zweites Dezimalzeichen hinzufügen + calc.pressDigitKey(5); + + String expected = "Error"; + String actual = calc.readScreen(); + + assertEquals(expected, actual); + } + + + + //TODO hier weitere Tests erstellen } From 541e9480bc477346865f5fff25083de40e74d46a Mon Sep 17 00:00:00 2001 From: jacob Date: Thu, 18 Apr 2024 15:43:10 +0200 Subject: [PATCH 2/5] Erster roter Test "testNegateZero" --- .../java/htw/berlin/prog2/ha1/CalculatorTest.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) 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 48307889..23bf6bf7 100644 --- a/app/src/test/java/htw/berlin/prog2/ha1/CalculatorTest.java +++ b/app/src/test/java/htw/berlin/prog2/ha1/CalculatorTest.java @@ -103,17 +103,14 @@ void testInversion() { } @Test - @DisplayName("should display error when trying to add two decimal dots in a number") - void testDoubleDecimalDotError() { + @DisplayName("should display zero when attempting to negate zero") + void testNegateZero() { Calculator calc = new Calculator(); - calc.pressDigitKey(3); - calc.pressDotKey(); - calc.pressDigitKey(1); - calc.pressDotKey(); // Zweites Dezimalzeichen hinzufügen - calc.pressDigitKey(5); + calc.pressDigitKey(0); + calc.pressNegativeKey(); - String expected = "Error"; + String expected = "0"; String actual = calc.readScreen(); assertEquals(expected, actual); From e13de7f7644d303caac633d8743d798e16e678bb Mon Sep 17 00:00:00 2001 From: jacob Date: Thu, 18 Apr 2024 15:49:28 +0200 Subject: [PATCH 3/5] =?UTF-8?q?"testNegateZero"=20l=C3=A4uft=20nun=20nicht?= =?UTF-8?q?=20mehr=20auf=20einen=20Fehler,=20da=20die=20Methode=20"pressNe?= =?UTF-8?q?gativeKey"=20angepasst=20wurde.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/htw/berlin/prog2/ha1/Calculator.java | 5 +++++ 1 file changed, 5 insertions(+) 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..2656d700 100644 --- a/app/src/main/java/htw/berlin/prog2/ha1/Calculator.java +++ b/app/src/main/java/htw/berlin/prog2/ha1/Calculator.java @@ -103,8 +103,13 @@ public void pressDotKey() { * aktualisiert und die Inhalt fortan als negativ interpretiert. * Zeigt der Bildschirm bereits einen negativen Wert mit führendem Minus an, dann wird dieses * entfernt und der Inhalt fortan als positiv interpretiert. + * Zeigt der Bildschirm eine Null an, so wird keine Anpassung vorgenommen, da die Negation von Null immer Null ist. */ public void pressNegativeKey() { + if (screen.equals("0")) { + // Wenn der Bildschirm "0" anzeigt, ändern wir nichts. + return; + } screen = screen.startsWith("-") ? screen.substring(1) : "-" + screen; } From 56bd95be2587dba87753ea878328f562e1ff7262 Mon Sep 17 00:00:00 2001 From: jacob Date: Wed, 24 Apr 2024 19:50:18 +0200 Subject: [PATCH 4/5] =?UTF-8?q?Zweiter=20roter=20Test=20"testMultiplePosit?= =?UTF-8?q?iveAddition"=20hinzugef=C3=BCgt.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/htw/berlin/prog2/ha1/Calculator.java | 2 +- .../java/htw/berlin/prog2/ha1/CalculatorTest.java | 15 ++++++++++++++- 2 files changed, 15 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 2656d700..1b2f6b40 100644 --- a/app/src/main/java/htw/berlin/prog2/ha1/Calculator.java +++ b/app/src/main/java/htw/berlin/prog2/ha1/Calculator.java @@ -107,7 +107,6 @@ public void pressDotKey() { */ public void pressNegativeKey() { if (screen.equals("0")) { - // Wenn der Bildschirm "0" anzeigt, ändern wir nichts. return; } screen = screen.startsWith("-") ? screen.substring(1) : "-" + screen; @@ -135,4 +134,5 @@ public void pressEqualsKey() { if(screen.endsWith(".0")) screen = screen.substring(0,screen.length()-2); if(screen.contains(".") && screen.length() > 11) screen = screen.substring(0, 10); } + } 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 23bf6bf7..430518dd 100644 --- a/app/src/test/java/htw/berlin/prog2/ha1/CalculatorTest.java +++ b/app/src/test/java/htw/berlin/prog2/ha1/CalculatorTest.java @@ -116,10 +116,23 @@ void testNegateZero() { assertEquals(expected, actual); } + @Test + @DisplayName("should display result after adding four positive one-digit numbers") + void testMultiplePositiveAddition() { + Calculator calc = new Calculator(); + calc.pressDigitKey(5); + calc.pressBinaryOperationKey("+"); + calc.pressDigitKey(5); + calc.pressBinaryOperationKey("+"); + calc.pressDigitKey(3); + calc.pressEqualsKey(); + String expected = "13.0"; // 8 + String actual = calc.readScreen(); + assertEquals(expected, actual); + } - //TODO hier weitere Tests erstellen } From efd0ed2927e397c1031412206c016ca3f931b5d1 Mon Sep 17 00:00:00 2001 From: jacob Date: Sun, 28 Apr 2024 23:33:10 +0200 Subject: [PATCH 5/5] =?UTF-8?q?Zweiten=20roten=20Test=20durch=20anpassung?= =?UTF-8?q?=20der=20"pressBinaryOperationKey"=20Methode=20best=C3=A4tigt.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/htw/berlin/prog2/ha1/Calculator.java | 4 ++++ app/src/test/java/htw/berlin/prog2/ha1/CalculatorTest.java | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) 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 1b2f6b40..ab4452c1 100644 --- a/app/src/main/java/htw/berlin/prog2/ha1/Calculator.java +++ b/app/src/main/java/htw/berlin/prog2/ha1/Calculator.java @@ -60,6 +60,10 @@ public void pressClearKey() { * @param operation "+" für Addition, "-" für Substraktion, "x" für Multiplikation, "/" für Division */ public void pressBinaryOperationKey(String operation) { + // Multiple numbers + if (!latestOperation.isEmpty()) { + pressEqualsKey(); // Perform the pending operation + } latestValue = Double.parseDouble(screen); latestOperation = operation; } 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 430518dd..51e3c9ed 100644 --- a/app/src/test/java/htw/berlin/prog2/ha1/CalculatorTest.java +++ b/app/src/test/java/htw/berlin/prog2/ha1/CalculatorTest.java @@ -128,7 +128,7 @@ void testMultiplePositiveAddition() { calc.pressDigitKey(3); calc.pressEqualsKey(); - String expected = "13.0"; // 8 + String expected = "13"; // 8 String actual = calc.readScreen(); assertEquals(expected, actual);