public void CheckIfTheMoveMethodChangeTheKurDirectionCorrectly() { List<IPlayer> players = new List<IPlayer>(); players.Add(new KingPlayer("king")); players.Add(new PawnPlayer("pawn")); IBoard board = new Board(); var firstPlayer = players[0]; IFigure king = new KingFigureFactory().CreateFigure(FigureSign.K); firstPlayer.AddFigure(king); board.AddFigure(king, new Position(Constants.initialKingRow, Constants.initialKingColumn)); var secondPlayer = players[1]; IFigure pawnA = new PawnFigureFactory().CreateFigure(FigureSign.A); IFigure pawnB = new PawnFigureFactory().CreateFigure(FigureSign.B); IFigure pawnC = new PawnFigureFactory().CreateFigure(FigureSign.C); IFigure pawnD = new PawnFigureFactory().CreateFigure(FigureSign.D); secondPlayer.AddFigure(pawnA); secondPlayer.AddFigure(pawnB); secondPlayer.AddFigure(pawnC); secondPlayer.AddFigure(pawnD); board.AddFigure(pawnA, new Position(Constants.pawnAInitialRow, Constants.pawnAInitialCol)); board.AddFigure(pawnB, new Position(Constants.pawnBInitialRow, Constants.pawnBInitialCol)); board.AddFigure(pawnC, new Position(Constants.pawnCInitialRow, Constants.pawnCInitialCol)); board.AddFigure(pawnD, new Position(Constants.pawnDInitialRow, Constants.pawnDInitialCol)); Move move = firstPlayer.Move("kur", board); var expectedRow = 6; Assert.AreEqual(move.To.Row, expectedRow); }
public void CheckIfTheAddFigureMethodThrowsCorrectlyNullReferenceExeption() { var board = new Board(); var position = new Position(-1, -1); IFigure figure = new King(FigureSign.K); board.AddFigure(figure, position); }
public void CheckIfAddNullFigureThrowsException() { var board = new Board(); var position = new Position(6, 6); IFigure figure = null; board.AddFigure(figure, position); }
public void CheckIfCheckFigureOnTheWayWorksProperlyWhenFigureIsOnTheWay() { IFigure king = new KingFigure("K"); var position = new Position(Constants.InitialKingRow, Constants.InitialKingColumn); var board = new Board(); board.AddFigure(king, position); Validator.CheckIfFigureOnTheWay(position, board); }
public void CheckIfTheAddFigureMethodThrowsCorrectlyIndexOutOfRangeException() { var board = new Board(); var position = new Position(9, 9); var figureSign = FigureSign.K; var figure = new King(figureSign); board.AddFigure(figure, position); }
public void CheckIfAFigureIsAddedCorrectlyToTheBoard() { var board = new Board(); var position = new Position(1, 1); var figure = new KingFigure(); board.AddFigure(figure, position); Assert.AreEqual(figure, board.GetFigureAtPosition(position)); }
public void CheckIfCheckFigureOnTheWayWorksProperlyWhenFigureIsOnTheWay() { var board = new Board(); var figure = new KingFigure(); var position = new Position(1, 1); board.AddFigure(figure, position); Validator.CheckIfFigureOnTheWay(position, board, "Figure on the way"); }
public void CheckfAddFigureMethodThrowsWhenPositionIsNotValid() { var board = new Board(); var position = new Position(9, 9); IFigure king = new KingFigure(); board.AddFigure(king, position); }
public void CheckIfCheckFigureOnTheWayWorksProperlyWhenNoFigureOnTheWay() { IFigure king = new KingFigure("K"); var board = new Board(); var position = new Position(1, 1); board.AddFigure(king, position); var expectedPosition = new Position(2, 2); Validator.CheckIfFigureOnTheWay(expectedPosition, board); }
public void CheckIfAddFigureWorksCorrectlyWithCorrectFigureAndCorrectPosition() { var board = new Board(); var position = new Position(3, 7); IFigure king = new KingFigure(); board.AddFigure(king, position); Assert.AreSame(king, board.GetFigureAtPosition(position)); }
public void CheckIfGetFigureAtPositionWorkCorrectly() { var board = new Board(); var figure = new KingFigure(); board.AddFigure(figure, new Position(1, 1)); var realFigure = board.GetFigureAtPosition(new Position(1, 1)); Assert.AreEqual(figure, realFigure); }
public void CheckIfGetFigureAtPositionReturnsTheCorrectFigure() { var board = new Board(); var position = new Position(1, 1); var figure = new KingFigure(); board.AddFigure(figure, position); Assert.AreEqual(figure, board.GetFigureAtPosition(position)); }
public void CheckIfRemoveFigureRemovesTheFigure() { var board = new Board(); var position = new Position(1, 1); var figureSign = FigureSign.K; var figure = new King(figureSign); board.AddFigure(figure, position); board.RemoveFigure(figure, position); Assert.AreNotEqual(figure, board.GetFigureAtPosition(position)); }
public void CheckIfAFigureIsAddedCorrectlyToTheBoard() { var position = new Position(1, 1); Mock<IFigure> mockedFigure = new Mock<IFigure>(); mockedFigure.Setup(r => r.DisplaySign).Returns("K"); var board = new Board(); board.AddFigure(mockedFigure.Object, position); Assert.AreSame(mockedFigure.Object, board.GetFigureAtPosition(position)); }
public void CheckIfAddFigureMethodThrowsWhenPositionIsNotValid() { var position = new Position(Constants.MaximumRowValueOnBoard + 2, Constants.MaximumRowValueOnBoard + 2); Mock<IFigure> mockedFigure = new Mock<IFigure>(); mockedFigure.Setup(r => r.DisplaySign).Returns("K"); var king = mockedFigure.Object; var board = new Board(); board.AddFigure(king, position); }
public void CheckIfAddFigureWorksCorrectlyWithCorrectFigureAndCorrectPosition() { var board = new Board(); var position = new Position(Constants.MaximumRowValueOnBoard / 2, Constants.MaximumColumnValueOnBoard / 2); Mock<IFigure> mockedFigure = new Mock<IFigure>(); mockedFigure.Setup(r => r.DisplaySign).Returns("K"); var king = mockedFigure.Object; board.AddFigure(king, position); Assert.AreSame(king, board.GetFigureAtPosition(position)); }
public void CheckIfKingLostWhenDoesntMeetTheConditions() { IFigure kingFigure = new KingFigure("K"); IPosition kingPosition = new Position(5, 7); IBoard board = new Board(8, 8); board.AddFigure(kingFigure, kingPosition); PawnFigure pawnA = new PawnFigure(Constants.FirstPawnDisplaySign); board.AddFigure(pawnA, new Position(4, 6)); PawnFigure pawnB = new PawnFigure(Constants.SecondPawnDisplaySign); board.AddFigure(pawnB, new Position(7, 3)); PawnFigure pawnC = new PawnFigure(Constants.ThirdPawnDisplaySign); board.AddFigure(pawnC, new Position(6, 4)); PawnFigure pawnD = new PawnFigure(Constants.FourthPawnDisplaySign); board.AddFigure(pawnD, new Position(7, 7)); var kingPlayer = new Player("king"); kingPlayer.AddFigure(new MoveableFigure(kingFigure)); var pawnPlayer = new Player("pawn"); pawnPlayer.AddFigure(new MoveableFigure(pawnA)); pawnPlayer.AddFigure(new MoveableFigure(pawnB)); pawnPlayer.AddFigure(new MoveableFigure(pawnC)); pawnPlayer.AddFigure(new MoveableFigure(pawnD)); var players = new List<IPlayer>() { kingPlayer, pawnPlayer }; var winningConditions = new WinningConditions(); var isKingWin = winningConditions.KingLost(players, board); Assert.AreEqual(isKingWin, false); }
public void CheckIfAnExceptionIsThrownWhenTheCommandIsThreeSymbolsLongButStillNotCorrect() { var player = new Player("Serafim"); var king = new KingFigure(); player.AddFigure(king); var board = new Board(); var position = new Position(Constants.InitialKingRow, Constants.InitialKingColumn); board.AddFigure(king, position); var commandFactory = new CommandFactory(); var commandContext = new CommandContext(new BoardMemory(), board, player); player.ExecuteCommand(commandContext, "aaa"); }
public void CheckIfAnExceptionIsThrownWhenTheCommandIsNotExactlyThreeSymbolsAndThePlayerIsPawn() { var player = new Player("Serafim"); var pawn = new PawnAFigure(); player.AddFigure(pawn); var board = new Board(); var position = new Position(Constants.InitialKingRow, Constants.InitialKingColumn); board.AddFigure(pawn, position); var commandFactory = new CommandFactory(); var commandContext = new CommandContext(new BoardMemory(), board, player); player.ExecuteCommand(commandContext, "aaaa"); }
public void ExecuteMoveCommandShouldWorkCorrectlyWhenTheCommandIsCorrect() { IFigure figure = new KingFigure("K"); IPosition position = new Position(7, 3); IBoard board = new Board(8, 8); board.AddFigure(figure, position); var figures = new Dictionary<string, IMoveableFigure>(); figures.Add(figure.DisplaySign, new MoveableFigure(figure)); var playerMock = new Mock<IPlayer>(); playerMock.SetupGet(x => x.Figures).Returns(figures); var memoryMock = new Mock<BoardMemory>(); Mock<ICommandContext> mockContext = new Mock<ICommandContext>(); mockContext.SetupGet(b => b.Board).Returns(board); mockContext.SetupGet(p => p.Player).Returns(playerMock.Object); mockContext.SetupGet(p => p.Memory).Returns(memoryMock.Object); var kingCommand = new KingUpRightCommand(); kingCommand.Execute(mockContext.Object); }
public void CheckIfTheMoveMethodSetNewPositionsCorrectlywithTheAdlCommand() { var player = new Player("Serafim"); var pawn = new PawnAFigure(); player.AddFigure(pawn); var board = new Board(); var position = new Position(0, 0); board.AddFigure(pawn, position); var commandFactory = new CommandFactory(); var commandContext = new CommandContext(new BoardMemory(), board, player); player.ExecuteCommand(commandContext, "adl"); }
public void CheckIfSaveMementoSavesBoardCorrectly() { var position = new Position(Constants.MaximumRowValueOnBoard / 2, Constants.MaximumColumnValueOnBoard / 2); Mock<IFigure> mockedFigure = new Mock<IFigure>(); mockedFigure.Setup(r => r.DisplaySign).Returns("K"); var board = new Board(); board.AddFigure(mockedFigure.Object, position); var actual = board.SaveMemento(); Assert.AreEqual(actual.Board.GetLength(1), board.NumberOfColumns); }
public void CheckIfGetFigurePositionRowWorksCorrectlyWhenCorrectInput() { var position = new Position(Constants.MaximumRowValueOnBoard / 2, Constants.MaximumColumnValueOnBoard / 2); Mock<IFigure> mockedFigure = new Mock<IFigure>(); mockedFigure.Setup(r => r.DisplaySign).Returns("K"); var figure = mockedFigure.Object; var board = new Board(); board.AddFigure(figure, position); var actualPosition = board.GetFigurePosition(figure); Assert.AreEqual(position.Row, actualPosition.Row); }
public void CheckIfKingWinWhenAllPawnAreOnTheLastRow() { IFigure kingFigure = new KingFigure("K"); IPosition kingPosition = new Position(1, 2); IBoard board = new Board(8, 8); board.AddFigure(kingFigure, kingPosition); PawnFigure pawnA = new PawnFigure(Constants.FirstPawnDisplaySign); board.AddFigure(pawnA, new Position(7, 1)); PawnFigure pawnB = new PawnFigure(Constants.SecondPawnDisplaySign); board.AddFigure(pawnB, new Position(7, 3)); PawnFigure pawnC = new PawnFigure(Constants.ThirdPawnDisplaySign); board.AddFigure(pawnC, new Position(7, 5)); PawnFigure pawnD = new PawnFigure(Constants.FourthPawnDisplaySign); board.AddFigure(pawnD, new Position(7, 7)); var kingPlayer = new Player("king"); kingPlayer.AddFigure(new MoveableFigure(kingFigure)); var pawnPlayer = new Player("pawn"); pawnPlayer.AddFigure(new MoveableFigure(pawnA)); pawnPlayer.AddFigure(new MoveableFigure(pawnB)); pawnPlayer.AddFigure(new MoveableFigure(pawnC)); pawnPlayer.AddFigure(new MoveableFigure(pawnD)); var players = new List<IPlayer>() { kingPlayer, pawnPlayer }; var winningConditions = new WinningConditions(); var isKingWin = winningConditions.KingWon(players, board); Assert.AreEqual(isKingWin, true); }
public void CheckIfTheMoveMethodThrowsCorrectlyWhenTheCommandIsNotExactlyThreeSymbols() { List<IPlayer> players = new List<IPlayer>(); players.Add(new PawnPlayer("pawn")); players.Add(new KingPlayer("king")); IBoard board = new Board(); var firstPlayer = players[0]; IFigure king = new KingFigureFactory().CreateFigure(FigureSign.K); firstPlayer.AddFigure(king); board.AddFigure(king, new Position(Constants.initialKingRow, Constants.initialKingColumn)); var secondPlayer = players[1]; IFigure pawnA = new PawnFigureFactory().CreateFigure(FigureSign.A); IFigure pawnB = new PawnFigureFactory().CreateFigure(FigureSign.B); IFigure pawnC = new PawnFigureFactory().CreateFigure(FigureSign.C); IFigure pawnD = new PawnFigureFactory().CreateFigure(FigureSign.D); secondPlayer.AddFigure(pawnA); secondPlayer.AddFigure(pawnB); secondPlayer.AddFigure(pawnC); secondPlayer.AddFigure(pawnD); board.AddFigure(pawnA, new Position(Constants.pawnAInitialRow, Constants.pawnAInitialCol)); board.AddFigure(pawnB, new Position(Constants.pawnBInitialRow, Constants.pawnBInitialCol)); board.AddFigure(pawnC, new Position(Constants.pawnCInitialRow, Constants.pawnCInitialCol)); board.AddFigure(pawnD, new Position(Constants.pawnDInitialRow, Constants.pawnDInitialCol)); secondPlayer.Move("shshs", board); }
public void CheckIfTheMoveMethodSetNewPositionsCorrectlywithTheAdrCommand() { var player = new Player("Serafim"); var pawn = new PawnAFigure(); player.AddFigure(pawn); var board = new Board(); var position = new Position(Constants.PawnAInitialRow, Constants.PawnAInitialCol); board.AddFigure(pawn, position); var commandFactory = new CommandFactory(); var commandContext = new CommandContext(new BoardMemory(), board, player); player.ExecuteCommand(commandContext, "adr"); var actualPosition = board.GetFigurePosition(pawn); var expectedPosition = new Position(1, 1); Assert.AreEqual(expectedPosition.Row, actualPosition.Row); Assert.AreEqual(expectedPosition.Col, actualPosition.Col); }
public void CheckIfTheMoveMethodSetNewPositionsCorrectlywithTheDdrCommand() { var player = new Player("Serafim"); var pawnA = new PawnAFigure(); player.AddFigure(pawnA); var pawnB = new PawnBFigure(); player.AddFigure(pawnB); var pawnC = new PawnCFigure(); player.AddFigure(pawnC); var pawnD = new PawnDFigure(); player.AddFigure(pawnD); var board = new Board(); var position = new Position(Constants.PawnDInitialRow, Constants.PawnDInitialCol); board.AddFigure(pawnA, position); board.AddFigure(pawnB, position); board.AddFigure(pawnC, position); board.AddFigure(pawnD, position); var commandFactory = new CommandFactory(); var playerCommand = commandFactory.CreatePlayerCommand("ddr"); var commandContext = new CommandContext(new BoardMemory(), board, player); player.ExecuteCommand(commandContext, "ddr"); var actualPosition = board.GetFigurePosition(pawnD); var expectedPosition = new Position(1, 7); Assert.AreEqual(expectedPosition.Row, actualPosition.Row); Assert.AreEqual(expectedPosition.Col, actualPosition.Col); }
public void CheckIfGetFigureAtPositionReturnsTheCorrectFigure() { var position = new Position(1, 1); Mock<IFigure> mockedFigure = new Mock<IFigure>(); mockedFigure.Setup(r => r.DisplaySign).Returns("K"); var figure = mockedFigure.Object; var board = new Board(); board.AddFigure(figure, position); Assert.AreSame(figure, board.GetFigureAtPosition(position)); }
public void CheckIfGetFigureAtPositionWorkCorrectly() { var position = new Position(Constants.MaximumRowValueOnBoard / 2, Constants.MaximumColumnValueOnBoard / 2); Mock<IFigure> mockedFigure = new Mock<IFigure>(); mockedFigure.Setup(r => r.DisplaySign).Returns("K"); var figure = mockedFigure.Object; var board = new Board(); board.AddFigure(figure, position); var realFigure = board.GetFigureAtPosition(position); Assert.AreEqual(figure, realFigure); }
public void CheckIfTheKdlDirectionThrowsWhenThePositionIsNotValid() { var player = new Player("Serafim"); var king = new KingFigure(); player.AddFigure(king); var board = new Board(); var position = new Position(Constants.InitialKingRow, Constants.InitialKingColumn); board.AddFigure(king, position); var commandContext = new CommandContext(new BoardMemory(), board, player); player.ExecuteCommand(commandContext, "kdl"); }