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.

131 lines
5.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.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.stream.Stream;
public class GameboardTest {
private Gameboard gb;
private Game g;
@BeforeEach
void setup() {
gb = new Gameboard();
g = new Game();
}
@Test
void checkGameboardSize() {
String expectedResult = "56";
String currentResult = "" + gb.board.length;
assertThat(currentResult).describedAs("Dimensions").isEqualTo(expectedResult);
}
@Test
void checkGameboardFilled() {
int[] expectedGameboard = new int[56];
int [] givenGameboard = gb.board;
assertThat(givenGameboard).describedAs("Initial Gameboard").isEqualTo(expectedGameboard);
}
@ParameterizedTest
@MethodSource("FieldStream")
void checkGameboardFieldType(String testname, int Pos, int expectedResult) {
gb.initGameboard();
int currentType = gb.board[Pos];
assertThat(currentType).describedAs(testname).isEqualTo(expectedResult);
}
static Stream<Arguments> FieldStream () {
return Stream.of(
Arguments.of("Normal Path", 1, 0),
Arguments.of("Starting Field", 0, 1),
Arguments.of("Starting Field", 10, 1),
Arguments.of("Starting Field", 20, 1),
Arguments.of("Starting Field", 30, 1),
Arguments.of("Doorway Field", 9, 2),
Arguments.of("Doorway Field", 19, 2),
Arguments.of("Doorway Field", 29, 2),
Arguments.of("Doorway Field", 39, 2),
Arguments.of("House Field", 40, 3),
Arguments.of("House Field", 55, 3)
);
}
@ParameterizedTest
@MethodSource("FiguresOnBoardData")
void checkGetFiguresOnBoard (String testname, ArrayList<Integer> positions, String[] expectedResult) {
Iterator<Player> pIt = g.players.iterator();
Iterator<Integer> posIt = positions.iterator();
while(pIt.hasNext()) {
Player p = pIt.next();
for (Figure f : p.figures) {
f.setPosition(posIt.next());
}
}
String[] calculatedResult = g.gb.getFiguresOnBoard(g);
assertThat(calculatedResult).describedAs(testname).isEqualTo(expectedResult);
}
static Stream<Arguments> FiguresOnBoardData () {
return Stream.of(
Arguments.of(
"All Figures in Base",
new ArrayList<>(Arrays.asList(
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
)),
new String[] {
" "," "," "," "," "," "," "," "," "," ",
" "," "," "," "," "," "," "," "," "," ",
" "," "," "," "," "," "," "," "," "," ",
" "," "," "," "," "," "," "," "," "," ",
" "," "," "," "," "," "," "," "," "," ",
" "," "," "," "," "," ","\u001b[31;1m1\u001b[0m",
"\u001b[31;1m2\u001b[0m","\u001b[31;1m3\u001b[0m","\u001b[31;1m4\u001b[0m",
"\u001b[34;1m1\u001b[0m","\u001b[34;1m2\u001b[0m","\u001b[34;1m3\u001b[0m",
"\u001b[34;1m4\u001b[0m","\u001b[33;1m1\u001b[0m","\u001b[33;1m2\u001b[0m",
"\u001b[33;1m3\u001b[0m","\u001b[33;1m4\u001b[0m","\u001b[32;1m1\u001b[0m",
"\u001b[32;1m2\u001b[0m", "\u001b[32;1m3\u001b[0m","\u001b[32;1m4\u001b[0m"}
),
Arguments.of(
"Figures on Board",
new ArrayList<>(Arrays.asList(
0,1,3,5,-1,-1,-1,-1,10,12,16,-1,-1,-1,-1,-1
)),
new String[] {
"\u001b[31;1m1\u001b[0m","\u001b[31;1m2\u001b[0m"," ","\u001b[31;1m3\u001b[0m",
" ","\u001b[31;1m4\u001b[0m"," "," ",
" "," ","\u001b[33;1m1\u001b[0m"," ",
"\u001b[33;1m2\u001b[0m"," "," "," ",
"\u001b[33;1m3\u001b[0m"," "," "," ",
" "," "," "," ",
" "," "," "," ",
" "," "," "," ",
" "," "," "," ",
" "," "," "," ",
" "," "," "," ",
" "," "," "," ",
" "," "," "," ",
" "," "," "," ",
" "," "," "," ",
"\u001b[34;1m1\u001b[0m","\u001b[34;1m2\u001b[0m","\u001b[34;1m3\u001b[0m",
"\u001b[34;1m4\u001b[0m", " "," "," ","\u001b[33;1m4\u001b[0m",
"\u001b[32;1m1\u001b[0m","\u001b[32;1m2\u001b[0m","\u001b[32;1m3\u001b[0m",
"\u001b[32;1m4\u001b[0m"}
)
);
}
}