public void SetToken_PositionOccupied_ReturnsInvalidMove() { // arrange var board = new CrossesBoard(); board.SetToken(GameToken.Player1, new BoardPosition(2, 1)); // act var validMovePlayed = board.SetToken(GameToken.Player2, new BoardPosition(2, 1)); // assert Assert.That(validMovePlayed, Is.EqualTo(MoveResult.PositionTaken)); }
public void GetStatusFrom_Player2Wins_ReturnsPlayer2() { // arrange var checker = new GameChecker(); var board = new CrossesBoard(); board.SetToken(GameToken.Player2, new BoardPosition(0, 0)); board.SetToken(GameToken.Player2, new BoardPosition(0, 1)); board.SetToken(GameToken.Player2, new BoardPosition(0, 2)); // act var status = checker.GetStatusFrom(board); // assert Assert.That(status, Is.EqualTo(GameStatus.Player2Wins)); }
public void GetStatusFrom_PartiallyFilledBoard_ReturnsOngoing() { // arrange var checker = new GameChecker(); var board = new CrossesBoard(); board.SetToken(GameToken.Player1, new BoardPosition(0, 0)); board.SetToken(GameToken.Player2, new BoardPosition(1, 2)); board.SetToken(GameToken.Player1, new BoardPosition(2, 1)); // act var status = checker.GetStatusFrom(board); // assert Assert.That(status, Is.EqualTo(GameStatus.Ongoing)); }
public void GetStatusFrom_PlayerWinsDiagonal_ReturnsPlayer(int column1, int row1, int column2, int row2, int column3, int row3) { // arrange var checker = new GameChecker(); var board = new CrossesBoard(); board.SetToken(GameToken.Player1, new BoardPosition(column1, row1)); board.SetToken(GameToken.Player1, new BoardPosition(column2, row2)); board.SetToken(GameToken.Player1, new BoardPosition(column3, row3)); // act var status = checker.GetStatusFrom(board); // assert Assert.That(status, Is.EqualTo(GameStatus.Player1Wins)); }
public void GetStatusFrom_PlayerWinsRow_ReturnsPlayer(int row) { // arrange var checker = new GameChecker(); var board = new CrossesBoard(); board.SetToken(GameToken.Player1, new BoardPosition(0, row)); board.SetToken(GameToken.Player1, new BoardPosition(1, row)); board.SetToken(GameToken.Player1, new BoardPosition(2, row)); // act var status = checker.GetStatusFrom(board); // assert Assert.That(status, Is.EqualTo(GameStatus.Player1Wins)); }
public void SetToken_PositionEmpty_ReturnsValidMove() { // arrange var board = new CrossesBoard(); // act var validMovePlayed = board.SetToken(GameToken.Player1, new BoardPosition(0, 0)); // assert Assert.That(validMovePlayed, Is.EqualTo(MoveResult.ValidMove)); }
public void SetToken_PositionOffBoard_ReturnsInvalidMove() { // arrange var board = new CrossesBoard(); // act var validMovePlayed = board.SetToken(GameToken.Player1, new BoardPosition(3, -1)); // assert Assert.That(validMovePlayed, Is.EqualTo(MoveResult.OutsideBoardBoundary)); }
public void For_Player2_CreatesBoardsForPlayer() { // arrange var board = new CrossesBoard(); board.SetToken(GameToken.Player1, new BoardPosition(0, 0)); board.SetToken(GameToken.Player2, new BoardPosition(1, 2)); board.SetToken(GameToken.Player1, new BoardPosition(2, 1)); // act var playerBoard = board.For(GameToken.Player2); // assert Assert.That(playerBoard.TokenAt(new BoardPosition(0, 0)), Is.EqualTo(PlayerToken.Opponent)); Assert.That(playerBoard.TokenAt(new BoardPosition(1, 2)), Is.EqualTo(PlayerToken.Me)); Assert.That(playerBoard.TokenAt(new BoardPosition(2, 1)), Is.EqualTo(PlayerToken.Opponent)); Assert.That(playerBoard.TokenAt(new BoardPosition(0, 1)), Is.EqualTo(PlayerToken.None)); Assert.That(playerBoard.TokenAt(new BoardPosition(1, 0)), Is.EqualTo(PlayerToken.None)); Assert.That(playerBoard.TokenAt(new BoardPosition(2, 0)), Is.EqualTo(PlayerToken.None)); Assert.That(playerBoard.TokenAt(new BoardPosition(0, 2)), Is.EqualTo(PlayerToken.None)); Assert.That(playerBoard.TokenAt(new BoardPosition(1, 1)), Is.EqualTo(PlayerToken.None)); Assert.That(playerBoard.TokenAt(new BoardPosition(2, 2)), Is.EqualTo(PlayerToken.None)); }
public void Copy_Called_CreatesCopyOfBoard() { // arrange var board = new CrossesBoard(); board.SetToken(GameToken.Player1, new BoardPosition(0, 0)); board.SetToken(GameToken.Player2, new BoardPosition(1, 2)); board.SetToken(GameToken.Player1, new BoardPosition(2, 1)); // act var newBoard = board.Copy(); // assert Assert.That(newBoard, Is.Not.EqualTo(board)); Assert.That(newBoard.TokenAt(new BoardPosition(0, 0)), Is.EqualTo(board.TokenAt(new BoardPosition(0, 0)))); Assert.That(newBoard.TokenAt(new BoardPosition(1, 0)), Is.EqualTo(board.TokenAt(new BoardPosition(1, 0)))); Assert.That(newBoard.TokenAt(new BoardPosition(2, 0)), Is.EqualTo(board.TokenAt(new BoardPosition(2, 0)))); Assert.That(newBoard.TokenAt(new BoardPosition(0, 1)), Is.EqualTo(board.TokenAt(new BoardPosition(0, 1)))); Assert.That(newBoard.TokenAt(new BoardPosition(1, 1)), Is.EqualTo(board.TokenAt(new BoardPosition(1, 1)))); Assert.That(newBoard.TokenAt(new BoardPosition(2, 1)), Is.EqualTo(board.TokenAt(new BoardPosition(2, 1)))); Assert.That(newBoard.TokenAt(new BoardPosition(0, 2)), Is.EqualTo(board.TokenAt(new BoardPosition(0, 2)))); Assert.That(newBoard.TokenAt(new BoardPosition(1, 2)), Is.EqualTo(board.TokenAt(new BoardPosition(1, 2)))); Assert.That(newBoard.TokenAt(new BoardPosition(2, 2)), Is.EqualTo(board.TokenAt(new BoardPosition(2, 2)))); }
public void ToString_BoardWithMixedTokens_DrawsBoard() { // arrange var board = new CrossesBoard(); board.SetToken(GameToken.Player1, new BoardPosition(0, 0)); board.SetToken(GameToken.Player2, new BoardPosition(1, 2)); board.SetToken(GameToken.Player1, new BoardPosition(2, 1)); // act var output = BoardVisualiser.ToString(board); // assert Assert.That(output, Is.EqualTo(@" 0 1 2 ┌───┬───┬───┐ 0 │ X │ │ │ ├───┼───┼───┤ 1 │ │ │ X │ ├───┼───┼───┤ 2 │ │ O │ │ └───┴───┴───┘ ")); }
public void GetStatusFrom_FilledBoardNoWinner_ReturnsDraw() { // arrange var checker = new GameChecker(); var board = new CrossesBoard(); board.SetToken(GameToken.Player1, new BoardPosition(0, 0)); board.SetToken(GameToken.Player1, new BoardPosition(0, 1)); board.SetToken(GameToken.Player1, new BoardPosition(1, 2)); board.SetToken(GameToken.Player1, new BoardPosition(2, 0)); board.SetToken(GameToken.Player1, new BoardPosition(2, 1)); board.SetToken(GameToken.Player2, new BoardPosition(0, 2)); board.SetToken(GameToken.Player2, new BoardPosition(1, 0)); board.SetToken(GameToken.Player2, new BoardPosition(1, 1)); board.SetToken(GameToken.Player2, new BoardPosition(2, 2)); // act var status = checker.GetStatusFrom(board); // assert Assert.That(status, Is.EqualTo(GameStatus.Draw)); }