Skip to content

Commit

Permalink
Feat: Add tests for checking terminal state horizontally and diagonally
Browse files Browse the repository at this point in the history
  • Loading branch information
JonBergland committed Feb 2, 2024
1 parent b593757 commit 007afdb
Showing 1 changed file with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.junit.jupiter.api.Test;

import board.master.model.Action;
import board.master.model.games.Board;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -115,8 +114,46 @@ void testIsTerminalAfterGameIsWon() {
connectFour = (ConnectFour) connectFour.result(connectFour.getActions().get(0));
boolean actual = connectFour.isTerminal();
assertEquals(expected, actual);
}

@Test
void testIsTerminalAfterGameIsWonHorizontally() {
boolean expected = true;
// Player 2 makes tower in column 0 and wins
connectFour = (ConnectFour) connectFour.result(connectFour.getActions().get(0));
connectFour = (ConnectFour) connectFour.result(connectFour.getActions().get(1));

connectFour = (ConnectFour) connectFour.result(connectFour.getActions().get(1));
connectFour = (ConnectFour) connectFour.result(connectFour.getActions().get(2));

connectFour = (ConnectFour) connectFour.result(connectFour.getActions().get(2));
connectFour = (ConnectFour) connectFour.result(connectFour.getActions().get(3));
connectFour = (ConnectFour) connectFour.result(connectFour.getActions().get(3));
connectFour = (ConnectFour) connectFour.result(connectFour.getActions().get(4));
boolean actual = connectFour.isTerminal();
assertEquals(expected, actual);
}

@Test
void testIsTerminalAfterGameIsWonDiagonally() {
boolean expected = true;
// Player 1 makes a diagonal and wins
connectFour = (ConnectFour) connectFour.result(connectFour.getActions().get(0));
connectFour = (ConnectFour) connectFour.result(connectFour.getActions().get(1));

connectFour = (ConnectFour) connectFour.result(connectFour.getActions().get(1));
connectFour = (ConnectFour) connectFour.result(connectFour.getActions().get(0));

connectFour = (ConnectFour) connectFour.result(connectFour.getActions().get(2));
connectFour = (ConnectFour) connectFour.result(connectFour.getActions().get(2));
connectFour = (ConnectFour) connectFour.result(connectFour.getActions().get(2));

connectFour = (ConnectFour) connectFour.result(connectFour.getActions().get(3));
connectFour = (ConnectFour) connectFour.result(connectFour.getActions().get(3));
connectFour = (ConnectFour) connectFour.result(connectFour.getActions().get(3));
connectFour = (ConnectFour) connectFour.result(connectFour.getActions().get(3));
boolean actual = connectFour.isTerminal();
assertEquals(expected, actual);
}

}
Expand Down

0 comments on commit 007afdb

Please sign in to comment.