64 lines
1.9 KiB
Java
64 lines
1.9 KiB
Java
|
import board.Board;
|
||
|
import events.FourInARow;
|
||
|
import events.IWinCondition;
|
||
|
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 FourInARowTest {
|
||
|
private final List<IWinCondition> conditions = new ArrayList<>();
|
||
|
|
||
|
@Test
|
||
|
public void horisontalTest() {
|
||
|
conditions.add(new FourInARow());
|
||
|
Board board = new Board(4, 1, new Empty(), conditions);
|
||
|
Token token = new Token(new Player("Naem", Color.RED));
|
||
|
assertTrue(board.drop(0, token));
|
||
|
assertFalse(board.won());
|
||
|
assertTrue(board.drop(1, token));
|
||
|
assertFalse(board.won());
|
||
|
assertTrue(board.drop(2, token));
|
||
|
assertFalse(board.won());
|
||
|
assertTrue(board.drop(3, token));
|
||
|
assertTrue(board.won());
|
||
|
}
|
||
|
|
||
|
@Test
|
||
|
public void verticalTest() {
|
||
|
conditions.add(new FourInARow());
|
||
|
Board board = new Board(1, 4, new Empty(), conditions);
|
||
|
Token token = new Token(new Player("Naem", Color.RED));
|
||
|
assertTrue(board.drop(0, token));
|
||
|
assertFalse(board.won());
|
||
|
assertTrue(board.drop(0, token));
|
||
|
assertFalse(board.won());
|
||
|
assertTrue(board.drop(0, token));
|
||
|
assertFalse(board.won());
|
||
|
assertTrue(board.drop(0, token));
|
||
|
assertTrue(board.won());
|
||
|
}
|
||
|
|
||
|
@Test
|
||
|
public void diagonalTest() {
|
||
|
conditions.add(new FourInARow());
|
||
|
Board board = new Board(10, 10, new Empty(), conditions);
|
||
|
Token token = new Token(new Player("Naem", Color.RED));
|
||
|
board.set(0, 0, token);
|
||
|
assertFalse(board.won());
|
||
|
board.set(1, 1, token);
|
||
|
assertFalse(board.won());
|
||
|
board.set(2, 2, token);
|
||
|
assertFalse(board.won());
|
||
|
board.set(3, 3, token);
|
||
|
assertTrue(board.won());
|
||
|
}
|
||
|
}
|