|
@ -1,6 +1,7 @@ |
|
|
import static org.assertj.core.api.Assertions.*; |
|
|
import static org.assertj.core.api.Assertions.*; |
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
|
|
|
import org.junit.jupiter.api.Test; |
|
|
import org.junit.jupiter.params.ParameterizedTest; |
|
|
import org.junit.jupiter.params.ParameterizedTest; |
|
|
import org.junit.jupiter.params.provider.Arguments; |
|
|
import org.junit.jupiter.params.provider.Arguments; |
|
|
import org.junit.jupiter.params.provider.MethodSource; |
|
|
import org.junit.jupiter.params.provider.MethodSource; |
|
@ -13,24 +14,26 @@ import java.util.stream.Stream; |
|
|
public class GameTest { |
|
|
public class GameTest { |
|
|
|
|
|
|
|
|
private Game g; |
|
|
private Game g; |
|
|
private Player p; |
|
|
|
|
|
|
|
|
private Player p1; |
|
|
|
|
|
private Player p2; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@BeforeEach |
|
|
@BeforeEach |
|
|
void setup() { |
|
|
void setup() { |
|
|
g = new Game(); |
|
|
g = new Game(); |
|
|
p = new Player("Rot", 1, 40, 43); |
|
|
|
|
|
|
|
|
p1 = new Player("Rot", 1, 40, 43); |
|
|
|
|
|
p2 = new Player("Blau",10, 44, 47); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ParameterizedTest |
|
|
@ParameterizedTest |
|
|
@MethodSource("checkDiceTestData") |
|
|
@MethodSource("checkDiceTestData") |
|
|
void checkDiceTest(String testname, Collection<Integer> positions, int dice, int c, boolean expectedResult) { |
|
|
void checkDiceTest(String testname, Collection<Integer> positions, int dice, int c, boolean expectedResult) { |
|
|
Iterator<Figure> it = p.figures.iterator(); |
|
|
|
|
|
|
|
|
Iterator<Figure> it = p1.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, p, c); |
|
|
|
|
|
|
|
|
boolean calculatedResult = g.checkDice(dice, p1, c); |
|
|
assertThat(calculatedResult).describedAs(testname).isEqualTo(expectedResult); |
|
|
assertThat(calculatedResult).describedAs(testname).isEqualTo(expectedResult); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -74,4 +77,27 @@ public class GameTest { |
|
|
) |
|
|
) |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
void checkFieldClearTestFieldNotTaken() { |
|
|
|
|
|
int expectedResult = 0; |
|
|
|
|
|
int calculatedResult = g.checkFieldClear(1, p1, g); |
|
|
|
|
|
assertThat(calculatedResult).describedAs("Check Field Clear").isEqualTo(expectedResult); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
void checkFieldClearTestFieldTakenByOtherPlayer() { |
|
|
|
|
|
int expectedResult = 1; |
|
|
|
|
|
g.players.get(1).figures.get(0).setPosition(1); |
|
|
|
|
|
int calculatedResult = g.checkFieldClear(1, g.players.get(0), g); |
|
|
|
|
|
assertThat(calculatedResult).describedAs("Check Field Clear").isEqualTo(expectedResult); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
void checkFieldClearTestFieldTakenByOwnFigure() { |
|
|
|
|
|
int expectedResult = 2; |
|
|
|
|
|
g.players.get(0).figures.get(1).setPosition(1); |
|
|
|
|
|
int calculatedResult = g.checkFieldClear(1, g.players.get(0), g); |
|
|
|
|
|
assertThat(calculatedResult).describedAs("Check Field Clear").isEqualTo(expectedResult); |
|
|
|
|
|
} |
|
|
} |
|
|
} |