|
|
@ -1,8 +1,48 @@ |
|
|
|
package TicTacToe; |
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.*; |
|
|
|
|
|
|
|
import java.util.stream.Stream; |
|
|
|
|
|
|
|
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 Arcade64.Arcade64.Code; |
|
|
|
|
|
|
|
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].value = _field[i]; |
|
|
|
} |
|
|
|
ttt.player = _winner; |
|
|
|
int realWinner = ttt.checkPlayfield(); |
|
|
|
|
|
|
|
assertEquals(_winner, realWinner); |
|
|
|
} |
|
|
|
|
|
|
|
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) |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |