Пример #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++;
            }
        }
        /// <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);
        }
Пример #3
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);
        }