diff --git a/src/main/java/Player.java b/src/main/java/Player.java new file mode 100644 index 0000000..6cba702 --- /dev/null +++ b/src/main/java/Player.java @@ -0,0 +1,17 @@ +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 new file mode 100644 index 0000000..86faf07 --- /dev/null +++ b/src/test/java/PlayerTest.java @@ -0,0 +1,33 @@ +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("Rot"); + } + + @Test + void testDice() { + int calculatedResult = p.rollDice(); + 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); + } + + +}