Browse Source

Refactor GameTest Player init

AIPlayer
Jonas Wagner 3 years ago
parent
commit
ec29bc93f5
  1. 14
      src/test/java/GameTest.java

14
src/test/java/GameTest.java

@ -13,64 +13,60 @@ import java.util.stream.Stream;
public class GameTest { public class GameTest {
private Game g; private Game g;
private Player p;
@BeforeEach @BeforeEach
void setup() { void setup() {
g = new Game(); g = new Game();
p = new Player("Rot", 1, 40, 43);
} }
@ParameterizedTest @ParameterizedTest
@MethodSource("checkDiceTestData") @MethodSource("checkDiceTestData")
void checkDiceTest(String testname, Player testPlayer, Collection<Integer> positions, int dice, int c, boolean expectedResult) {
Iterator<Figure> it = testPlayer.figures.iterator();
void checkDiceTest(String testname, Collection<Integer> positions, int dice, int c, boolean expectedResult) {
Iterator<Figure> it = p.figures.iterator();
Iterator<Integer> it2 = positions.iterator(); Iterator<Integer> it2 = positions.iterator();
while(it.hasNext()) { while(it.hasNext()) {
it.next().setPosition(it2.next()); it.next().setPosition(it2.next());
} }
boolean calculatedResult = g.checkDice(dice, testPlayer, c);
boolean calculatedResult = g.checkDice(dice, p, c);
assertThat(calculatedResult).describedAs(testname).isEqualTo(expectedResult); assertThat(calculatedResult).describedAs(testname).isEqualTo(expectedResult);
} }
static Stream<Arguments> checkDiceTestData () { static Stream<Arguments> checkDiceTestData () {
return Stream.of( return Stream.of(
Arguments.of("No figures on Field - d: 1 - c: 1", Arguments.of("No figures on Field - d: 1 - c: 1",
new Player("Rot", 40, 43),
Arrays.asList(-1, -1, -1, -1), Arrays.asList(-1, -1, -1, -1),
1, 1,
1, 1,
true true
), ),
Arguments.of("No figures on Field - d: 1 - c: 2", Arguments.of("No figures on Field - d: 1 - c: 2",
new Player("Rot", 40, 43),
Arrays.asList(-1, -1, -1, -1), Arrays.asList(-1, -1, -1, -1),
1, 1,
2, 2,
true true
), ),
Arguments.of("No figures on Field - d: 1 - c: 3", Arguments.of("No figures on Field - d: 1 - c: 3",
new Player("Rot", 40, 43),
Arrays.asList(-1, -1, -1, -1), Arrays.asList(-1, -1, -1, -1),
1, 1,
3, 3,
true true
), ),
Arguments.of("No figures on Field - d: 1 - c: 4", Arguments.of("No figures on Field - d: 1 - c: 4",
new Player("Rot", 40, 43),
Arrays.asList(-1, -1, -1, -1), Arrays.asList(-1, -1, -1, -1),
1, 1,
4, 4,
false false
), ),
Arguments.of("Figures on Field - d: 1 - c: 1", Arguments.of("Figures on Field - d: 1 - c: 1",
new Player("Rot", 40, 43),
Arrays.asList(10, -1, 2, -1), Arrays.asList(10, -1, 2, -1),
1, 1,
1, 1,
false false
), ),
Arguments.of("Figures on Field - d: 6 - c: 1", Arguments.of("Figures on Field - d: 6 - c: 1",
new Player("Rot", 40, 43),
Arrays.asList(10, -1, 2, -1), Arrays.asList(10, -1, 2, -1),
6, 6,
1, 1,

Loading…
Cancel
Save