From 8a5ba92d528c33a7bc09aa768740fb353e898af2 Mon Sep 17 00:00:00 2001 From: Tobias Krause Date: Wed, 22 Dec 2021 16:42:00 +0100 Subject: [PATCH] gameexplorer: points cant be less than zero --- src/main/java/de/tims/gameexplorer/Player.java | 2 +- src/test/java/de/tims/gameexplorer/PlayerTest.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/tims/gameexplorer/Player.java b/src/main/java/de/tims/gameexplorer/Player.java index 4bae8ab..0200dc8 100644 --- a/src/main/java/de/tims/gameexplorer/Player.java +++ b/src/main/java/de/tims/gameexplorer/Player.java @@ -9,7 +9,7 @@ public class Player { } public void addPoints(int pointsToAdd) { - this.points += pointsToAdd; + this.points = (this.points + pointsToAdd > 0) ? this.points + pointsToAdd : 0; } public int getPoints() { diff --git a/src/test/java/de/tims/gameexplorer/PlayerTest.java b/src/test/java/de/tims/gameexplorer/PlayerTest.java index 716245b..2d782d1 100644 --- a/src/test/java/de/tims/gameexplorer/PlayerTest.java +++ b/src/test/java/de/tims/gameexplorer/PlayerTest.java @@ -25,7 +25,8 @@ class PlayerTest { return Stream.of(Arguments.of("NoPointsBeforeGet0Points", 0, 0, 0), Arguments.of("NoPointsBeforeGet10Points", 0, 10, 10), Arguments.of("10PointsBeforeAdd10Points", 10, 10, 20), - Arguments.of("10PointsBeforeLose10Points", 10, -10, 0)); + Arguments.of("10PointsBeforeLose10Points", 10, -10, 0), + Arguments.of("LoseMorePointsThanYouHave", 10, -20, 0)); } }