コード例 #1
0
        public void GetSize_InvalidIndexes_Exception()
        {
            var target = new CheckersBoard(10);

            var actual = Assert.Catch <ArgumentOutOfRangeException>(() =>
            {
                target.GetSquare(-1, 0);
            });

            Assert.AreEqual("columnIndex", actual.ParamName);

            actual = Assert.Catch <ArgumentOutOfRangeException>(() =>
            {
                target.GetSquare(10, 0);
            });
            Assert.AreEqual("columnIndex", actual.ParamName);

            actual = Assert.Catch <ArgumentOutOfRangeException>(() =>
            {
                target.GetSquare(0, -1);
            });
            Assert.AreEqual("rowIndex", actual.ParamName);

            actual = Assert.Catch <ArgumentOutOfRangeException>(() =>
            {
                target.GetSquare(0, 10);
            });
            Assert.AreEqual("rowIndex", actual.ParamName);
        }
コード例 #2
0
        public void CountCapturableByPiece_ThereIsEnemyPieceAroundButCannotBeCaptured_Zero()
        {
            var target = new CheckersBoard(8);
            var piece  = target.GetSquare(1, 2).CurrentPiece;

            Assert.IsTrue(target.MovePiece(new CheckersMove(piece, target.GetSquare(2, 3))));
            Assert.AreEqual(0, target.CountCapturableByPiece(piece));

            Assert.IsTrue(target.MovePiece(new CheckersMove(piece, target.GetSquare(3, 4))));
            Assert.AreEqual(0, target.CountCapturableByPiece(piece));

            Assert.IsFalse(target.MovePiece(new CheckersMove(piece, target.GetSquare(4, 5))));
            Assert.AreEqual(0, target.CountCapturableByPiece(piece));
        }
コード例 #3
0
        public void CountCapturableByPiece_ThereIsTwoEnemyPieceAround_CapturableCountTwo()
        {
            var target = new CheckersBoard(8);
            var piece  = target.GetSquare(3, 2).CurrentPiece;

            Assert.AreEqual(0, target.CountCapturableByPiece(piece));

            var enemyPiece1 = target.GetSquare(6, 5).CurrentPiece;

            Assert.AreEqual(0, target.CountCapturableByPiece(piece));
            Assert.AreEqual(0, target.CountCapturableByPiece(enemyPiece1));
            Assert.IsTrue(target.MovePiece(new CheckersMove(enemyPiece1, target.GetSquare(5, 4))));
            Assert.AreEqual(0, target.CountCapturableByPiece(piece));
            Assert.AreEqual(0, target.CountCapturableByPiece(enemyPiece1));
            Assert.IsTrue(target.MovePiece(new CheckersMove(enemyPiece1, target.GetSquare(4, 3))));
            Assert.AreEqual(1, target.CountCapturableByPiece(piece));
            Assert.AreEqual(0, target.CountCapturableByPiece(enemyPiece1));

            var enemyPiece2 = target.GetSquare(4, 5).CurrentPiece;

            Assert.AreEqual(1, target.CountCapturableByPiece(piece));
            Assert.AreEqual(0, target.CountCapturableByPiece(enemyPiece2));
            Assert.IsTrue(target.MovePiece(new CheckersMove(enemyPiece2, target.GetSquare(3, 4))));
            Assert.AreEqual(1, target.CountCapturableByPiece(piece));
            Assert.AreEqual(0, target.CountCapturableByPiece(enemyPiece2));
            Assert.IsTrue(target.MovePiece(new CheckersMove(enemyPiece2, target.GetSquare(2, 3))));
            Assert.AreEqual(2, target.CountCapturableByPiece(piece));
            Assert.AreEqual(0, target.CountCapturableByPiece(enemyPiece2));
            Assert.AreEqual(0, target.CountCapturableByPiece(enemyPiece1));
        }
コード例 #4
0
        public void CountCapturableByPiece_ThereIsEnemyPieceAround_CapturableCount()
        {
            var target = new CheckersBoard(8);
            var piece  = target.GetSquare(1, 2).CurrentPiece;

            Assert.IsTrue(target.MovePiece(new CheckersMove(piece, target.GetSquare(2, 3))));
            Assert.AreEqual(0, target.CountCapturableByPiece(piece));

            Assert.IsTrue(target.MovePiece(new CheckersMove(piece, target.GetSquare(3, 4))));
            Assert.AreEqual(0, target.CountCapturableByPiece(piece));

            var enemyPiece = target.GetSquare(4, 5).CurrentPiece;

            Assert.AreEqual(1, target.CountCapturableByPiece(enemyPiece));
            Assert.AreEqual(0, target.CountCapturableByPiece(piece));

            Assert.IsTrue(target.MovePiece(new CheckersMove(enemyPiece, target.GetSquare(2, 3))));
            Assert.AreEqual(0, target.CountCapturableByPiece(enemyPiece));

            var otherPiece = target.GetSquare(2, 1).CurrentPiece;

            Assert.IsTrue(target.MovePiece(new CheckersMove(otherPiece, target.GetSquare(1, 2))));
            Assert.AreEqual(1, target.CountCapturableByPiece(otherPiece));
            Assert.AreEqual(0, target.CountCapturableByPiece(enemyPiece));
        }
コード例 #5
0
        public void CountPieceChancesToBeCaptured_CanAndCannotCapture_CapturedCount()
        {
            var target = new CheckersBoard(8);
            var piece  = target.GetSquare(1, 2).CurrentPiece;

            Assert.IsTrue(target.MovePiece(new CheckersMove(piece, target.GetSquare(2, 3))));
            Assert.AreEqual(0, target.CountPieceChancesToBeCaptured(piece));

            Assert.IsTrue(target.MovePiece(new CheckersMove(piece, target.GetSquare(3, 4))));
            Assert.AreEqual(2, target.CountPieceChancesToBeCaptured(piece));

            var enemyPiece = target.GetSquare(4, 5).CurrentPiece;

            Assert.AreEqual(0, target.CountPieceChancesToBeCaptured(enemyPiece));

            Assert.IsFalse(target.MovePiece(new CheckersMove(piece, target.GetSquare(4, 5))));
            Assert.AreEqual(2, target.CountPieceChancesToBeCaptured(piece));
        }
コード例 #6
0
        public void GetSize_InvalidIndexes_Exception()
        {
            var target = new CheckersBoard(10);

            ExceptionAssert.IsThrowing(new ArgumentOutOfRangeException("columnIndex"), () =>
            {
                target.GetSquare(-1, 0);
            });

            ExceptionAssert.IsThrowing(new ArgumentOutOfRangeException("columnIndex"), () =>
            {
                target.GetSquare(10, 0);
            });

            ExceptionAssert.IsThrowing(new ArgumentOutOfRangeException("rowIndex"), () =>
            {
                target.GetSquare(0, -1);
            });

            ExceptionAssert.IsThrowing(new ArgumentOutOfRangeException("rowIndex"), () =>
            {
                target.GetSquare(0, 10);
            });
        }
コード例 #7
0
        public void Contructor_ValidSize_FreeAndNotPlayableSquaresOk()
        {
            var target = new CheckersBoard(8);

            Assert.AreEqual(8, target.Size);

            for (int c = 0; c < 8; c++)
            {
                for (int r = 0; r < 8; r++)
                {
                    var notPlayable = CheckersSquare.IsNotPlayableSquare(c, r);
                    var actual      = target.GetSquare(c, r).State;

                    if (notPlayable)
                    {
                        Assert.AreEqual(CheckersSquareState.NotPlayable, actual);
                    }
                    else
                    {
                        Assert.AreNotEqual(CheckersSquareState.NotPlayable, actual);
                    }
                }
            }
        }
コード例 #8
0
        public void Contructor_ValidSize_PlayerTwoPiecedPlaced()
        {
            var target = new CheckersBoard(8);

            Assert.AreEqual(8, target.Size);

            // first row.
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerTwo, target.GetSquare(0, 7).State);
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerTwo, target.GetSquare(2, 7).State);
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerTwo, target.GetSquare(4, 7).State);
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerTwo, target.GetSquare(6, 7).State);

            // second row
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerTwo, target.GetSquare(1, 6).State);
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerTwo, target.GetSquare(3, 6).State);
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerTwo, target.GetSquare(5, 6).State);
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerTwo, target.GetSquare(7, 6).State);

            // third row
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerTwo, target.GetSquare(0, 5).State);
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerTwo, target.GetSquare(2, 5).State);
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerTwo, target.GetSquare(4, 5).State);
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerTwo, target.GetSquare(6, 5).State);
        }
コード例 #9
0
        public void Contructor_ValidSize_PlayerOnePiecedPlaced()
        {
            var target = new CheckersBoard(8);

            Assert.AreEqual(8, target.Size);

            // First row.
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerOne, target.GetSquare(1, 0).State);
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerOne, target.GetSquare(3, 0).State);
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerOne, target.GetSquare(5, 0).State);
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerOne, target.GetSquare(7, 0).State);

            // second row
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerOne, target.GetSquare(0, 1).State);
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerOne, target.GetSquare(2, 1).State);
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerOne, target.GetSquare(4, 1).State);
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerOne, target.GetSquare(6, 1).State);

            // third row
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerOne, target.GetSquare(1, 2).State);
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerOne, target.GetSquare(3, 2).State);
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerOne, target.GetSquare(5, 2).State);
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerOne, target.GetSquare(7, 2).State);
        }