You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
208 lines
7.4 KiB
208 lines
7.4 KiB
import static org.assertj.core.api.Assertions.*;
|
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
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;
|
|
|
|
import java.util.*;
|
|
import java.util.stream.Stream;
|
|
|
|
public class GameTest {
|
|
|
|
private Game g;
|
|
private Player p1;
|
|
private Game g2;
|
|
private Player p2;
|
|
|
|
|
|
@BeforeEach
|
|
void setup() {
|
|
g = new Game();
|
|
p1 = g.players.get(0);
|
|
|
|
g2 = new Game();
|
|
p2 = g2.players.get(0);
|
|
}
|
|
|
|
@ParameterizedTest
|
|
@MethodSource("checkDiceTestData")
|
|
void checkDiceTest(String testname, Collection<Integer> positions, int dice, int c, boolean expectedResult) {
|
|
Iterator<Figure> it = p1.figures.iterator();
|
|
Iterator<Integer> it2 = positions.iterator();
|
|
while(it.hasNext()) {
|
|
it.next().setPosition(it2.next());
|
|
}
|
|
boolean calculatedResult = g.checkDice(dice, p1, c, g);
|
|
assertThat(calculatedResult).describedAs(testname).isEqualTo(expectedResult);
|
|
}
|
|
|
|
static Stream<Arguments> checkDiceTestData () {
|
|
return Stream.of(
|
|
Arguments.of("No figures on Field - d: 1 - c: 1",
|
|
Arrays.asList(-1, -1, -1, -1),
|
|
1,
|
|
1,
|
|
true
|
|
),
|
|
Arguments.of("No figures on Field - d: 1 - c: 2",
|
|
Arrays.asList(-1, -1, -1, -1),
|
|
1,
|
|
2,
|
|
true
|
|
),
|
|
Arguments.of("No figures on Field - d: 1 - c: 3",
|
|
Arrays.asList(-1, -1, -1, -1),
|
|
1,
|
|
3,
|
|
false
|
|
),
|
|
Arguments.of("No figures on Field - d: 1 - c: 4",
|
|
Arrays.asList(-1, -1, -1, -1),
|
|
1,
|
|
4,
|
|
false
|
|
),
|
|
Arguments.of("Figures on Field - d: 1 - c: 1",
|
|
Arrays.asList(10, -1, 2, -1),
|
|
1,
|
|
1,
|
|
false
|
|
),
|
|
Arguments.of("Figures on Field - d: 6 - c: 1",
|
|
Arrays.asList(10, -1, 2, -1),
|
|
6,
|
|
1,
|
|
true
|
|
),
|
|
Arguments.of("Figures in Base + One in Finish (movable) - d: 5 - c: 1",
|
|
Arrays.asList(42, -1, -1, -1),
|
|
5,
|
|
1,
|
|
false
|
|
),
|
|
Arguments.of("Figures in Base + Two in Finish - d: 5 - c: 1",
|
|
Arrays.asList(42, 43, -1, -1),
|
|
5,
|
|
1,
|
|
true
|
|
)
|
|
);
|
|
}
|
|
|
|
@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, p1, g);
|
|
assertThat(calculatedResult).describedAs("Check Field Clear").isEqualTo(expectedResult);
|
|
}
|
|
|
|
@Test
|
|
void checkFieldClearTestFieldTakenByOwnFigure() {
|
|
int expectedResult = 2;
|
|
p1.figures.get(1).setPosition(1);
|
|
int calculatedResult = g.checkFieldClear(1, p1, g);
|
|
assertThat(calculatedResult).describedAs("Check Field Clear").isEqualTo(expectedResult);
|
|
}
|
|
|
|
@ParameterizedTest
|
|
@MethodSource("usableFiguresData")
|
|
void getUsableFiguresTest(String testname, int dice, Collection<Integer> positions, ArrayList<Integer> expectedResult) {
|
|
Iterator<Figure> figureIt = p1.figures.iterator();
|
|
Iterator<Integer> posIt = positions.iterator();
|
|
while(figureIt.hasNext()) {
|
|
Figure f = figureIt.next();
|
|
f.setPosition(posIt.next());
|
|
}
|
|
|
|
List<Integer> calculatedResult = g.getUsableFigures(dice, p1, g);
|
|
assertThat(calculatedResult).describedAs(testname).isEqualTo(expectedResult);
|
|
}
|
|
|
|
static Stream<Arguments> usableFiguresData () {
|
|
return Stream.of(
|
|
Arguments.of(
|
|
"Alle Figuren",
|
|
1,
|
|
Arrays.asList(10, 25, 2, 17),
|
|
new ArrayList<>(Arrays.asList(0, 1, 2, 3))
|
|
),
|
|
Arguments.of(
|
|
"Nur Figuren aus der Base",
|
|
6,
|
|
Arrays.asList(10, -1, -1, -1),
|
|
new ArrayList<>(Arrays.asList(1, 2, 3))
|
|
),
|
|
Arguments.of(
|
|
"Figur die das Startfeld besetzt",
|
|
6,
|
|
Arrays.asList(10, 0, -1, -1),
|
|
new ArrayList<>(List.of(1))
|
|
),
|
|
Arguments.of(
|
|
"Figur vor dem Ziel - kann man benutzen",
|
|
5,
|
|
Arrays.asList(10, 37, -1, -1),
|
|
new ArrayList<>(Arrays.asList(0,1))
|
|
),
|
|
Arguments.of(
|
|
"Figur vor dem Ziel - kann man nicht benutzen",
|
|
5,
|
|
Arrays.asList(10, 39, -1, -1),
|
|
new ArrayList<>(List.of(0))
|
|
),
|
|
Arguments.of(
|
|
"Nur Figuren die auf ein freies Feld kommen",
|
|
2,
|
|
Arrays.asList(10, 12, -1, -1),
|
|
new ArrayList<>(List.of(1))
|
|
),
|
|
Arguments.of(
|
|
"Figur auf Startfeld",
|
|
6,
|
|
Arrays.asList(-1, -1, -1, 0),
|
|
new ArrayList<>(List.of(3))
|
|
),
|
|
Arguments.of(
|
|
"Im Ziel überworfen nur andere Figuren möglich",
|
|
5,
|
|
Arrays.asList(-1, 41, -1, 0),
|
|
new ArrayList<>(List.of(3))
|
|
),
|
|
Arguments.of(
|
|
"Im Haus bewegen",
|
|
2,
|
|
Arrays.asList(-1, 41, -1, 0),
|
|
new ArrayList<>(List.of(1, 3))
|
|
)
|
|
);
|
|
}
|
|
|
|
@ParameterizedTest
|
|
@MethodSource("setFigureData")
|
|
void setFigureTest(String testname, int figId, int dice, int currentPosition, int expectedResult) {
|
|
p2.figures.get(figId).setPosition(currentPosition);
|
|
int calculatedResult = g2.setFigure(figId, dice, p2, g2);
|
|
assertThat(calculatedResult).describedAs(testname).isEqualTo(expectedResult);
|
|
}
|
|
|
|
static Stream<Arguments> setFigureData () {
|
|
return Stream.of(
|
|
Arguments.of("Figur wird auf Feld gesetzt - Niemand gekicked", 0, 4, 5, 9),
|
|
Arguments.of("Figur wird auf Feld gesetzt - Jemand gekicked", 1, 4, 10, 14),
|
|
Arguments.of("Figur wird ins Haus gesetzt", 3, 4, 38, 42),
|
|
Arguments.of("Figur wird im Haus gesetzt", 3, 3, 41, 44)
|
|
);
|
|
}
|
|
}
|
|
|
|
|