public void TestFromFenValid() { const string FEN_STRING = "pQ4N1/3k3R/1r4n1/KbBbBppP/8/8/q7/7n"; FENSerializer ser = new FENSerializer(); Board expected = new Board(null); Board actual; // Setup expected['8', 'A'] = new Pawn('b'); expected['8', 'B'] = new Queen('w'); expected['8', 'G'] = new Knight('w'); expected['7', 'D'] = new King('b'); expected['7', 'H'] = new Rook('w'); expected['6', 'B'] = new Rook('b'); expected['6', 'G'] = new Knight('b'); expected['5', 'A'] = new King('w'); expected['5', 'B'] = new Bishop('b'); expected['5', 'C'] = new Bishop('w'); expected['5', 'D'] = new Bishop('b'); expected['5', 'E'] = new Bishop('w'); expected['5', 'F'] = new Pawn('b'); expected['5', 'G'] = new Pawn('b'); expected['5', 'H'] = new Pawn('w'); expected['2', 'A'] = new Queen('b'); expected['1', 'H'] = new Knight('b'); // Act actual = ser.Deserialize(FEN_STRING); // Test for (int file = 0; file < Board.NUM_FILES; file++) { for (int row = 0; row < Board.NUM_ROWS; row++) { Piece expectedPiece = expected[row, file]; Piece actualPiece = actual[row, file]; bool areEqual = Piece.AreEqual(expectedPiece, actualPiece); Assert.IsTrue(areEqual); } } }
private void TestInvalidFen(string fen, string expectedErrMsg, int expectedIndex) { //Setup FENSerializer ser = new FENSerializer(); bool exceptionThrown = false; string actualErrMsg = String.Empty; int actualIndex = Int32.MinValue; try { // Act ser.Deserialize(fen); } catch (FENException e) { exceptionThrown = true; actualErrMsg = e.Message; actualIndex = e.ErrorIndex; } // Test Assert.IsTrue(exceptionThrown); Assert.AreEqual(expectedErrMsg, actualErrMsg); Assert.AreEqual(expectedIndex, actualIndex); Assert.AreEqual(exceptionThrown, !ser.IsValidSerialization(fen)); }