示例#1
0
        public RomanAbacus(int thousandThreshold)
        {
            if (thousandThreshold < 1)
            {
                throw new ArgumentOutOfRangeException("thousandThreshold", "'M' threshold must be a positive integer");
            }

            this.thousandThreshold = thousandThreshold;

            RomanRode rodeForThousandSymbol    = new RomanRode(symbolOneThousand.ToString(CultureInfo.InvariantCulture), this.thousandThreshold, null);
            RomanRode rodeForFiveHundredSymbol = new RomanRode(symbolFiveHundred.ToString(CultureInfo.InvariantCulture), 2, rodeForThousandSymbol);
            RomanRode rodeForOneHundredSymbol  = new RomanRode(symbolOneHundred.ToString(CultureInfo.InvariantCulture), 5, rodeForFiveHundredSymbol);
            RomanRode rodeForFiftySymbol       = new RomanRode(symbolFifty.ToString(CultureInfo.InvariantCulture), 2, rodeForOneHundredSymbol);
            RomanRode rodeForTenSymbol         = new RomanRode(symbolTen.ToString(CultureInfo.InvariantCulture), 5, rodeForFiftySymbol);
            RomanRode rodeForFiveSymbol        = new RomanRode(symbolFive.ToString(CultureInfo.InvariantCulture), 2, rodeForTenSymbol);
            RomanRode rodeForOneSymbol         = new RomanRode(symbolOne.ToString(CultureInfo.InvariantCulture), 5, rodeForFiveSymbol);

            rodes = new List <RomanRode>
            {
                rodeForOneSymbol,
                rodeForFiveSymbol,
                rodeForTenSymbol,
                rodeForFiftySymbol,
                rodeForOneHundredSymbol,
                rodeForFiveHundredSymbol,
                rodeForThousandSymbol
            };
        }
示例#2
0
        protected override string GetResult()
        {
            StringBuilder sb = new StringBuilder();

            for (int rodeIndex = rodes.Count - 1; rodeIndex >= 0; rodeIndex--)
            {
                RomanRode romanRode = rodes[rodeIndex];

                for (int index = 0; index < romanRode.BeadsCount; index++)
                {
                    sb.Append(romanRode.Symbol);
                }
            }

            string result = sb.ToString();

            result = result.Replace("DD", "M");
            result = result.Replace("CCCCC", "D");
            result = result.Replace("CCCC", "CD");
            result = result.Replace("LL", "C");
            result = result.Replace("XXXXX", "L");
            result = result.Replace("XXXX", "XL");
            result = result.Replace("VV", "X");
            result = result.Replace("IIIII", "V");
            result = result.Replace("IIII", "IV");
            return(result);
        }
        public RomanAbacus(int thousandThreshold)
        {
            if (thousandThreshold < 1)
            {
                throw new ArgumentOutOfRangeException("thousandThreshold", "'M' threshold must be a positive integer");
            }

            this.thousandThreshold = thousandThreshold;

            RomanRode rodeForThousandSymbol = new RomanRode(symbolOneThousand.ToString(CultureInfo.InvariantCulture), this.thousandThreshold, null);
            RomanRode rodeForFiveHundredSymbol = new RomanRode(symbolFiveHundred.ToString(CultureInfo.InvariantCulture), 2, rodeForThousandSymbol);
            RomanRode rodeForOneHundredSymbol = new RomanRode(symbolOneHundred.ToString(CultureInfo.InvariantCulture), 5, rodeForFiveHundredSymbol);
            RomanRode rodeForFiftySymbol = new RomanRode(symbolFifty.ToString(CultureInfo.InvariantCulture), 2, rodeForOneHundredSymbol);
            RomanRode rodeForTenSymbol = new RomanRode(symbolTen.ToString(CultureInfo.InvariantCulture), 5, rodeForFiftySymbol);
            RomanRode rodeForFiveSymbol = new RomanRode(symbolFive.ToString(CultureInfo.InvariantCulture), 2, rodeForTenSymbol);
            RomanRode rodeForOneSymbol = new RomanRode(symbolOne.ToString(CultureInfo.InvariantCulture), 5, rodeForFiveSymbol);

            rodes = new List<RomanRode>
                        {
                                rodeForOneSymbol,
                                rodeForFiveSymbol,
                                rodeForTenSymbol,
                                rodeForFiftySymbol,
                                rodeForOneHundredSymbol,
                                rodeForFiveHundredSymbol,
                                rodeForThousandSymbol
                        };
        }
 public void Constructor_UsingNullEmptyOrWhitespaceSymbol_ThrowsException(
         [ValueSource(typeof (SymbolGenerator), "GetNullEmptyAndWhitespaceStrings")] string nullEmptyOrWhitespaceString)
 {
     RomanRode romanRode = new RomanRode(nullEmptyOrWhitespaceString, null, null);
 }
 public void Constructor_UsingInvalidRomanSymbol_ThrowsException()
 {
     RomanRode romanRode = new RomanRode("123", null, null);
 }
 public void Constructor_UsingAValidRomanSymbol_DoesNotThrowsException(
         [ValueSource(typeof (SymbolGenerator), "GetRomanBasicSymbols")] string romanSymbol)
 {
     RomanRode romanRode = new RomanRode(romanSymbol, null, null);
 }