Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
calculator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
PIERRON Laurent
calculator
Commits
dc35595d
Commit
dc35595d
authored
2 years ago
by
PIERRON Laurent
Browse files
Options
Downloads
Patches
Plain Diff
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
2 years ago
Stage: build
Stage: test
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/fr/nancy/iut/CalcEngine.java
+2
-1
2 additions, 1 deletion
src/main/java/fr/nancy/iut/CalcEngine.java
src/test/java/fr/nancy/iut/CalcEngineTest.java
+27
-1
27 additions, 1 deletion
src/test/java/fr/nancy/iut/CalcEngineTest.java
with
29 additions
and
2 deletions
src/main/java/fr/nancy/iut/CalcEngine.java
+
2
−
1
View file @
dc35595d
...
...
@@ -72,10 +72,11 @@ public class CalcEngine
if
(
previousOperator
==
'+'
)
{
displayValue
=
leftOperand
+
displayValue
;
}
else
{
else
if
(
previousOperator
==
'-'
)
{
displayValue
=
leftOperand
-
displayValue
;
}
leftOperand
=
0
;
previousOperator
=
'='
;
}
/**
...
...
This diff is collapsed.
Click to expand it.
src/test/java/fr/nancy/iut/CalcEngineTest.java
+
27
−
1
View file @
dc35595d
...
...
@@ -25,7 +25,7 @@ public class CalcEngineTest {
}
@Test
@DisplayName
(
"
T
Testing 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
());
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment