Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/htw/berlin/prog2/ha1/Calculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public void pressNegativeKey() {
* und das Ergebnis direkt angezeigt.
*/
public void pressEqualsKey() {
if(latestOperation.equals("")) return;
var result = switch(latestOperation) {
case "+" -> latestValue + Double.parseDouble(screen);
case "-" -> latestValue - Double.parseDouble(screen);
Expand Down
36 changes: 35 additions & 1 deletion src/test/java/htw/berlin/prog2/ha1/CalculatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,39 @@ void testMultipleDecimalDots() {


//TODO hier weitere Tests erstellen
}

@Test
@DisplayName("should multiply two numbers")
void testMultiplication() {
Calculator calc = new Calculator();

calc.pressDigitKey(3);
calc.pressBinaryOperationKey("x");
calc.pressDigitKey(4);
calc.pressEqualsKey();

assertEquals("12", calc.readScreen());

}
@Test
@DisplayName("should not change value when equals pressed without operation")
void testEqualsWithoutOperation() {
Calculator calc = new Calculator();

calc.pressDigitKey(5);
calc.pressEqualsKey();

assertEquals("5", calc.readScreen());
}
@Test
@DisplayName("should toggle negative sign correctly")
void testNegativeToggle() {
Calculator calc = new Calculator();

calc.pressDigitKey(7);
calc.pressNegativeKey();
calc.pressNegativeKey();

assertEquals("7", calc.readScreen());
}
}