Exemplo n.º 1
0
        public static void ShowConsoleMenu(string[] inputParams)
        {
            bool isNewTry = false;

            do
            {
                if (isNewTry)
                {
                    inputParams = AskInputParams(InputData.CountParams);
                    isNewTry    = false;
                }

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

                    inputParams = AskInputParams(InputData.CountParams);

                    continue;
                }

                InputData inputData = Parser.Parse(inputParams);
                if (inputData.AlgorithmsArr.Length == 0)
                {
                    Console.WriteLine("Your file doesn`t have key words?");
                    if (!AskBoolValue("Do you want to choose another file?",
                                      new string[] { "YES", "Y" }))
                    {
                        break;
                    }

                    inputParams = AskInputParams(InputData.CountParams);

                    continue;
                }

                var factory = new LuckyTicketDeterminatorFactory();
                var counter = new LuckyTicketCounter(factory);

                PrintKeyValueArr("Number of lucky tickets: ",
                                 inputData.AlgorithmsArr,
                                 counter.GetRangeCountLuckyTickets(inputData.AlgorithmsArr));

                if (AskBoolValue("Do you want to continue?",
                                 new string[] { "YES", "Y" }))
                {
                    isNewTry = true;
                }
                else
                {
                    break;
                }
            } while (true);
        }
        public void CountNumberOfLuckyTickets_Piter_ReturnsNumberOfTickets(int digits, int expected)
        {
            // Arrange
            LuckyTicketCounter ticketCounter = new LuckyTicketCounter(new LuckyTicketPeter(), digits);

            // Act
            int actual = ticketCounter.CountNumberOfLuckyTickets();

            // Assert
            Assert.AreEqual(expected, actual);
        }
        public void GetCountLuckyTickets_ModePiterStandardValues_55251()
        {
            //arrange
            string mode     = "Piter";
            int    expected = 55251;

            var factory = new LuckyTicketDeterminatorFactory();
            var counter = new LuckyTicketCounter(factory);

            //act
            var actual = counter.GetCountLuckyTickets(mode);

            //assert
            Assert.Equal(expected, actual);
        }
        public void CountTest_CorrectInputForDigitsOfTicketInputValue(byte digitsOfTicket, int expectedCount)
        {
            // Arrange
            Mock <ILuckyTicketAlgorithm> luckyTicketAlgorithm = new Mock <ILuckyTicketAlgorithm>();

            luckyTicketAlgorithm.Setup((obj) => obj.IsLucky(It.Is <Ticket>(
                                                                ticket => (ticket.NumberOfDigits & 1) == 0))).Returns(true);
            LuckyTicketCounter counter = new LuckyTicketCounter();
            int actualLuckyTicketCount;

            // Act
            actualLuckyTicketCount = counter.Count(luckyTicketAlgorithm.Object, digitsOfTicket);

            // Assert
            Assert.AreEqual(expectedCount, actualLuckyTicketCount);
        }
        public void CountTest_CorrectInputForStringInputStartValueAndInputBoundaryValue(
            string inputStartValue, string inputBoundaryValue, int expectedCount)
        {
            // Arrange
            Mock <ILuckyTicketAlgorithm> luckyTicketAlgorithm = new Mock <ILuckyTicketAlgorithm>();

            luckyTicketAlgorithm.Setup((obj) => obj.IsLucky(It.Is <Ticket>(
                                                                ticket => (ticket.NumberOfDigits & 1) == 0))).Returns(true);
            Ticket             startValue    = Ticket.Initialize(inputStartValue);
            Ticket             boundaryValue = Ticket.Initialize(inputBoundaryValue);
            LuckyTicketCounter counter       = new LuckyTicketCounter();
            int actualLuckyTicketCount;

            // Act
            actualLuckyTicketCount = counter.Count(luckyTicketAlgorithm.Object, startValue, boundaryValue);

            // Assert
            Assert.AreEqual(expectedCount, actualLuckyTicketCount);
        }
Exemplo n.º 6
0
        public static 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 inputData = Parser.Parse(args);
                if (inputData.Algorithm == 0)
                {
                    Logger.Log.Debug("ProgramController: "
                                     + "The file doesn`t have key words");

                    ConsoleUI.ShowMessage("Your file doesn`t have key words");
                    if (!ConsoleUI.AskСonfirmation("Do you want to choose another file?",
                                                   new string[] { "YES", "Y" }))
                    {
                        break;
                    }

                    args = ConsoleUI.AskInputParams();

                    continue;
                }

                var factory = new LuckyTicketDeterminatorFactory();
                var counter = new LuckyTicketCounter(factory);

                ConsoleUI.ShowMessage("Number of lucky tickets: "
                                      + inputData.Algorithm + " - "
                                      + counter.GetCountLuckyTickets(inputData.Algorithm.ToString()));


                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);
        }