Skip to content
Snippets Groups Projects
Commit c45a7fde authored by Johannes Link's avatar Johannes Link
Browse files

Moved score incrementation logic to Score class

parent af9730fa
Branches
Tags after-2-2
No related merge requests found
......@@ -11,4 +11,11 @@ public record Score(int a, int b) {
return a + ":" + b;
}
public Score aIncrementBy(int points) {
return new Score(a + points, b);
}
public Score bIncrementBy(int points) {
return new Score(a, b + points);
}
}
......@@ -4,12 +4,12 @@ public enum Team {
A {
@Override
Score score(Score oldScore, int points) {
return Score.ab(oldScore.a() + points, oldScore.b());
return oldScore.aIncrementBy(points);
}
}, B {
@Override
Score score(Score oldScore, int points) {
return Score.ab(oldScore.a(), oldScore.b() + points);
return oldScore.bIncrementBy(points);
}
}, NONE;
......
......@@ -36,4 +36,18 @@ class ScoreTests {
void toStringDisplaysPointsSeparatedByColon() {
assertEquals("33:45", Score.ab(33, 45).toString());
}
@Test
void incrementA() {
Score score = new Score(3, 5);
Score newScore = score.aIncrementBy(1);
assertEquals(Score.ab(4, 5), newScore);
}
@Test
void incrementB() {
Score score = new Score(3, 5);
Score newScore = score.bIncrementBy(1);
assertEquals(Score.ab(3, 6), newScore);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment