예제 #1
0
        public int GetCountLuckyTickets(string algorithmName,
                                        int start       = DefaultStart, int end = DefaultEnd,
                                        int countDigits = DefaultCountDigits)
        {
            if (start > end)
            {
                throw new ArgumentException("End can't be less than start");
            }
            if (!Ticket.IsRealTicket(start, DefaultCountDigits) ||
                !Ticket.IsRealTicket(end, DefaultCountDigits))
            {
                throw new ArgumentException("Range are invalid");
            }

            var determinator = factory.CreateDeterminator(algorithmName);
            int count        = 0;

            for (int i = start; i <= end; i++)
            {
                if (determinator.IsLuckyTicket(new Ticket(i, countDigits)))
                {
                    ++count;
                }
            }

            return(count);
        }
        public void CreateDeterminator_StrMoskow_MoskowLuckyTicketDeterminator()
        {
            //arrange
            var factory = new LuckyTicketDeterminatorFactory();

            //act
            var actual = factory.CreateDeterminator("Moskow");

            //assert
            Assert.IsType <MoskowLuckyTicketDeterminator>(actual);
        }
        public void CreateDeterminator_StrPiter_PiterLuckyTicketDeterminator()
        {
            //arrange
            var factory = new LuckyTicketDeterminatorFactory();

            //act
            var actual = factory.CreateDeterminator("Piter");

            //assert
            Assert.IsType <PiterLuckyTicketDeterminator>(actual);
        }
        public void CreateDeterminator_NullStr_Null()
        {
            //arrange
            var factory = new LuckyTicketDeterminatorFactory();

            //act
            var actual = factory.CreateDeterminator(null);

            //assert
            Assert.Null(actual);
        }