Exemplo n.º 1
0
 protected override void ValidateRepeat(RomanCalculator connector)
 {
     if (connector.Contains($"{this.ToString()}{this.ToString()}"))
     {
         throw new Exception($"{this.ToString()} can nerver be repeated.");
     }
 }
Exemplo n.º 2
0
        protected virtual void ValidatePosition(RomanCalculator connector)
        {
            var afterNumbers = connector.After(this);

            if (!afterNumbers.IsNullOrEmpty() && !(afterNumbers.All(o => o.Value <= this.Value)))
            {
                throw new Exception($"{this.Symbol} can nerver be subtracted.");
            }
        }
Exemplo n.º 3
0
        protected override void ValidatePosition(RomanCalculator connector)
        {
            var beforeNumbers = connector.Before(this);

            if (!beforeNumbers.IsNullOrEmpty() && !(beforeNumbers.All(o => o.Value >= this.Value || new[] { SymbolEnum.C }.Contains(o.Symbol))))
            {
                throw new Exception($"{this.Symbol} can be only subtracted from {SymbolEnum.C}.");
            }
        }
Exemplo n.º 4
0
        protected override void ValidatePosition(RomanCalculator connector)
        {
            var afterNumbers = connector.After(this);

            if (!afterNumbers.IsNullOrEmpty() && !(afterNumbers.All(o => o.Value <= this.Value || new[] { SymbolEnum.D, SymbolEnum.M }.Contains(o.Symbol))))
            {
                throw new Exception($"{this.Symbol} can be only subtracted from {SymbolEnum.D} {SymbolEnum.M}.");
            }
        }
Exemplo n.º 5
0
        protected virtual void ValidateRepeat(RomanCalculator connector)
        {
            if (connector.Contains($"{this.ToString()}{this.ToString()}{this.ToString()}{this.ToString()}"))
            {
                throw new Exception($"{this.Symbol} can not be repeated over than 3 times in successive.");
            }

            MatchCollection matches = null;

            if (connector.Contains(new Regex("^[" + this.ToString() + "]{3}([.]){1}" + this.ToString() + "$"), out matches))
            {
                var midNumber = RomanNumber.Create(matches[0].Value);
                if (midNumber.Value >= this.Value)
                {
                    throw new Exception($"{midNumber.Symbol} must be less than {this.ToString()}'s value : {this.ToString()}.");
                }
            }
        }
Exemplo n.º 6
0
 public virtual void Validate(RomanCalculator connector)
 {
     this.ValidateRepeat(connector);
     this.ValidatePosition(connector);
 }