Browse Source

tictactoe: added test case to check if player 1 has won in column 1

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

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

@ -48,14 +48,14 @@ public class GameLogic {
// check columns
for (int i = 0; i < this.board.length; i++) {
for (int j = 0; j < this.board[0].length; j++) {
if(board[i][j] == player) countFields++;
if(board[i][j] == player) countFields++;
}
}
if(countFields == this.board.length) finished = true;
// check rows
for (int i = 0; i < this.board.length; i++) {
for (int j = 0; j < this.board[0].length; j++) {
for (int i = 0; i < this.board[0].length; i++) {
for (int j = 0; j < this.board.length; j++) {
if(board[j][i] == player) countFields++;
}
}

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

@ -138,6 +138,10 @@ class GameLogicTest {
{{'x', '-', '-'},
{'x', '-', '-'},
{'x', '-', '-'}}),
Arguments.of("check win in column 1 for player 1", 'x', true, new char[][]
{{'-', 'x', '-'},
{'-', 'x', '-'},
{'-', 'x', '-'}}),
Arguments.of("check win in column 0 for player 2", 'o', true, new char[][]
{{'o', '-', '-'},
{'o', '-', '-'},

Loading…
Cancel
Save