Browse Source

tictactoe: added test case to check if player 2 has won in row 0

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

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

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

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

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

Loading…
Cancel
Save