Esempio n. 1
0
        public void SeekDirectionTest()
        {
            var start = new DayRange();

            var daySeeker = new DaySeeker();

            Enumerable
            .Range(-10, 20)
            .RunEach(i => {
                var offset = i * 5;
                var day    = daySeeker.FindDay(start, offset);
                day.IsSamePeriod(start.AddDays(offset)).Should().Be.True();
            });


            var backwardSeeker = new DaySeeker(SeekDirection.Backward);

            Enumerable
            .Range(-10, 20)
            .RunEach(i => {
                var offset = i * 5;
                var day    = backwardSeeker.FindDay(start, offset);
                day.IsSamePeriod(start.AddDays(-offset)).Should().Be.True();
            });
        }
Esempio n. 2
0
        public void SimpleForwardTest()
        {
            var start     = new DayRange();
            var daySeeker = new DaySeeker();

            var day1 = daySeeker.FindDay(start, 0);

            day1.IsSamePeriod(start).Should().Be.True();

            var day2 = daySeeker.FindDay(start, 1);

            day2.IsSamePeriod(start.GetNextDay()).Should().Be.True();

            Enumerable
            .Range(-10, 20)
            .RunEach(i => {
                var offset = i * 5;
                var day    = daySeeker.FindDay(start, offset);
                day.IsSamePeriod(start.AddDays(offset)).Should().Be.True();
            });
        }
Esempio n. 3
0
        protected DayRange StartDayVisit(DayRange day, TContext context, SeekDirection?visitDirection = null)
        {
            day.ShouldNotBeNull("day");
            var direction = visitDirection ?? SeekDirection;

            if (IsDebugEnabled)
            {
                log.Debug("Day 단위로 탐색합니다. day=[{0}], context=[{1}], direction=[{2}]", day, context, direction);
            }

            DayRange lastVisited = null;

            OnVisitStart();

            var minStart = DateTime.MinValue;
            var maxEnd   = DateTime.MaxValue.AddYears(-1);
            var offset   = (direction == SeekDirection.Forward) ? 1 : -1;

            while (day.Start > minStart && day.End < maxEnd)
            {
                if (OnVisitDay(day, context) == false)
                {
                    lastVisited = day;
                    break;
                }

                day = day.AddDays(offset);
            }

            OnVisitEnd();

            if (IsDebugEnabled)
            {
                log.Debug("마지막 탐색 Day. lastVisited=[{0}]", lastVisited);
            }

            return(lastVisited);
        }
Esempio n. 4
0
        public void SimpleBackwardTest()
        {
            var start     = new DayRange();
            var daySeeker = new DaySeeker(SeekDirection.Backward);


            var day1 = daySeeker.FindDay(start, 0);

            day1.IsSamePeriod(start).Should().Be.True();


            var day2 = daySeeker.FindDay(start, 1);

            day2.IsSamePeriod(start.GetPreviousDay()).Should().Be.True();

            Enumerable
            .Range(-10, 20)
            .RunEach(i => {
                var offset = i * 5;
                var day    = daySeeker.FindDay(start, offset);
                day.IsSamePeriod(start.AddDays(-offset)).Should().Be.True();
            });
        }