Ejemplo n.º 1
0
        public void GetEnumeratorTest__FalseLuckyTicketAlgorithm_ReturnZeroTickets(uint startTicketValue, byte startTicketDigitsNumber)
        {
            // Arrange
            List <Ticket> ticketList = new List <Ticket>();

            ticketList.Add(Ticket.Initialize(startTicketValue, startTicketDigitsNumber));
            ticketList.Add(Ticket.Initialize(startTicketValue + 1, startTicketDigitsNumber));
            ticketList.Add(Ticket.Initialize(startTicketValue + 2, startTicketDigitsNumber));
            ticketList.Add(Ticket.Initialize(startTicketValue + 3, startTicketDigitsNumber));
            Mock <ILuckyTicketAlgorithm> luckyTicketAlgorithm = new Mock <ILuckyTicketAlgorithm>();

            luckyTicketAlgorithm.Setup((obj) => obj.IsLucky(It.IsAny <Ticket>())).Returns(false);
            LuckyTicketsGenerator generator = LuckyTicketsGenerator.Initialize(
                Ticket.Initialize(startTicketValue, startTicketDigitsNumber),
                Ticket.Initialize(startTicketValue + 3, startTicketDigitsNumber),
                luckyTicketAlgorithm.Object);

            // Act and Assert
            int i = 0;

            foreach (Ticket ticket in generator)
            {
                Assert.IsTrue(ticketList[i].Equals(ticket));
                i++;
            }
        }
        public void Count(GenerationLackyTicketsMethod method, byte quantityDigits, int expected)
        {
            // Arrange
            LuckyTicketsGenerator lackyGenerator = LuckyTicketsGenerator.Create(method, quantityDigits);

            // Act
            int real = lackyGenerator.Count();

            // Assert
            Assert.AreEqual(real, expected);
        }
        /// <summary>
        /// Counts lucky tickets in specified range using specified algorithm
        /// </summary>
        /// <param name="luckyTicketAlgorithm">The lucky ticket algorithm</param>
        /// <param name="startValue">The start value from which generator wil be searching for tickets</param>
        /// <param name="boundaryValue">The boundary value until which generator wil be searching for tickets</param>
        /// <returns></returns>
        public int Count(ILuckyTicketAlgorithm luckyTicketAlgorithm, Ticket startValue, Ticket boundaryValue)
        {
            LuckyTicketsGenerator generator = LuckyTicketsGenerator.Initialize(startValue, boundaryValue, luckyTicketAlgorithm);
            int luckyTicketsCount           = 0;

            foreach (Ticket luckyTicket in generator)
            {
                luckyTicketsCount++;
            }

            return(luckyTicketsCount);
        }
Ejemplo n.º 4
0
        public void Run(string[] args)
        {
            _view.PrintTitleText(MessagesResources.ApplicationName);
            _view.PrintInstructionText(MessagesResources.Instruction);

            try
            {
                _inboxParams = new MainParamValidator(args).GetMainParameters();
            }
            catch (Exception ex)
            {
                _view.PrintErrorText(ex.Message);
                return;
            }

            do
            {
                bool isFailed;
                do
                {
                    isFailed = false;
                    try
                    {
                        _view.AskInputPath(MessagesResources.AskInputPath);
                    }
                    catch (Exception ex)
                    {
                        _view.PrintErrorText(ex.Message);
                        isFailed = true;
                    }
                } while (isFailed);

                LuckyTicketsGenerator lackyGenerator = LuckyTicketsGenerator.Create(_countMethod, _inboxParams.QuantityDigits);

                try
                {
                    if (_inboxParams.PathLog != String.Empty)
                    {
                        lackyGenerator.SaveToFile(_inboxParams.PathLog);
                    }
                }
                catch
                {
                    _view.PrintErrorText(MessagesResources.ErrorFileNotSaved);
                }

                _view.PrintResultText(String.Format(MessagesResources.Result, lackyGenerator.Count().ToString()));
                _view.AskContinueFlag(MessagesResources.AskContunue);
            } while (_continueFlag);
        }
Ejemplo n.º 5
0
        public void InitializeTest_ReturnNewLuckyTicketGeneratorWithCorrectProperties(
            string stringStartTicket, string stringBoundaryTicket)
        {
            // Arrange
            Ticket startTicket    = Ticket.Initialize(stringStartTicket);
            Ticket boundaryTicket = Ticket.Initialize(stringBoundaryTicket);

            Mock <ILuckyTicketAlgorithm> luckyTicketAlgorithm = new Mock <ILuckyTicketAlgorithm>();

            luckyTicketAlgorithm.Setup((obj) => obj.IsLucky(It.IsAny <Ticket>())).Returns(true);

            // Act
            LuckyTicketsGenerator generator = LuckyTicketsGenerator.Initialize(startTicket,
                                                                               boundaryTicket, luckyTicketAlgorithm.Object);

            // Assert
            Assert.IsNotNull(generator);
            Assert.IsInstanceOfType(generator, typeof(LuckyTicketsGenerator));
            Assert.AreEqual(startTicket, generator.StartValue);
            Assert.AreEqual(boundaryTicket, generator.BoundaryValue);
            Assert.AreEqual(luckyTicketAlgorithm.Object, generator.LuckyTicketAlgorithm);
        }