public void Move_Should_ThrowException_When_ToIsNull() { // Arrange SUT board = new SUT(); // Act board.Move(new ChessSquare("e2"), null); }
public void Move_Should_ThrowException_When_FromIsNull() { // Arrange SUT board = new SUT(); // Act board.Move(null, new ChessSquare("e4")); }
public void Move_Should_ThrowException_When_MoveIsInvalid() { // Arrange SUT board = new SUT(); // Act ChessMove invalidMove = board.GetMoveValidity(new ChessSquare("e2"), new ChessSquare("e5")); board.Move(invalidMove); }
public void Move_Should_ResetEnPassant(string fen, string nextMove) { // Arrange var board = new SUT(fen); // Act board.Move(board.SANToMove(nextMove)); fen = board.GetFEN(); // Assert Assert.AreEqual("-", new FEN(fen).EnPassant); }
public void GetMoveHistory_Should_Return_AllTheMoves() { // Arrange SUT board = new SUT(); List <ChessMove> playedMoves = new List <ChessMove>(); ChessMove[] moveHistory; int moveCount = 0; List <ChessMove> legalMoves = board.GetLegalMoves(); System.Random randomizer = new System.Random(System.DateTime.Now.Second); // Act do { var moveIndex = randomizer.Next(0, legalMoves.Count); board.Move(legalMoves[moveIndex]); playedMoves.Add(legalMoves[moveIndex]); legalMoves = board.GetLegalMoves(); moveCount++; } while (legalMoves.Count > 0 && moveCount < 30); moveHistory = board.GetMoveHistory(); // Assert Assert.IsNotNull(moveHistory); Assert.AreEqual(playedMoves.Count, moveHistory.Length); for (int i = 0; i < moveHistory.Length; i++) { Assert.AreEqual(moveHistory[i].CapturedPiece, playedMoves[i].CapturedPiece); Assert.IsTrue(moveHistory[i].From == playedMoves[i].From); Assert.IsTrue(moveHistory[i].To == playedMoves[i].To); Assert.AreEqual(moveHistory[i].IsValid, playedMoves[i].IsValid); Assert.AreEqual(moveHistory[i].MoveKind, playedMoves[i].MoveKind); Assert.AreEqual(moveHistory[i].MovingPiece.Kind, playedMoves[i].MovingPiece.Kind); Assert.AreEqual(moveHistory[i].PromotedTo, playedMoves[i].PromotedTo); Assert.AreEqual(moveHistory[i].IllegalReason, playedMoves[i].IllegalReason); } }