Browse Source

tictactoe: added test case to check if player 1 has won in row 0 with full board

tictactoe
Malte Schellhardt 3 years ago
committed by Lorenz Hohmann
parent
commit
eec2f540a5
  1. 4
      src/main/java/de/tims/tictactoe/GameLogic.java
  2. 6
      src/test/java/de/tims/tictactoe/GameLogicTest.java

4
src/main/java/de/tims/tictactoe/GameLogic.java

@ -48,7 +48,6 @@ public class GameLogic {
// check columns
for (int i = 0; i < this.board.length; i++) {
for (int j = 0; j < this.board[0].length; j++) {
System.out.println(j + ", " + i);
if(board[j][i] == player) countFields++;
}
if(countFields == this.board.length) return finished = true;
@ -61,8 +60,9 @@ public class GameLogic {
for (int j = 0; j < this.board.length; j++) {
if(board[i][j] == player) countFields++;
}
if(countFields == this.board.length) return finished = true;
countFields = 0;
}
if(countFields == this.board.length) finished = true;
return finished;
}

6
src/test/java/de/tims/tictactoe/GameLogicTest.java

@ -181,7 +181,11 @@ class GameLogicTest {
Arguments.of("check win in column 2 for player 2 with full board", 'o', true, new char[][]
{{'x', 'o', 'o'},
{'x', 'x', 'o'},
{'o', 'o', 'o'}})
{'o', 'o', 'o'}}),
Arguments.of("check win in row 0 for player 1 with full board", 'x', true, new char[][]
{{'x', 'x', 'x'},
{'x', 'o', 'o'},
{'o', 'o', 'x'}})
);
}

Loading…
Cancel
Save