public void Translate_Number_ShoulReturn_ValidText()
        {
            //Arrange
            var number = 100;

            //Action
            var result = _service.Translate(number);

            //Assert
            Assert.AreEqual(result, "hundred");
        }
Exemplo n.º 2
0
        private string GetEquilentWord(int number, int unit)
        {
            StringBuilder sb = new StringBuilder();

            if ((number / unit) > 0)
            {
                sb.Append($"{NumberToWords(number / unit)} {_numberTranslator.Translate(unit)} ");
                if (number % unit != 0)
                {
                    sb.Append($"{_serviceConfigurations.CurrencyUnitsSepartor} ");
                }
            }
            return(sb.ToString());
        }
        //private StringBuilder _wordsBuilder;
        private string NumberToWords(int number)
        {
            StringBuilder words = new StringBuilder();

            if (number == 0)
            {
                return("zero");
            }

            //Process Million
            words.Append(Process(number, 1000000));
            number %= 1000000;
            //todo: verify logic
            //words = words.Replace(CurrencySepartor, " ");

            if (words.Length != 0)
            {
                words.Append(CurrencySepartor);
            }

            //Process Thousands
            words.Append(Process(number, 1000));
            number %= 1000;

            //if (words.Length != 0)
            //    words.Append(CurrencySepartor);

            words.Append(Process(number, 100));
            number %= 100;

            //words.Append(Process(number, 10));
            //number %= 10;

            if (number > 0)
            {
                if (words.Length != 0)
                {
                    words.Append(TeensSepartor);
                }

                //var unitsMap = new[] { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
                //var tensMap = new[] { "zero", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" };

                if (number < 20)
                {
                    words.Append(_numberTranslator.Translate(number));//unitsMap[number];
                }
                else
                {//21-99
                 //words.Append(_numberTranslator.Translate(number / 10));//tensMap[number / 10];

                    var tens = number - (number % 10);
                    words.Append(_numberTranslator.Translate(tens));//tensMap[number / 10];
                    if ((number % 10) > 0)
                    {
                        words.Append("-" + _numberTranslator.Translate(number % 10));//unitsMap[number % 10];
                    }
                }
            }

            return(words.ToString());
        }