Browse Source

Add toString

AIPlayer
FelixKrull 3 years ago
parent
commit
c6298b001b
  1. 12
      src/main/java/Player.java
  2. 9
      src/test/java/PlayerTest.java

12
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);
}

9
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);
}
}
Loading…
Cancel
Save