Browse Source

gameexplorer: points cant be less than zero

gameexplorer
Tobias Krause 3 years ago
committed by Lorenz Hohmann
parent
commit
8a5ba92d52
  1. 2
      src/main/java/de/tims/gameexplorer/Player.java
  2. 3
      src/test/java/de/tims/gameexplorer/PlayerTest.java

2
src/main/java/de/tims/gameexplorer/Player.java

@ -9,7 +9,7 @@ public class Player {
} }
public void addPoints(int pointsToAdd) { public void addPoints(int pointsToAdd) {
this.points += pointsToAdd;
this.points = (this.points + pointsToAdd > 0) ? this.points + pointsToAdd : 0;
} }
public int getPoints() { public int getPoints() {

3
src/test/java/de/tims/gameexplorer/PlayerTest.java

@ -25,7 +25,8 @@ class PlayerTest {
return Stream.of(Arguments.of("NoPointsBeforeGet0Points", 0, 0, 0), return Stream.of(Arguments.of("NoPointsBeforeGet0Points", 0, 0, 0),
Arguments.of("NoPointsBeforeGet10Points", 0, 10, 10), Arguments.of("NoPointsBeforeGet10Points", 0, 10, 10),
Arguments.of("10PointsBeforeAdd10Points", 10, 10, 20), Arguments.of("10PointsBeforeAdd10Points", 10, 10, 20),
Arguments.of("10PointsBeforeLose10Points", 10, -10, 0));
Arguments.of("10PointsBeforeLose10Points", 10, -10, 0),
Arguments.of("LoseMorePointsThanYouHave", 10, -20, 0));
} }
} }
Loading…
Cancel
Save