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 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 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}) ); } }