Browse Source

tictactoe: added test case to check diagonal left win for player 1

tictactoe
Malte Schellhardt 3 years ago
committed by Lorenz Hohmann
parent
commit
85f79d14bc
  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

@ -64,6 +64,13 @@ public class GameLogic {
countFields = 0;
}
// check diagonal left
for (int i = this.board.length - 1, j = this.board.length - 1; i >= 0 ; i--, j--) {
if (board[i][j] == player) countFields++;
}
if(countFields == this.board.length) return finished = true;
return finished;
}

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

@ -196,13 +196,17 @@ class GameLogicTest {
{'-', '-', '-'}}),
Arguments.of("check a draw for player 2", 'o', false, new char[][]
{{'o', 'o', 'x'},
{'o', 'o', 'x'},
{'o', 'x', 'x'},
{'x', 'x', 'o'}}),
Arguments.of("check a draw for player 1", 'x', false, new char[][]
{{'o', 'o', 'x'},
{'o', 'o', 'x'},
{'x', 'x', 'o'}})
);
{'x', 'x', 'o'}}),
Arguments.of("check diagonal left win for player 1", 'x', true, new char[][]
{{'x', 'o', 'x'},
{'x', 'x', 'o'},
{'o', 'o', 'x'}})
);
}
}
Loading…
Cancel
Save