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

3 years ago
3 years ago
3 years ago
  1. package TicTacToe;
  2. import static org.junit.jupiter.api.Assertions.*;
  3. import java.util.stream.Stream;
  4. import org.junit.jupiter.params.ParameterizedTest;
  5. import org.junit.jupiter.params.provider.Arguments;
  6. import org.junit.jupiter.params.provider.MethodSource;
  7. class TicTacToeGameTest {
  8. @ParameterizedTest
  9. @MethodSource("testFieldsWinning")
  10. void testGameEndWin(int[] _field, int _winner) {
  11. TicTacToeGame ttt = new TicTacToeGame();
  12. for(int i = 0; i < ttt.field.length; i++) {
  13. ttt.field[i].playerID = _field[i];
  14. }
  15. ttt.playerID = _winner;
  16. int realWinner = ttt.checkPlayfield();
  17. assertEquals(_winner, realWinner);
  18. }
  19. @ParameterizedTest
  20. @MethodSource("testFieldsDraw")
  21. void testGameEndDraw(int[] _field) {
  22. TicTacToeGame ttt = new TicTacToeGame();
  23. for(int i = 0; i < ttt.field.length; i++) {
  24. ttt.field[i].playerID = _field[i];
  25. }
  26. int noWinner = ttt.checkPlayfield();
  27. assertEquals(0, noWinner);
  28. }
  29. private static Stream<Arguments> testFieldsWinning(){
  30. return Stream.of(
  31. Arguments.of(new int[]{ 1,2,1,
  32. 2,2,2,
  33. 1,2,1}, 2),
  34. Arguments.of(new int[]{ 2,1,2,
  35. 2,2,1,
  36. 1,1,1}, 1),
  37. Arguments.of(new int[]{ 1,1,2,
  38. 1,2,2,
  39. 1,2,1}, 1),
  40. Arguments.of(new int[]{ 2,1,1,
  41. 1,2,1,
  42. 1,1,2}, 2)
  43. );
  44. }
  45. private static Stream<Arguments> testFieldsDraw(){
  46. return Stream.of(
  47. Arguments.of(new int[]{ 2,1,1,
  48. 2,2,2,
  49. 1,2,1}),
  50. Arguments.of(new int[]{ 2,1,2,
  51. 2,2,1,
  52. 1,2,1}),
  53. Arguments.of(new int[]{ 2,1,2,
  54. 1,2,2,
  55. 1,2,1}),
  56. Arguments.of(new int[]{ 2,1,1,
  57. 1,2,2,
  58. 2,1,1})
  59. );
  60. }
  61. }