Skip to content
Snippets Groups Projects
Commit c05d208e authored by PIERRON Laurent's avatar PIERRON Laurent :man_in_tuxedo_tone1:
Browse files

Adding multiplication.

parent 2f36359e
No related branches found
No related tags found
No related merge requests found
Pipeline #10552 passed
......@@ -81,6 +81,14 @@ public class CalcEngine
applyOperator('-');
}
/**
* The '*' button was pressed.
*/
public void multiply()
{
applyOperator('*');
}
/**
* The '=' button was pressed.
*/
......@@ -156,6 +164,11 @@ public class CalcEngine
haveLeftOperand = true;
leftOperand = displayValue;
}
case '*' -> {
displayValue = leftOperand * displayValue;
haveLeftOperand = true;
leftOperand = displayValue;
}
default -> keySequenceError();
}
}
......
......@@ -91,4 +91,18 @@ class CalcEngineTest {
// Return the result, which should be 5.
assertEquals(5, engine.getDisplayValue());
}
@Test
@DisplayName("Testing the multiply operation : 9 * 4 = 36")
void testMultiply() {
// Make sure the engine is in a valid starting state.
engine.clear();
// Simulate the presses: 9 - 4 =
engine.numberPressed(9);
engine.multiply();
engine.numberPressed(4);
engine.equals();
// Return the result, which should be 5.
assertEquals(36, engine.getDisplayValue());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment