Example #1
0
        public void ValidateMove_PawnDiagonalCaptureLeftOfBlackPiece_ReturnsValid()
        {
            var from = "C2";
            var to = "B3";

            var chessBoardStub = MockRepository.GenerateStub<ChessBoard>();
            chessBoardStub.Stub(stub => stub.GetSquare(to)).Return(SquareWithBlackKnight);

            var whitePawn = new Pawn(Colour.White);
            ExceptionReasonDetail exceptionReasonDetail;
            MoveResult moveResult = whitePawn.ValidateMove(chessBoardStub, from, to, out exceptionReasonDetail);

            Assert.That(moveResult, Is.EqualTo(MoveResult.Valid));
            Assert.That(exceptionReasonDetail, Is.EqualTo(ExceptionReasonDetail.None));
        }
Example #2
0
        public void ValidateMove_PawnDiagonalCaptureLeftOfNothing_ReturnsIllegal()
        {
            var from = "C2";
            var to = "B3";

            var chessBoardStub = MockRepository.GenerateStub<ChessBoard>();
            chessBoardStub.Stub(stub => stub.GetSquare(to)).Return(EmptySquare);

            var whitePawn = new Pawn(Colour.White);

            ExceptionReasonDetail exceptionReasonDetail;
            MoveResult moveResult = whitePawn.ValidateMove(chessBoardStub, from, to, out exceptionReasonDetail);

            Assert.That(moveResult, Is.EqualTo(MoveResult.Illegal));
            Assert.That(exceptionReasonDetail, Is.EqualTo(ExceptionReasonDetail.PawnCannotMoveDiagonallyUnlessCapturing));
        }
Example #3
0
        public void ValidateMove_PawnBackward1Square_ReturnsIllegal()
        {
            var from = "C3";
            var to = "C2";

            var chessBoardStub = MockRepository.GenerateStub<ChessBoard>();
            chessBoardStub.Stub(stub => stub.GetSquare(to)).Return(EmptySquare);

            var whitePawn = new Pawn(Colour.White);

            ExceptionReasonDetail exceptionReasonDetail;
            MoveResult moveResult = whitePawn.ValidateMove(chessBoardStub, from, to, out exceptionReasonDetail);

            Assert.That(moveResult, Is.EqualTo(MoveResult.Illegal));
            Assert.That(exceptionReasonDetail, Is.EqualTo(ExceptionReasonDetail.None));
        }
Example #4
0
        public void ValidateMove_PawnForward2SquaresRound1OnHomeRank_ReturnsValid()
        {
            var from = "C2";
            var inbetween = "C3";
            var to = "C4";

            var chessBoardStub = MockRepository.GenerateStub<ChessBoard>();
            chessBoardStub.Round = 1;
            chessBoardStub.Stub(stub => stub.GetSquare(inbetween)).Return(EmptySquare);
            chessBoardStub.Stub(stub => stub.GetSquare(to)).Return(EmptySquare);

            var whitePawn = new Pawn(Colour.White);

            ExceptionReasonDetail exceptionReasonDetail;
            MoveResult moveResult = whitePawn.ValidateMove(chessBoardStub, from, to, out exceptionReasonDetail);

            Assert.That(moveResult, Is.EqualTo(MoveResult.Valid));
            Assert.That(exceptionReasonDetail, Is.EqualTo(ExceptionReasonDetail.None));
        }
Example #5
0
        public void ValidateMove_PawnForward2SquaresNotRound1_ReturnsIllegal()
        {
            var from = "C2";
            var inbetween = "C3";
            var to = "C4";

            var chessBoardStub = MockRepository.GenerateStub<ChessBoard>();
            chessBoardStub.Round = 2;
            chessBoardStub.Stub(stub => stub.GetSquare(inbetween)).Return(EmptySquare);
            chessBoardStub.Stub(stub => stub.GetSquare(to)).Return(EmptySquare);

            var whitePawn = new Pawn(Colour.White);

            ExceptionReasonDetail exceptionReasonDetail;
            MoveResult moveResult = whitePawn.ValidateMove(chessBoardStub, from, to, out exceptionReasonDetail);

            Assert.That(moveResult, Is.EqualTo(MoveResult.Illegal));
            Assert.That(exceptionReasonDetail, Is.EqualTo(ExceptionReasonDetail.PawnCannotMoveTwoSpacesAtThisTime));
        }
Example #6
0
        public void ValidateMove_PawnForward1SquareBlocked_ReturnsCollision()
        {
            var from = "C3";
            var to = "C4";

            var chessBoardStub = MockRepository.GenerateStub<ChessBoard>();
            chessBoardStub.Stub(stub => stub.GetSquare(to)).Return(SquareWithBlackKnight);

            var whitePawn = new Pawn(Colour.White);

            ExceptionReasonDetail exceptionReasonDetail;
            MoveResult moveResult = whitePawn.ValidateMove(chessBoardStub, from, to, out exceptionReasonDetail);

            Assert.That(moveResult, Is.EqualTo(MoveResult.Collision));
            Assert.That(exceptionReasonDetail, Is.EqualTo(ExceptionReasonDetail.None));
        }