From 13f8e09b28aaa5a62e90f1c4b173a112c0002faa Mon Sep 17 00:00:00 2001 From: FelixKrull Date: Tue, 18 Jan 2022 09:30:49 +0100 Subject: [PATCH 1/2] Add rollDice --- src/main/java/Player.java | 5 +++++ src/test/java/PlayerTest.java | 28 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/main/java/Player.java create mode 100644 src/test/java/PlayerTest.java diff --git a/src/main/java/Player.java b/src/main/java/Player.java new file mode 100644 index 0000000..57920b0 --- /dev/null +++ b/src/main/java/Player.java @@ -0,0 +1,5 @@ +public class Player { + public int rollDice() { + return (int) (Math.random() * 6); + } +} diff --git a/src/test/java/PlayerTest.java b/src/test/java/PlayerTest.java new file mode 100644 index 0000000..1dfa925 --- /dev/null +++ b/src/test/java/PlayerTest.java @@ -0,0 +1,28 @@ +import static org.assertj.core.api.Assertions.*; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +public class PlayerTest { + + private Player p; + + @BeforeEach + void setup() { + p = new Player(); + } + + @Test + void testDice() { + int calculatedResult = p.rollDice(); + assertThat(calculatedResult).describedAs("Dice result").isBetween(1,6); + } + + + + +} From c6298b001b3f38b716e0b4223a99cdcee1d948bc Mon Sep 17 00:00:00 2001 From: FelixKrull Date: Tue, 18 Jan 2022 09:41:28 +0100 Subject: [PATCH 2/2] Add toString --- src/main/java/Player.java | 12 ++++++++++++ src/test/java/PlayerTest.java | 9 +++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/Player.java b/src/main/java/Player.java index 57920b0..6cba702 100644 --- a/src/main/java/Player.java +++ b/src/main/java/Player.java @@ -1,4 +1,16 @@ public class Player { + + String name; + + public Player (String name) { + this.name = name; + } + + @Override + public String toString() { + return name; + } + public int rollDice() { return (int) (Math.random() * 6); } diff --git a/src/test/java/PlayerTest.java b/src/test/java/PlayerTest.java index 1dfa925..86faf07 100644 --- a/src/test/java/PlayerTest.java +++ b/src/test/java/PlayerTest.java @@ -13,7 +13,7 @@ public class PlayerTest { @BeforeEach void setup() { - p = new Player(); + p = new Player("Rot"); } @Test @@ -22,7 +22,12 @@ public class PlayerTest { assertThat(calculatedResult).describedAs("Dice result").isBetween(1,6); } - + @Test + void testToString() { + String expectedResult = "Rot"; + String calculatedResult = p.toString(); + assertThat(calculatedResult).describedAs("Player Name").isEqualTo(expectedResult); + } }