Beispiel #1
0
        public static void ValidateEnPassant(string fen, FENError expectedError)
        {
            var validator = new Core.Validation.Validators.FENValidation.Rules.EnPassantRule();
            var actual    = validator.Validate(fen);

            Assert.AreEqual(expectedError, actual);
        }
Beispiel #2
0
        public static void ValidateActiveColor(string fen, FENError expectedError)
        {
            var validator = new ActiveColorRule();
            var actual    = validator.Validate(fen);

            Assert.AreEqual(expectedError, actual);
        }
Beispiel #3
0
        public static void ValidateCastlingAvailability(string fen, FENError expectedError)
        {
            var validator = new Core.Validation.Validators.FENValidation.Rules.CastlingAvailabilityRule();
            var actual    = validator.Validate(fen);

            Assert.AreEqual(expectedError, actual);
        }
Beispiel #4
0
        public static void ValidateHalfmoveClock(string fen, FENError expectedError)
        {
            var validator = new Core.Validation.Validators.FENValidation.Rules.HalfmoveClockRule();
            var actual    = validator.Validate(fen);

            Assert.AreEqual(expectedError, actual);
        }
Beispiel #5
0
        private static string FormatFENError(string fen, FENError e)
        {
            if (e == FENError.None)
            {
                return("");
            }
            var sb = new StringBuilder($"PremoveFEN Errors Found ({fen}):\r\n");

            foreach (var error in e.GetFlags().Select(x => new { error = x, message = GetFormattedMessage(x) }))
            {
                sb.AppendLine(error.message);
            }

            return(sb.ToString());
        }
Beispiel #6
0
        private void AssertExceptionValueSet(FENError error)
        {
            _fenRuleMock = new Mock <IFENRule>();
            var mockedMethod = _fenRuleMock
                               .Setup(x => x.Validate(It.IsAny <string>()))
                               .Returns(error);

            _fenValidator = new FENValidator(_fenRuleMock.Object);
            try
            {
                _fenValidator.Validate(BoardConstants.FenStartingPosition);
            }
            catch (System.Exception exc)
            {
                var fenException = (FENException)exc;
                Assert.AreEqual(error, fenException.FENError, $"Expected fenException Error to have been {error}");
                throw;
            }
        }
Beispiel #7
0
        private static FENError ValidateEnPassantSquare(string v)
        {
            if (v == "-")
            {
                return(FENError.None);
            }
            const FENError error = FENError.InvalidEnPassantSquare;
            var            valid = true;

            if (v.Length != 2)
            {
                return(error);
            }
            valid &= char.IsLetter(v[0]) && char.IsLower(v[0]) && v[0] >= 'a' && v[0] <= 'h';
            valid &= ushort.TryParse(v[1].ToString(), out var rank);
            if (valid)
            {
                valid &= rank >= 1 && rank <= 8;
            }

            return(valid ? FENError.None : error);
        }
Beispiel #8
0
 private static string GetFormattedMessage(FENError e)
 {
     return("* " + e.AsString(EnumFormat.Description));
 }
Beispiel #9
0
 public FENException(string fen, FENError fenError, Exception innerException)
     : base(FormatFENError(fen, fenError), innerException)
 {
     FENError = fenError;
 }
Beispiel #10
0
 public FENException(string fen, FENError fenError)
     : base(FormatFENError(fen, fenError))
 {
     FENError = fenError;
 }
Beispiel #11
0
 public void FENValidatorTest_ShouldThrowExceptionWhenInvalidFenStringDetected(FENError testCase)
 {
     _fenValidator = new FENValidator(_fenRuleMock.Object);
     Assert.Throws(typeof(FENException), () => AssertExceptionValueSet(testCase));
 }