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

Adding a new operator '=' to avoid to do a sub again after an equal operation.

parent 2c10fd55
No related branches found
No related tags found
No related merge requests found
Pipeline #10577 failed
......@@ -72,10 +72,11 @@ public class CalcEngine
if (previousOperator == '+') {
displayValue = leftOperand + displayValue;
}
else {
else if (previousOperator == '-') {
displayValue = leftOperand - displayValue;
}
leftOperand = 0;
previousOperator = '=';
}
/**
......
......@@ -25,7 +25,7 @@ public class CalcEngineTest {
}
@Test
@DisplayName("TTesting the addition operation : 3 + 4 = 7")
@DisplayName("Testing the addition operation : 3 + 4 = 7")
void testPlus() {
// Make sure the engine is in a valid starting state.
engine.clear();
......@@ -38,4 +38,30 @@ public class CalcEngineTest {
assertEquals(7, engine.getDisplayValue());
}
@Test
@DisplayName("Testing the operation : 1 + 2 + 3 = - 2 = - 1 = 3 ")
void testComplexFormula() {
// Make sure the engine is in a valid starting state.
engine.clear();
// Simulate the key presses: 1 + 2 + 3 =
engine.numberPressed(1);
engine.plus();
engine.numberPressed(2);
engine.plus();
engine.numberPressed(3);
engine.equals();
// Intermediate result : 6
assertEquals(6, engine.getDisplayValue());
engine.minus();
engine.numberPressed(2);
engine.equals();
// Intermediate result : 4 (6 _ 2)
assertEquals(4, engine.getDisplayValue());
engine.minus();
engine.numberPressed(1);
engine.equals();
// Final result : 3 (4 - 1).
assertEquals(3, engine.getDisplayValue());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment