Connect-Four/test/TicTacToeTest.java

83 lines
2.6 KiB
Java
Raw Normal View History

2018-04-16 13:40:41 +02:00
import board.Board;
import events.IWinCondition;
import events.ThreeInARow;
import objects.Empty;
import objects.Player;
import objects.Token;
import org.junit.Test;
import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class TicTacToeTest {
private final List<IWinCondition> conditions = new ArrayList<>();
@Test
public void horisontalTest() {
conditions.add(new ThreeInARow());
Board board = new Board(3, 3, new Empty(), conditions);
Token token = new Token(new Player("Naem", Color.WHITE));
board.set(0, 0, token);
board.set(1, 0, token);
board.set(2, 0, token);
assertTrue(board.won());
board = new Board(3, 3, new Empty(), conditions);
board.set(0, 1, token);
board.set(1, 1, token);
board.set(2, 1, token);
assertTrue(board.won());
board = new Board(3, 3, new Empty(), conditions);
board.set(0, 2, token);
board.set(1, 2, token);
board.set(2, 2, token);
assertTrue(board.won());
}
@Test
public void verticalTest() {
conditions.add(new ThreeInARow());
Board board = new Board(3, 3, new Empty(), conditions);
Token token = new Token(new Player("Naem", Color.WHITE));
board.set(0, 0, token);
assertFalse(board.won());
board.set(0, 1, token);
assertFalse(board.won());
board.set(0, 2, token);
assertTrue(board.won());
board = new Board(3, 3, new Empty(), conditions);
board.set(1, 0, token);
board.set(1, 1, token);
board.set(1, 2, token);
assertTrue(board.won());
board = new Board(3, 3, new Empty(), conditions);
board.set(2, 0, token);
board.set(2, 1, token);
board.set(2, 2, token);
assertTrue(board.won());
}
@Test
public void diagonalTest() {
conditions.add(new ThreeInARow());
Board board = new Board(3, 3, new Empty(), conditions);
Token token = new Token(new Player("Naem", Color.WHITE));
board.set(0, 0, token);
assertFalse(board.won());
board.set(1, 1, token);
assertFalse(board.won());
board.set(2, 2, token);
assertTrue(board.won());
board = new Board(3, 3, new Empty(), conditions);
board.set(0, 2, token);
assertFalse(board.won());
board.set(1, 1, token);
assertFalse(board.won());
board.set(2, 0, token);
assertTrue(board.won());
}
}