Nur die besten Spiele ;3
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.

77 lines
1.7 KiB

package TicTacToe;
import static org.junit.jupiter.api.Assertions.*;
import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
class TicTacToeGameTest {
@ParameterizedTest
@MethodSource("testFieldsWinning")
void testGameEndWin(int[] _field, int _winner) {
TicTacToeGame ttt = new TicTacToeGame();
for(int i = 0; i < ttt.field.length; i++) {
ttt.field[i].playerID = _field[i];
}
ttt.playerID = _winner;
int realWinner = ttt.checkPlayfield();
assertEquals(_winner, realWinner);
}
@ParameterizedTest
@MethodSource("testFieldsDraw")
void testGameEndDraw(int[] _field) {
TicTacToeGame ttt = new TicTacToeGame();
for(int i = 0; i < ttt.field.length; i++) {
ttt.field[i].playerID = _field[i];
}
int noWinner = ttt.checkPlayfield();
assertEquals(0, noWinner);
}
private static Stream<Arguments> testFieldsWinning(){
return Stream.of(
Arguments.of(new int[]{ 1,2,1,
2,2,2,
1,2,1}, 2),
Arguments.of(new int[]{ 2,1,2,
2,2,1,
1,1,1}, 1),
Arguments.of(new int[]{ 1,1,2,
1,2,2,
1,2,1}, 1),
Arguments.of(new int[]{ 2,1,1,
1,2,1,
1,1,2}, 2)
);
}
private static Stream<Arguments> testFieldsDraw(){
return Stream.of(
Arguments.of(new int[]{ 2,1,1,
2,2,2,
1,2,1}),
Arguments.of(new int[]{ 2,1,2,
2,2,1,
1,2,1}),
Arguments.of(new int[]{ 2,1,2,
1,2,2,
1,2,1}),
Arguments.of(new int[]{ 2,1,1,
1,2,2,
2,1,1})
);
}
}