Example #1
0
        public void CanConvertNumber_Number100000000_True()
        {
            //arrange
            var  converter = new EnglishNumberToTextConverter();
            long number    = 100000000;

            //act
            var actual = converter.CanConvertNumber(number);

            //assert
            Assert.True(actual);
        }
Example #2
0
        public void CanConvertNumber_NumberInt32Min_False()
        {
            //arrange
            var  converter = new EnglishNumberToTextConverter();
            long number    = Int64.MinValue + 1;

            //act
            var actual = converter.CanConvertNumber(number);

            //assert
            Assert.False(actual);
        }
Example #3
0
        public void ConvertNumber_0_Zero()
        {
            //arrange
            var    converter = new EnglishNumberToTextConverter();
            long   number    = 0;
            string expected  = "zero";

            //act
            var actual = converter.ConvertNumber(number);

            actual = actual.Trim();

            //assert
            Assert.Equal(expected, actual);
        }
Example #4
0
        public void ConvertNumber_100000000_CorrectString()
        {
            //arrange
            var    converter = new EnglishNumberToTextConverter();
            long   number    = 100000000;
            string expected  = "one hundred million";

            //act
            var actual = converter.ConvertNumber(number);

            actual = actual.Trim();

            //assert
            Assert.Equal(expected, actual);
        }
Example #5
0
        public void ConvertNumber_999_CorrectString()
        {
            //arrange
            var    converter = new EnglishNumberToTextConverter();
            long   number    = 999;
            string expected  = "nine hundred ninety nine";

            //act
            var actual = converter.ConvertNumber(number);

            actual = actual.Trim();

            //assert
            Assert.Equal(expected, actual);
        }
Example #6
0
        public void ConvertNumber_12_CorrectString()
        {
            //arrange
            var    converter = new EnglishNumberToTextConverter();
            long   number    = 12;
            string expected  = "twelve";

            //act
            var actual = converter.ConvertNumber(number);

            actual = actual.Trim();

            //assert
            Assert.Equal(expected, actual);
        }
Example #7
0
        public void DivideNumberIntoParts_Number546Quantity1_Correct()
        {
            //arrange
            var converter = new EnglishNumberToTextConverter();
            int number    = 546;
            int quantity  = 1;

            int[] expected = { 5, 4, 6 };

            //act
            var actual = converter.DivideNumberIntoParts(
                number, quantity);

            //assert
            Assert.Equal(expected, actual);
        }
Example #8
0
        public void DivideNumberIntoParts_Number0Quantity3_EmptyArr()
        {
            //arrange
            var converter = new EnglishNumberToTextConverter();
            int number    = 0;
            int quantity  = 3;

            int[] expected = { };

            //act
            var actual = converter.DivideNumberIntoParts(
                number, quantity);

            //assert
            Assert.Equal(expected, actual);
        }
Example #9
0
        public void DivideNumberIntoParts_Number1456872Quantity3_Correct()
        {
            //arrange
            var converter = new EnglishNumberToTextConverter();
            int number    = 1456872;
            int quantity  = 3;

            int[] expected = { 1, 456, 872 };

            //act
            var actual = converter.DivideNumberIntoParts(
                number, quantity);

            //assert
            Assert.Equal(expected, actual);
        }
Example #10
0
        public void ExecuteProgram(string[] args)
        {
            bool isNewTry = false;

            do
            {
                if (isNewTry)
                {
                    args     = ConsoleUI.AskInputParams();
                    isNewTry = false;
                }

                if (!Validator.IsValid(args))
                {
                    Logger.Log.Info("ProgramController: "
                                    + "Input data is not valid");

                    ConsoleUI.ShowMessage("Your data is not valid");

                    if (!ConsoleUI.AskСonfirmation("Do you want to retype them?",
                                                   new string[] { "YES", "Y" }))
                    {
                        Logger.Log.Info("ProgramController: "
                                        + "Program completion. "
                                        + "User refused to re-enter data");

                        break;
                    }

                    Logger.Log.Debug("ProgramController: "
                                     + "Re-input data");

                    args = ConsoleUI.AskInputParams();

                    continue;
                }

                InputDTO inputDTO = Parser.Parse(args);
                NumberToTextConverter converter;

                Logger.Log.Debug("ProgramController: "
                                 + "Type of translator selected: "
                                 + inputDTO.Algorithm.ToString());

                switch (inputDTO.Algorithm)
                {
                case InputDTO.Algorithms.English:
                    converter = new EnglishNumberToTextConverter();
                    break;

                default:
                    converter = new EnglishNumberToTextConverter();
                    break;
                }

                NumberTranslator translator = new NumberTranslator(converter);

                if (translator.CanConvertToText(inputDTO.Number))
                {
                    ConsoleUI.ShowMessage(
                        translator.ConvertToText(inputDTO.Number));
                }
                else
                {
                    Logger.Log.InfoFormat("ProgramController: "
                                          + "translator {0} can't convert {1}"
                                          , inputDTO.Algorithm.ToString()
                                          , inputDTO.Number);

                    ConsoleUI.ShowMessage(
                        "This converter can't convert the number. " +
                        "The number is too big.");
                }

                if (ConsoleUI.AskСonfirmation("Do you want to continue?",
                                              new string[] { "YES", "Y" }))
                {
                    Logger.Log.Info("ProgramController: "
                                    + "Program continue. "
                                    + "User confirmed continuation");

                    isNewTry = true;
                }
                else
                {
                    Logger.Log.Info("ProgramController: "
                                    + "Program completion. "
                                    + "User did't confirm continuation");

                    break;
                }
            } while (true);
        }
        public void ExecuteProgramm(string[] args)
        {
            bool isNewTry = false;

            do
            {
                if (isNewTry)
                {
                    args     = AskInputParams();
                    isNewTry = false;
                }

                if (!IsValid(args))
                {
                    Console.WriteLine("Your data is not valid");
                    if (!BaseConsoleUI.AskСonfirmation("Do you want to retype them?",
                                                       new string[] { "YES", "Y" }))
                    {
                        break;
                    }

                    args = AskInputParams();

                    continue;
                }

                InputDTO inputDTO = Parser.Parse(args);

                NumberToTextConverter converter;

                switch (inputDTO.Algorithm)
                {
                case InputDTO.Algorithms.English:
                    converter = new EnglishNumberToTextConverter();
                    break;

                default:
                    converter = new EnglishNumberToTextConverter();
                    break;
                }

                Number number = new Number(inputDTO.Number, converter);

                if (number.CanConvertToText())
                {
                    Console.WriteLine(number.ConvertToText());
                }
                else
                {
                    Console.WriteLine(
                        "This converter can't convert the number. " +
                        "The number is too big.");
                }

                if (BaseConsoleUI.AskСonfirmation("Do you want to continue?",
                                                  new string[] { "YES", "Y" }))
                {
                    isNewTry = true;
                }
                else
                {
                    break;
                }
            } while (true);
        }