Exemple #1
0
            public void BasicTests()
            {
                BoardSquareChecker callback = (int file, int rank, bool expected) =>
                {
                    Trace.WriteLine(String.Format("Verifying BoardSquare[{0}:{1}] is {2}", file, rank, expected));
                    Assert.IsTrue(BoardSquare.IsValid(file, rank) == expected);
                };

                // ChessBoard.BoardSquare.IsValid is a static helper that takes
                // ints rather than PieceFiles as those objects must be valid.
                // IsValid helps with offsets to locations that may be invalid
                // (and thus you can't construct a PieceFile)
                // There are only 64 valid squares, check them all
                for (int fileIndex = 1; fileIndex <= 8; fileIndex++)
                {
                    for (int rankIndex = 1; rankIndex <= 8; rankIndex++)
                    {
                        callback(fileIndex, rankIndex, true);
                    }
                }

                // Now try some invalid ones
                callback(0, 0, false);
                callback(-1, -20, false);
                callback(-1, 8, false);
                callback(1, 9, false);
                callback(9, 8, false);
            }