Browse Source

tictactoe: fixed previous checkForWin test cases

tictactoe
Malte Schellhardt 2 years ago
committed by Lorenz Hohmann
parent
commit
f81871b180
  1. 7
      src/main/java/de/tims/tictactoe/GameLogic.java
  2. 10
      src/test/java/de/tims/tictactoe/GameLogicTest.java

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

@ -54,10 +54,9 @@ public class GameLogic {
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;
for (int i = 0; i < this.board.length; i++) {
for (int j = 0; j < this.board[0].length; j++) {
if(board[j][i] == player) countFields++;
}
}
if(countFields == this.board.length) finished = true;

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

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

Loading…
Cancel
Save