コード例 #1
0
        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);
        }
コード例 #2
0
 public void CheckIfTheAddFigureMethodThrowsCorrectlyNullReferenceExeption()
 {
     var board = new Board();
     var position = new Position(-1, -1);
     IFigure figure = new King(FigureSign.K);
     board.AddFigure(figure, position);
 }
コード例 #3
0
 public void CheckIfAddNullFigureThrowsException()
 {
     var board = new Board();
     var position = new Position(6, 6);
     IFigure figure = null;
     board.AddFigure(figure, position);
 }
コード例 #4
0
 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);
 }
コード例 #5
0
 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);
 }
コード例 #6
0
ファイル: BoardTests.cs プロジェクト: Fatme/King-Survival-4
 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));
 }
コード例 #7
0
 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");
 }
コード例 #8
0
ファイル: BoardTests.cs プロジェクト: Fatme/King-Survival-4
        public void CheckfAddFigureMethodThrowsWhenPositionIsNotValid()
        {
            var board = new Board();
            var position = new Position(9, 9);
            IFigure king = new KingFigure();

            board.AddFigure(king, position);
        }
コード例 #9
0
 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);
 }
コード例 #10
0
ファイル: BoardTests.cs プロジェクト: Fatme/King-Survival-4
        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));
        }
コード例 #11
0
ファイル: BoardTests.cs プロジェクト: Fatme/King-Survival-4
        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);
        }
コード例 #12
0
ファイル: BoardTests.cs プロジェクト: Fatme/King-Survival-4
        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));
        }
コード例 #13
0
        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));
        }
コード例 #14
0
        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));
        }
コード例 #15
0
        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);
        }
コード例 #16
0
        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));
        }
コード例 #17
0
        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);
        }
コード例 #18
0
ファイル: PlayerTests.cs プロジェクト: Fatme/King-Survival-4
        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");
        }
コード例 #19
0
ファイル: PlayerTests.cs プロジェクト: Fatme/King-Survival-4
        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");
        }
コード例 #20
0
        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);
        }
コード例 #21
0
ファイル: PlayerTests.cs プロジェクト: Fatme/King-Survival-4
        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");
        }
コード例 #22
0
        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);
        }
コード例 #23
0
        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);
        }
コード例 #24
0
        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);
        }
コード例 #25
0
        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);
        }
コード例 #26
0
ファイル: PlayerTests.cs プロジェクト: Fatme/King-Survival-4
        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);
        }
コード例 #27
0
ファイル: PlayerTests.cs プロジェクト: Fatme/King-Survival-4
        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);
        }
コード例 #28
0
        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));
        }
コード例 #29
0
        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);
        }
コード例 #30
0
ファイル: PlayerTests.cs プロジェクト: Fatme/King-Survival-4
        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");
        }