Browse Source

tictactoe: added test case to check if player 2 has won in column 2 with full board

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

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

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

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

@ -177,7 +177,11 @@ class GameLogicTest {
Arguments.of("check win in column 1 for player 2 with full board", 'o', true, new char[][]
{{'x', 'o', 'o'},
{'x', 'o', 'x'},
{'o', 'o', 'x'}})
{'o', 'o', 'x'}}),
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'}})
);
}

Loading…
Cancel
Save