public void CalendarGetGapTest() { // simmulation of some reservations TimePeriodCollection periods = new TimePeriodCollection(); periods.Add(new Days(2011, 3, 7, 2)); periods.Add(new Days(2011, 3, 16, 2)); // the overall search range CalendarTimeRange limits = new CalendarTimeRange(new DateTime(2011, 3, 4), new DateTime(2011, 3, 21)); Days days = new Days(limits.Start, limits.Duration.Days + 1); ITimePeriodCollection dayList = days.GetDays(); foreach (Day day in dayList) { if (!limits.HasInside(day)) { continue; // outside of the search scope } if (day.DayOfWeek == DayOfWeek.Saturday || day.DayOfWeek == DayOfWeek.Sunday) { periods.Add(day); // // exclude weekend day } } TimeGapCalculator <TimeRange> gapCalculator = new TimeGapCalculator <TimeRange>(new TimeCalendar()); ITimePeriodCollection gaps = gapCalculator.GetGaps(periods, limits); Assert.Equal(4, gaps.Count); Assert.True(gaps[0].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 4), Duration.Days(1)))); Assert.True(gaps[1].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 9), Duration.Days(3)))); Assert.True(gaps[2].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 14), Duration.Days(2)))); Assert.True(gaps[3].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 18), Duration.Days(1)))); } // CalendarGetGapTest
public void InsertTest() { var now = ClockProxy.Clock.Now; var schoolDay = new SchoolDay(now); var timePeriods = new TimePeriodCollection(); timePeriods.Count.Should().Be(0); timePeriods.Add(schoolDay.Lesson1); timePeriods.Count.Should().Be(1); timePeriods.Add(schoolDay.Lesson3); timePeriods.Count.Should().Be(2); timePeriods.Add(schoolDay.Lesson4); timePeriods.Count.Should().Be(3); // between timePeriods[1].Should().Be(schoolDay.Lesson3); timePeriods.Insert(1, schoolDay.Lesson2); timePeriods[1].Should().Be(schoolDay.Lesson2); // first timePeriods[0].Should().Be(schoolDay.Lesson1); timePeriods.Insert(0, schoolDay.Break1); timePeriods[0].Should().Be(schoolDay.Break1); // last timePeriods[timePeriods.Count - 1].Should().Be(schoolDay.Lesson4); timePeriods.Insert(timePeriods.Count, schoolDay.Break3); timePeriods[timePeriods.Count - 1].Should().Be(schoolDay.Break3); }
public void InsertTest() { DateTime now = ClockProxy.Clock.Now; SchoolDay schoolDay = new SchoolDay(now); TimePeriodCollection timePeriods = new TimePeriodCollection(); Assert.Equal(0, timePeriods.Count); timePeriods.Add(schoolDay.Lesson1); Assert.Equal(1, timePeriods.Count); timePeriods.Add(schoolDay.Lesson3); Assert.Equal(2, timePeriods.Count); timePeriods.Add(schoolDay.Lesson4); Assert.Equal(3, timePeriods.Count); // between Assert.Equal(timePeriods[1], schoolDay.Lesson3); timePeriods.Insert(1, schoolDay.Lesson2); Assert.Equal(timePeriods[1], schoolDay.Lesson2); // first Assert.Equal(timePeriods[0], schoolDay.Lesson1); timePeriods.Insert(0, schoolDay.Break1); Assert.Equal(timePeriods[0], schoolDay.Break1); // last Assert.Equal(timePeriods[timePeriods.Count - 1], schoolDay.Lesson4); timePeriods.Insert(timePeriods.Count, schoolDay.Break3); Assert.Equal(timePeriods[timePeriods.Count - 1], schoolDay.Break3); } // InsertTest
public void SortByDurationTest() { DateTime now = ClockProxy.Clock.Now; TimePeriodCollection timePeriods = new TimePeriodCollection(); TimeSpan oneHour = new TimeSpan(1, 0, 0); TimeSpan twoHours = new TimeSpan(2, 0, 0); TimeSpan threeHours = new TimeSpan(3, 0, 0); TimeSpan fourHours = new TimeSpan(4, 0, 0); timePeriods.Add(new TimeRange(now, oneHour)); timePeriods.Add(new TimeRange(now, twoHours)); timePeriods.Add(new TimeRange(now, threeHours)); timePeriods.Add(new TimeRange(now, fourHours)); timePeriods.SortByDuration(ListSortDirection.Descending); Assert.Equal(fourHours, timePeriods[0].Duration); Assert.Equal(threeHours, timePeriods[1].Duration); Assert.Equal(twoHours, timePeriods[2].Duration); Assert.Equal(oneHour, timePeriods[3].Duration); timePeriods.SortByDuration(); Assert.Equal(oneHour, timePeriods[0].Duration); Assert.Equal(twoHours, timePeriods[1].Duration); Assert.Equal(threeHours, timePeriods[2].Duration); Assert.Equal(fourHours, timePeriods[3].Duration); } // SortByDurationTest
public void RelationPeriodsTest() { DateTime now = ClockProxy.Clock.Now; TimeRange timeRange1 = new TimeRange(new DateTime(now.Year, now.Month, 8), new DateTime(now.Year, now.Month, 18)); TimeRange timeRange2 = new TimeRange(new DateTime(now.Year, now.Month, 10), new DateTime(now.Year, now.Month, 11)); TimeRange timeRange3 = new TimeRange(new DateTime(now.Year, now.Month, 13), new DateTime(now.Year, now.Month, 15)); TimeRange timeRange4 = new TimeRange(new DateTime(now.Year, now.Month, 9), new DateTime(now.Year, now.Month, 14)); TimeRange timeRange5 = new TimeRange(new DateTime(now.Year, now.Month, 16), new DateTime(now.Year, now.Month, 17)); TimePeriodCollection timePeriods = new TimePeriodCollection(); timePeriods.Add(timeRange1); timePeriods.Add(timeRange2); timePeriods.Add(timeRange3); timePeriods.Add(timeRange4); timePeriods.Add(timeRange5); Assert.Equal(1, timePeriods.RelationPeriods(timeRange1, PeriodRelation.ExactMatch).Count); Assert.Equal(1, timePeriods.RelationPeriods(timeRange2, PeriodRelation.ExactMatch).Count); Assert.Equal(1, timePeriods.RelationPeriods(timeRange3, PeriodRelation.ExactMatch).Count); Assert.Equal(1, timePeriods.RelationPeriods(timeRange4, PeriodRelation.ExactMatch).Count); Assert.Equal(1, timePeriods.RelationPeriods(timeRange5, PeriodRelation.ExactMatch).Count); // all Assert.Equal(5, timePeriods.RelationPeriods(new TimeRange(new DateTime(now.Year, now.Month, 7), new DateTime(now.Year, now.Month, 19)), PeriodRelation.Enclosing).Count); // timerange3 Assert.Equal(1, timePeriods.RelationPeriods(new TimeRange(new DateTime(now.Year, now.Month, 11), new DateTime(now.Year, now.Month, 16)), PeriodRelation.Enclosing).Count); } // RelationPeriodsTest
public void GetGapTest() { DateTime now = ClockProxy.Clock.Now; SchoolDay schoolDay = new SchoolDay(now); TimePeriodCollection excludePeriods = new TimePeriodCollection(); TimeGapCalculator <TimeRange> gapCalculator = new TimeGapCalculator <TimeRange>(); excludePeriods.AddAll(schoolDay); Assert.Equal(0, gapCalculator.GetGaps(excludePeriods).Count); Assert.Equal(0, gapCalculator.GetGaps(excludePeriods, schoolDay).Count); excludePeriods.Clear(); excludePeriods.Add(schoolDay.Lesson1); excludePeriods.Add(schoolDay.Lesson2); excludePeriods.Add(schoolDay.Lesson3); excludePeriods.Add(schoolDay.Lesson4); ITimePeriodCollection gaps2 = gapCalculator.GetGaps(excludePeriods); Assert.Equal(3, gaps2.Count); Assert.True(gaps2[0].IsSamePeriod(schoolDay.Break1)); Assert.True(gaps2[1].IsSamePeriod(schoolDay.Break2)); Assert.True(gaps2[2].IsSamePeriod(schoolDay.Break3)); TimeRange testRange3 = new TimeRange(schoolDay.Lesson1.Start, schoolDay.Lesson4.End); ITimePeriodCollection gaps3 = gapCalculator.GetGaps(excludePeriods, testRange3); Assert.Equal(3, gaps3.Count); Assert.True(gaps3[0].IsSamePeriod(schoolDay.Break1)); Assert.True(gaps3[1].IsSamePeriod(schoolDay.Break2)); Assert.True(gaps3[2].IsSamePeriod(schoolDay.Break3)); TimeRange testRange4 = new TimeRange(schoolDay.Start.AddHours(-1), schoolDay.End.AddHours(1)); ITimePeriodCollection gaps4 = gapCalculator.GetGaps(excludePeriods, testRange4); Assert.Equal(5, gaps4.Count); Assert.True(gaps4[0].IsSamePeriod(new TimeRange(testRange4.Start, schoolDay.Start))); Assert.True(gaps4[1].IsSamePeriod(schoolDay.Break1)); Assert.True(gaps4[2].IsSamePeriod(schoolDay.Break2)); Assert.True(gaps4[3].IsSamePeriod(schoolDay.Break3)); Assert.True(gaps4[4].IsSamePeriod(new TimeRange(testRange4.End, testRange3.End))); excludePeriods.Clear(); excludePeriods.Add(schoolDay.Lesson1); ITimePeriodCollection gaps8 = gapCalculator.GetGaps(excludePeriods, schoolDay.Lesson1); Assert.Equal(0, gaps8.Count); TimeRange testRange9 = new TimeRange(schoolDay.Lesson1.Start.Subtract(new TimeSpan(1)), schoolDay.Lesson1.End.Add(new TimeSpan(1))); ITimePeriodCollection gaps9 = gapCalculator.GetGaps(excludePeriods, testRange9); Assert.Equal(2, gaps9.Count); Assert.Equal <TimeSpan>(gaps9[0].Duration, new TimeSpan(1)); Assert.Equal <TimeSpan>(gaps9[1].Duration, new TimeSpan(1)); } // GetGapsTest
public void IntersectionPeriodsDateTimeTest() { DateTime now = ClockProxy.Clock.Now; TimeRange timeRange1 = new TimeRange(new DateTime(now.Year, now.Month, 8), new DateTime(now.Year, now.Month, 18)); TimeRange timeRange2 = new TimeRange(new DateTime(now.Year, now.Month, 10), new DateTime(now.Year, now.Month, 11)); TimeRange timeRange3 = new TimeRange(new DateTime(now.Year, now.Month, 13), new DateTime(now.Year, now.Month, 15)); TimeRange timeRange4 = new TimeRange(new DateTime(now.Year, now.Month, 9), new DateTime(now.Year, now.Month, 14)); TimeRange timeRange5 = new TimeRange(new DateTime(now.Year, now.Month, 16), new DateTime(now.Year, now.Month, 17)); TimePeriodCollection timePeriods = new TimePeriodCollection(); timePeriods.Add(timeRange1); timePeriods.Add(timeRange2); timePeriods.Add(timeRange3); timePeriods.Add(timeRange4); timePeriods.Add(timeRange5); Assert.Equal(1, timePeriods.IntersectionPeriods(timeRange1.Start).Count); Assert.Equal(1, timePeriods.IntersectionPeriods(timeRange1.End).Count); Assert.Equal(3, timePeriods.IntersectionPeriods(timeRange2.Start).Count); Assert.Equal(3, timePeriods.IntersectionPeriods(timeRange2.End).Count); Assert.Equal(3, timePeriods.IntersectionPeriods(timeRange3.Start).Count); Assert.Equal(2, timePeriods.IntersectionPeriods(timeRange3.End).Count); Assert.Equal(2, timePeriods.IntersectionPeriods(timeRange4.Start).Count); Assert.Equal(3, timePeriods.IntersectionPeriods(timeRange4.End).Count); Assert.Equal(2, timePeriods.IntersectionPeriods(timeRange5.Start).Count); Assert.Equal(2, timePeriods.IntersectionPeriods(timeRange5.End).Count); DateTime test1 = timeRange1.Start.AddMilliseconds(-1); ITimePeriodCollection insidePeriods1 = timePeriods.IntersectionPeriods(test1); Assert.Equal(0, insidePeriods1.Count); DateTime test2 = timeRange1.End.AddMilliseconds(1); ITimePeriodCollection insidePeriods2 = timePeriods.IntersectionPeriods(test2); Assert.Equal(0, insidePeriods2.Count); DateTime test3 = new DateTime(now.Year, now.Month, 12); ITimePeriodCollection insidePeriods3 = timePeriods.IntersectionPeriods(test3); Assert.Equal(2, insidePeriods3.Count); DateTime test4 = new DateTime(now.Year, now.Month, 14); ITimePeriodCollection insidePeriods4 = timePeriods.IntersectionPeriods(test4); Assert.Equal(3, insidePeriods4.Count); } // IntersectionPeriodsDateTimeTest
public void HasStartTest() { TimePeriodCollection timePeriods = new TimePeriodCollection(); Assert.False(timePeriods.HasStart); timePeriods.Add(new TimeBlock(TimeSpec.MinPeriodDate, Duration.Hour)); Assert.False(timePeriods.HasStart); timePeriods.Clear(); timePeriods.Add(new TimeBlock(ClockProxy.Clock.Now, Duration.Hour)); Assert.True(timePeriods.HasStart); } // HasStartTest
} // GapCalculator8 // ---------------------------------------------------------------------- public void GapCalculator16(int count) { TimeRange limits = new TimeRange(new DateTime(2011, 3, 29), new DateTime(2011, 6, 1)); TimeGapCalculator <TimeRange> gapCalculator = new TimeGapCalculator <TimeRange>(); TimePeriodCollection excludePeriods = new TimePeriodCollection(); for (int i = 0; i < 2; i++) { excludePeriods.Add(new TimeRange(new DateTime(2011, 3, 30, 00, 00, 0), new DateTime(2011, 3, 31, 00, 00, 0))); excludePeriods.Add(new TimeRange(new DateTime(2011, 3, 30, 00, 00, 0), new DateTime(2011, 3, 31, 00, 00, 0))); excludePeriods.Add(new TimeRange(new DateTime(2011, 4, 01, 00, 00, 0), new DateTime(2011, 4, 12, 00, 00, 0))); excludePeriods.Add(new TimeRange(new DateTime(2011, 4, 12, 00, 00, 0), new DateTime(2011, 4, 18, 00, 00, 0))); excludePeriods.Add(new TimeRange(new DateTime(2011, 4, 29, 00, 00, 0), new DateTime(2011, 4, 30, 00, 00, 0))); excludePeriods.Add(new TimeRange(new DateTime(2011, 4, 29, 00, 00, 0), new DateTime(2011, 4, 30, 00, 00, 0))); excludePeriods.Add(new TimeRange(new DateTime(2011, 5, 01, 00, 00, 0), new DateTime(2011, 5, 12, 00, 00, 0))); excludePeriods.Add(new TimeRange(new DateTime(2011, 5, 12, 00, 00, 0), new DateTime(2011, 5, 18, 00, 00, 0))); } Console.Write("GapCalculator 16 ({0:#,0}): ", count); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); for (int i = 0; i < count; i++) { gapCalculator.GetGaps(excludePeriods, limits); } stopwatch.Stop(); Console.WriteLine(" {0} ms", stopwatch.ElapsedMilliseconds); } // GapCalculator16
public void HasEndTest() { var now = ClockProxy.Clock.Now; var timePeriods = new TimePeriodCollection(); Assert.IsFalse(timePeriods.HasEnd); timePeriods.Add(new TimeBlock(DurationUtil.Hour, TimeSpec.MaxPeriodTime)); Assert.IsFalse(timePeriods.HasEnd); timePeriods.Clear(); timePeriods.Add(new TimeBlock(now, DurationUtil.Hour)); Assert.IsTrue(timePeriods.HasEnd); }
// ---------------------------------------------------------------------- public void TimePeriodCollectionSample() { TimePeriodCollection timePeriods = new TimePeriodCollection(); DateTime testDay = new DateTime(2010, 7, 23); // --- items --- timePeriods.Add(new TimeRange(TimeTrim.Hour(testDay, 8), TimeTrim.Hour(testDay, 11))); timePeriods.Add(new TimeBlock(TimeTrim.Hour(testDay, 10), Duration.Hours(3))); timePeriods.Add(new TimeRange(TimeTrim.Hour(testDay, 16, 15), TimeTrim.Hour(testDay, 18, 45))); timePeriods.Add(new TimeRange(TimeTrim.Hour(testDay, 14), TimeTrim.Hour(testDay, 15, 30))); Console.WriteLine("TimePeriodCollection: " + timePeriods); // > TimePeriodCollection: Count = 4; 23.07.2010 08:00:00 - 18:45:00 | 0.10:45 Console.WriteLine("TimePeriodCollection.Items"); foreach (ITimePeriod timePeriod in timePeriods) { Console.WriteLine("Item: " + timePeriod); } // > Item: 23.07.2010 08:00:00 - 11:00:00 | 03:00:00 // > Item: 23.07.2010 10:00:00 - 13:00:00 | 03:00:00 // > Item: 23.07.2010 16:15:00 - 18:45:00 | 02:30:00 // > Item: 23.07.2010 14:00:00 - 15:30:00 | 01:30:00 // --- intersection by moment --- DateTime intersectionMoment = new DateTime(2010, 7, 23, 10, 30, 0); ITimePeriodCollection momentIntersections = timePeriods.IntersectionPeriods(intersectionMoment); Console.WriteLine("TimePeriodCollection.IntesectionPeriods of " + intersectionMoment); // > TimePeriodCollection.IntesectionPeriods of 23.07.2010 10:30:00 foreach (ITimePeriod momentIntersection in momentIntersections) { Console.WriteLine("Intersection: " + momentIntersection); } // > Intersection: 23.07.2010 08:00:00 - 11:00:00 | 03:00:00 // > Intersection: 23.07.2010 10:00:00 - 13:00:00 | 03:00:00 // --- intersection by period --- TimeRange intersectionPeriod = new TimeRange(TimeTrim.Hour(testDay, 9), TimeTrim.Hour(testDay, 14, 30)); ITimePeriodCollection periodIntersections = timePeriods.IntersectionPeriods(intersectionPeriod); Console.WriteLine("TimePeriodCollection.IntesectionPeriods of " + intersectionPeriod); // > TimePeriodCollection.IntesectionPeriods of 23.07.2010 09:00:00 - 14:30:00 | 0.05:30 foreach (ITimePeriod periodIntersection in periodIntersections) { Console.WriteLine("Intersection: " + periodIntersection); } // > Intersection: 23.07.2010 08:00:00 - 11:00:00 | 03:00:00 // > Intersection: 23.07.2010 10:00:00 - 13:00:00 | 03:00:00 // > Intersection: 23.07.2010 14:00:00 - 15:30:00 | 01:30:00 } // TimePeriodCollectionSample
public void HasEndTest() { DateTime now = ClockProxy.Clock.Now; TimePeriodCollection timePeriods = new TimePeriodCollection(); Assert.False(timePeriods.HasEnd); timePeriods.Add(new TimeBlock(Duration.Hour, TimeSpec.MaxPeriodDate)); Assert.False(timePeriods.HasEnd); timePeriods.Clear(); timePeriods.Add(new TimeBlock(now, Duration.Hour)); Assert.True(timePeriods.HasEnd); } // HasEndTest
public void AddTest() { TimePeriodCollection timePeriods = new TimePeriodCollection(); Assert.AreEqual(timePeriods.Count, 0); timePeriods.Add(new TimeRange()); Assert.AreEqual(timePeriods.Count, 1); timePeriods.Add(new TimeRange()); Assert.AreEqual(timePeriods.Count, 2); timePeriods.Clear(); Assert.AreEqual(timePeriods.Count, 0); } // AddTest
public void AddTest() { var timePeriods = new TimePeriodCollection(); timePeriods.Count.Should().Be(0); timePeriods.Add(new TimeRange()); timePeriods.Count.Should().Be(1); timePeriods.Add(new TimeRange()); timePeriods.Count.Should().Be(2); timePeriods.Clear(); timePeriods.Count.Should().Be(0); }
public void PeriodOutsideTouchingLimitsTest() { TimeRange limits = new TimeRange(new DateTime(2011, 3, 1), new DateTime(2011, 3, 31)); TimeGapCalculator <TimeRange> gapCalculator = new TimeGapCalculator <TimeRange>(); TimePeriodCollection excludePeriods = new TimePeriodCollection(); excludePeriods.Add(new TimeRange(new DateTime(2011, 2, 1), new DateTime(2011, 3, 5))); excludePeriods.Add(new TimeRange(new DateTime(2011, 3, 20), new DateTime(2011, 4, 15))); ITimePeriodCollection gaps = gapCalculator.GetGaps(excludePeriods, limits); Assert.Equal(1, gaps.Count); Assert.True(gaps[0].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 5), new DateTime(2011, 3, 20)))); } // PeriodOutsideTouchingLimitsTest
public void AddTest() { TimePeriodCollection timePeriods = new TimePeriodCollection(); Assert.Equal(0, timePeriods.Count); timePeriods.Add(new TimeRange()); Assert.Equal(1, timePeriods.Count); timePeriods.Add(new TimeRange()); Assert.Equal(2, timePeriods.Count); timePeriods.Clear(); Assert.Equal(0, timePeriods.Count); } // AddTest
public void TimeBlockCombinedPeriodsTest() { TimePeriodCollection periods = new TimePeriodCollection(); DateTime date1 = ClockProxy.Clock.Now; DateTime date2 = date1.AddDays(1); DateTime date3 = date2.AddDays(1); periods.Add(new TimeBlock(date1, date2)); periods.Add(new TimeBlock(date2, date3)); TimeLine <TimeRange> timeLine = new TimeLine <TimeRange>(periods, null, null); ITimePeriodCollection combinedPeriods = timeLine.CombinePeriods(); Assert.Equal(1, combinedPeriods.Count); Assert.Equal(new TimeRange(date1, date3), combinedPeriods[0]); } // TimeBlockCombinedPeriodsTest
// ---------------------------------------------------------------------- public ITimePeriodCollection GetPeriodsOfYear(int year) { List <DateTime> timeLineMoments = new List <DateTime>(); DateTime yearStartDay = new DateTime(year, 1, 1); DateTime yearEndDay = yearStartDay.AddYears(1); timeLineMoments.Add(yearStartDay); foreach (YearMoment yearMoment in this) { // add error handling in case of invalid date like month=2 and day=30 timeLineMoments.Add(new DateTime(year, yearMoment.Month, yearMoment.Day)); } timeLineMoments.Add(yearEndDay); timeLineMoments.Sort((left, right) => left.Ticks.CompareTo(right.Ticks)); TimePeriodCollection yearPeriods = new TimePeriodCollection(); for (int i = 0; i < timeLineMoments.Count - 1; i++) { DateTime start = timeLineMoments[i]; DateTime end = timeLineMoments[i + 1]; int dayCount = end.Subtract(start).Days; yearPeriods.Add(new Days(start, dayCount)); } return(yearPeriods); } // GetPeriodsOfYear
/// <summary> /// <see cref="Periods"/>들의 Gap 부분들만을 기간 컬렉션으로 반환합니다. /// </summary> /// <returns>Gap 기간들의 컬렉션</returns> public ITimePeriodCollection CalcuateGaps() { if (IsDebugEnabled) { log.Debug("ITimePeriod 사이의 Gap들을 계산하여 ITimePeriod 컬렉션으로 반환합니다..."); } // exclude periods // var gapPeriods = new TimePeriodCollection(); foreach (var period in Periods.Where(p => Limits.IntersectsWith(p))) { gapPeriods.Add(new TimeRange(period)); } var timeLineMoments = GetTimeLineMoments(gapPeriods); if (timeLineMoments.Count == 0) { return new TimePeriodCollection { Limits } } ; var range = ActivatorTool.CreateInstance <T>(); range.Setup(MapPeriodStart(Limits.Start), MapPeriodEnd(Limits.End)); return(timeLineMoments.CalculateGaps <T>(range)); }
public void OverlappingPeriods3Test() { TimeRange limits = new TimeRange(new DateTime(2011, 3, 29), new DateTime(2011, 4, 1)); TimeGapCalculator <TimeRange> gapCalculator = new TimeGapCalculator <TimeRange>(); TimePeriodCollection excludePeriods = new TimePeriodCollection(); excludePeriods.Add(new TimeRange(new DateTime(2011, 3, 30, 00, 00, 0), new DateTime(2011, 3, 31, 00, 00, 0))); excludePeriods.Add(new TimeRange(new DateTime(2011, 3, 30, 00, 00, 0), new DateTime(2011, 3, 31, 00, 00, 0))); ITimePeriodCollection gaps = gapCalculator.GetGaps(excludePeriods, limits); Assert.Equal(2, gaps.Count); Assert.True(gaps[0].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 29), new DateTime(2011, 3, 30)))); Assert.True(gaps[1].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 31), new DateTime(2011, 4, 01)))); } // OverlappingPeriods3Test
// ---------------------------------------------------------------------- public IList <MyTimePeriod> GetGaps(IEnumerable <MyTimePeriod> periods) { TimeGapCalculator <TimeRange> gapCalculator = new TimeGapCalculator <TimeRange>(); TimePeriodCollection calcPeriods = new TimePeriodCollection(); foreach (MyTimePeriod period in periods) { calcPeriods.Add(new TimeRange(period.Start, period.End)); } List <MyTimePeriod> gaps = new List <MyTimePeriod>(); if (calcPeriods.Count == 0) { return(gaps); } ITimePeriodCollection calcCaps = gapCalculator.GetGaps(calcPeriods); foreach (TimeRange calcCap in calcCaps) { gaps.Add(new MyTimePeriod { Start = calcCap.Start, End = calcCap.End }); } return(gaps); } // GetGaps
public void TouchingPeriodsTest() { TimeRange limits = new TimeRange(new DateTime(2011, 3, 29), new DateTime(2011, 4, 1)); TimeGapCalculator <TimeRange> gapCalculator = new TimeGapCalculator <TimeRange>(); TimePeriodCollection excludePeriods = new TimePeriodCollection(); excludePeriods.Add(new TimeRange(new DateTime(2011, 3, 30, 00, 00, 0), new DateTime(2011, 3, 30, 08, 30, 0))); excludePeriods.Add(new TimeRange(new DateTime(2011, 3, 30, 08, 30, 0), new DateTime(2011, 3, 30, 12, 00, 0))); excludePeriods.Add(new TimeRange(new DateTime(2011, 3, 30, 10, 00, 0), new DateTime(2011, 3, 31, 00, 00, 0))); ITimePeriodCollection gaps = gapCalculator.GetGaps(excludePeriods, limits); Assert.AreEqual(gaps.Count, 2); Assert.IsTrue(gaps[0].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 29), new DateTime(2011, 3, 30)))); Assert.IsTrue(gaps[1].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 31), new DateTime(2011, 4, 01)))); } // TouchingPeriodsTest
// ---------------------------------------------------------------------- public void TimeGapCalculatorSample() { // simulation of some reservations TimePeriodCollection reservations = new TimePeriodCollection(); reservations.Add(new Days(2011, 3, 7, 2)); reservations.Add(new Days(2011, 3, 16, 2)); // the overall search range CalendarTimeRange searchLimits = new CalendarTimeRange(new DateTime(2011, 3, 4), new DateTime(2011, 3, 21)); // search the largest free time block ICalendarTimeRange largestFreeTimeBlock = FindLargestFreeTimeBlock(reservations, searchLimits); Console.WriteLine("Largest free time: " + largestFreeTimeBlock); // > Largest free time: 09.03.2011 00:00:00 - 11.03.2011 23:59:59 | 2.23:59 } // TimeGapCalculatorSample
public HttpResponseMessage Post(string param1, string param2, string api_key) { Customer customer = new Customer(); customer.param1 = param1; customer.param2 = param2; customer.api_key = api_key; delay = int.Parse(workTimeString[2]); if (customer.api_key == "M6N015C8W6ALJ") { String formatFromAndroid = "yyyyMMddTHHmmss"; DateTime dateTime = DateTime.ParseExact(customer.param1, formatFromAndroid, null); DateTime dateTimeTemp = dateTime; dateTime = dateTime.Add(new TimeSpan(0, -delay, 0)); customer.SetParam1Temp(dateTime.ToString(formatFromAndroid)); ITimePeriod timePeriod = new TimeBlock(dateTimeTemp); TimePeriodCollection timePeriods = new TimePeriodCollection(); foreach (Customer customer1 in customers) { string line = customer1.GetParam1Temp(); DateTime parsedLine = DateTime.ParseExact(line, formatFromAndroid, null); timePeriods.Add(new TimeBlock(parsedLine, Duration.Minutes(delay * 2))); if (timePeriods.Last().IntersectsWith(timePeriod)) { List <CustSecret> custSecrets = new List <CustSecret>(); foreach (Customer customer2 in customers) { CustSecret custSecret = new CustSecret(); custSecret.param1 = customer2.param1; custSecrets.Add(custSecret); } return(Request.CreateResponse(HttpStatusCode.Created, custSecrets)); } } customers.Add(customer); return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.NotFound)); } }
public void SortByStartTest() { DateTime now = ClockProxy.Clock.Now; SchoolDay schoolDay = new SchoolDay(now); TimePeriodCollection timePeriods = new TimePeriodCollection(); timePeriods.Add(schoolDay.Lesson4); timePeriods.Add(schoolDay.Break3); timePeriods.Add(schoolDay.Lesson3); timePeriods.Add(schoolDay.Break2); timePeriods.Add(schoolDay.Lesson2); timePeriods.Add(schoolDay.Break1); timePeriods.Add(schoolDay.Lesson1); timePeriods.SortByStart(ListSortDirection.Descending); Assert.Equal(timePeriods[0], schoolDay.Lesson4); Assert.Equal(timePeriods[1], schoolDay.Break3); Assert.Equal(timePeriods[2], schoolDay.Lesson3); Assert.Equal(timePeriods[3], schoolDay.Break2); Assert.Equal(timePeriods[4], schoolDay.Lesson2); Assert.Equal(timePeriods[5], schoolDay.Break1); Assert.Equal(timePeriods[6], schoolDay.Lesson1); timePeriods.SortByStart(); Assert.Equal(timePeriods[0], schoolDay.Lesson1); Assert.Equal(timePeriods[1], schoolDay.Break1); Assert.Equal(timePeriods[2], schoolDay.Lesson2); Assert.Equal(timePeriods[3], schoolDay.Break2); Assert.Equal(timePeriods[4], schoolDay.Lesson3); Assert.Equal(timePeriods[5], schoolDay.Break3); Assert.Equal(timePeriods[6], schoolDay.Lesson4); } // SortByStartTest
public void IntersectionPeriodsTimePeriodTest() { DateTime now = ClockProxy.Clock.Now; TimeRange timeRange1 = new TimeRange(new DateTime(now.Year, now.Month, 8), new DateTime(now.Year, now.Month, 18)); TimeRange timeRange2 = new TimeRange(new DateTime(now.Year, now.Month, 10), new DateTime(now.Year, now.Month, 11)); TimeRange timeRange3 = new TimeRange(new DateTime(now.Year, now.Month, 13), new DateTime(now.Year, now.Month, 15)); TimeRange timeRange4 = new TimeRange(new DateTime(now.Year, now.Month, 9), new DateTime(now.Year, now.Month, 13)); TimeRange timeRange5 = new TimeRange(new DateTime(now.Year, now.Month, 15), new DateTime(now.Year, now.Month, 17)); TimePeriodCollection timePeriods = new TimePeriodCollection(); timePeriods.Add(timeRange1); timePeriods.Add(timeRange2); timePeriods.Add(timeRange3); timePeriods.Add(timeRange4); timePeriods.Add(timeRange5); Assert.Equal(5, timePeriods.IntersectionPeriods(timeRange1).Count); Assert.Equal(3, timePeriods.IntersectionPeriods(timeRange2).Count); Assert.Equal(4, timePeriods.IntersectionPeriods(timeRange3).Count); Assert.Equal(4, timePeriods.IntersectionPeriods(timeRange4).Count); Assert.Equal(3, timePeriods.IntersectionPeriods(timeRange5).Count); ITimeRange test1 = timeRange1.Copy(new TimeSpan(100, 0, 0, 0).Negate()); ITimePeriodCollection insidePeriods1 = timePeriods.IntersectionPeriods(test1); Assert.Equal(0, insidePeriods1.Count); ITimeRange test2 = timeRange1.Copy(new TimeSpan(100, 0, 0, 0)); ITimePeriodCollection insidePeriods2 = timePeriods.IntersectionPeriods(test2); Assert.Equal(0, insidePeriods2.Count); TimeRange test3 = new TimeRange(new DateTime(now.Year, now.Month, 9), new DateTime(now.Year, now.Month, 11)); ITimePeriodCollection insidePeriods3 = timePeriods.IntersectionPeriods(test3); Assert.Equal(3, insidePeriods3.Count); TimeRange test4 = new TimeRange(new DateTime(now.Year, now.Month, 14), new DateTime(now.Year, now.Month, 17)); ITimePeriodCollection insidePeriods4 = timePeriods.IntersectionPeriods(test4); Assert.Equal(3, insidePeriods4.Count); } // IntersectionPeriodsTimePeriodTest
public void TotalDurationTest() { DateTime now = ClockProxy.Clock.Now; TimeRange timeRange1 = new TimeRange(new DateTime(now.Year, now.Month, 8), new DateTime(now.Year, now.Month, 18)); TimeRange timeRange2 = new TimeRange(new DateTime(now.Year, now.Month, 10), new DateTime(now.Year, now.Month, 11)); TimePeriodCollection timePeriods = new TimePeriodCollection(); Assert.Equal <TimeSpan>(timePeriods.TotalDuration, TimeSpan.Zero); timePeriods.Add(timeRange1); Assert.Equal(timePeriods.TotalDuration, timeRange1.End.Subtract(timeRange1.Start)); Assert.Equal(timePeriods.TotalDuration, timeRange1.Duration); timePeriods.Add(timeRange2); Assert.Equal(timePeriods.TotalDuration, timeRange1.End.Subtract(timeRange1.Start). Add(timeRange2.End.Subtract(timeRange2.Start))); Assert.Equal(timePeriods.TotalDuration, timeRange1.Duration.Add(timeRange2.Duration)); } // TotalDurationTest
/// <summary> /// ITimeLineMomentCollection으로부터 교집합에 해당하는 기간들을 구합니다 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="timeLineMoments"></param> /// <returns></returns> public static ITimePeriodCollection IntersectPeriods <T>(this ITimeLineMomentCollection timeLineMoments) where T : ITimePeriod { if (IsDebugEnabled) { log.Debug("ITimeLineMomentCollection으로부터 교집합에 해당하는 기간들을 구합니다..."); } var periods = new TimePeriodCollection(); if (timeLineMoments.IsEmpty) { return(periods); } // search for periods var intersectionStart = -1; var balance = 0; for (var i = 0; i < timeLineMoments.Count; i++) { var moment = timeLineMoments[i]; balance += moment.StartCount; balance -= moment.EndCount; // intersection is starting by a period start if (moment.StartCount > 0 && balance > 1 && intersectionStart < 0) { intersectionStart = i; continue; } // intersection is starting by a period end if (moment.EndCount > 0 && balance <= 1 && intersectionStart >= 0) { var period = ActivatorTool.CreateInstance <T>(); period.Setup(timeLineMoments[intersectionStart].Moment, moment.Moment); if (IsDebugEnabled) { log.Debug("Intersect Period를 추가합니다. period=[{0}]", period); } periods.Add(period); intersectionStart = -1; } } if (IsDebugEnabled) { log.Debug("ITimeLineMomentCollection으로부터 교집합에 해당하는 기간들을 구했습니다. periods=[{0}]", periods.CollectionToString()); } return(periods); }
public void HasGapsTest() { DateTime start1 = ClockProxy.Clock.Now.Date; DateTime end1 = start1.AddDays(1); DateTime start2 = end1; DateTime end2 = start2.AddDays(1); DateTime start3 = end2; DateTime end3 = start3.AddDays(1); DateTime start4 = end3; DateTime end4 = start4.AddDays(1); TimePeriodCollection periods = new TimePeriodCollection(); TimeLine <TimeRange> timeLineMoments = new TimeLine <TimeRange>(periods, null, null); Assert.AreEqual(false, timeLineMoments.HasGaps()); periods.Add(new TimeRange(start1, start1)); Assert.AreEqual(false, timeLineMoments.HasGaps()); periods.RemoveAt(periods.Count - 1); periods.Add(new TimeRange(start1, end1)); Assert.AreEqual(false, timeLineMoments.HasGaps()); periods.Add(new TimeRange(start1, end1)); Assert.AreEqual(false, timeLineMoments.HasGaps()); periods.RemoveAt(periods.Count - 1); Assert.AreEqual(false, timeLineMoments.HasGaps()); periods.Add(new TimeRange(start2, end2)); Assert.AreEqual(false, timeLineMoments.HasGaps()); periods.Add(new TimeRange(start1, end2)); Assert.AreEqual(false, timeLineMoments.HasGaps()); periods.RemoveAt(periods.Count - 1); Assert.AreEqual(false, timeLineMoments.HasGaps()); periods.Add(new TimeRange(start3, end3)); Assert.AreEqual(false, timeLineMoments.HasGaps()); periods.Add(new TimeRange(start4, end4)); Assert.AreEqual(false, timeLineMoments.HasGaps()); periods.RemoveAt(2); // start/end 3 Assert.AreEqual(true, timeLineMoments.HasGaps()); periods.RemoveAt(1); // start/end 1 Assert.AreEqual(true, timeLineMoments.HasGaps()); periods.RemoveAt(periods.Count - 1); // start/end 4 Assert.AreEqual(false, timeLineMoments.HasGaps()); periods.RemoveAt(0); Assert.AreEqual(false, timeLineMoments.HasGaps()); periods.Clear(); Assert.AreEqual(false, timeLineMoments.HasGaps()); } // HasGapsTest
public void DurationTest() { TimePeriodCollection timePeriods = new TimePeriodCollection(); Assert.Equal(timePeriods.Duration, TimeSpec.MaxPeriodDuration); TimeSpan duration = Duration.Hour; timePeriods.Add(new TimeBlock(ClockProxy.Clock.Now, duration)); Assert.Equal <TimeSpan>(timePeriods.Duration, duration); } // DurationTest
public void IsAnytimeTest() { var now = ClockProxy.Clock.Now; var timePeriods = new TimePeriodCollection(); Assert.IsTrue(timePeriods.IsAnytime); timePeriods.Add(TimeRange.Anytime); Assert.IsTrue(timePeriods.IsAnytime); timePeriods.Clear(); Assert.IsTrue(timePeriods.IsAnytime); timePeriods.Add(new TimeRange(TimeSpec.MinPeriodTime, now)); Assert.IsFalse(timePeriods.IsAnytime); timePeriods.Add(new TimeRange(now, TimeSpec.MaxPeriodTime)); Assert.IsTrue(timePeriods.IsAnytime); timePeriods.Clear(); Assert.IsTrue(timePeriods.IsAnytime); }
public void GetGapTest() { var now = ClockProxy.Clock.Now; var schoolDay = new SchoolDay(now); var gapCalculator = new TimeGapCalculator<TimeRange>(); var excludePeriods = new TimePeriodCollection(); excludePeriods.AddAll(schoolDay); gapCalculator.GetGaps(excludePeriods).Count.Should().Be(0); gapCalculator.GetGaps(excludePeriods, schoolDay).Count.Should().Be(0); excludePeriods.Clear(); excludePeriods.Add(schoolDay.Lesson1); excludePeriods.Add(schoolDay.Lesson2); excludePeriods.Add(schoolDay.Lesson3); excludePeriods.Add(schoolDay.Lesson4); var gaps2 = gapCalculator.GetGaps(excludePeriods); gaps2.Count.Should().Be(3); gaps2[0].IsSamePeriod(schoolDay.Break1).Should().Be.True(); gaps2[1].IsSamePeriod(schoolDay.Break2).Should().Be.True(); gaps2[2].IsSamePeriod(schoolDay.Break3).Should().Be.True(); var testRange3 = new TimeRange(schoolDay.Lesson1.Start, schoolDay.Lesson4.End); var gaps3 = gapCalculator.GetGaps(excludePeriods, testRange3); gaps3.Count.Should().Be(3); gaps3[0].IsSamePeriod(schoolDay.Break1).Should().Be.True(); gaps3[1].IsSamePeriod(schoolDay.Break2).Should().Be.True(); gaps3[2].IsSamePeriod(schoolDay.Break3).Should().Be.True(); var testRange4 = new TimeRange(schoolDay.Start.AddHours(-1), schoolDay.End.AddHours(1)); var gaps4 = gapCalculator.GetGaps(excludePeriods, testRange4); gaps4.Count.Should().Be(5); gaps4[0].IsSamePeriod(new TimeRange(testRange4.Start, schoolDay.Start)).Should().Be.True(); gaps4[1].IsSamePeriod(schoolDay.Break1).Should().Be.True(); gaps4[2].IsSamePeriod(schoolDay.Break2).Should().Be.True(); gaps4[3].IsSamePeriod(schoolDay.Break3).Should().Be.True(); gaps4[4].IsSamePeriod(new TimeRange(testRange4.End, schoolDay.End)).Should().Be.True(); excludePeriods.Clear(); excludePeriods.Add(schoolDay.Lesson1); var gaps8 = gapCalculator.GetGaps(excludePeriods, schoolDay.Lesson1); gaps8.Count.Should().Be(0); excludePeriods.Clear(); excludePeriods.Add(schoolDay.Lesson1); var testRange9 = new TimeRange(schoolDay.Lesson1.Start.Subtract(new TimeSpan(1)), schoolDay.Lesson1.End.Add(new TimeSpan(1))); var gaps9 = gapCalculator.GetGaps(excludePeriods, testRange9); gaps9.Count.Should().Be(2); gaps9[0].Duration.Should().Be(TimeSpan.FromTicks(1)); gaps9[1].Duration.Should().Be(TimeSpan.FromTicks(1)); }
public void HasStartTest() { TimePeriodCollection timePeriods = new TimePeriodCollection(); Assert.IsFalse(timePeriods.HasStart); timePeriods.Add(new TimeBlock(TimeSpec.MinPeriodTime, DurationUtil.Hour)); Assert.IsFalse(timePeriods.HasStart); timePeriods.Clear(); timePeriods.Add(new TimeBlock(ClockProxy.Clock.Now, DurationUtil.Hour)); Assert.IsTrue(timePeriods.HasStart); }
/// <summary> /// <paramref name="start"/>시각으로부터 <paramref name="offset"/> 만큼 떨어진 시각을 구합니다. /// </summary> /// <param name="start">기준 시각</param> /// <param name="offset">기간</param> /// <param name="seekDirection">검색 방향 (이전|이후)</param> /// <param name="seekBoundaryMode">검색 값 포함 여부</param> /// <param name="remaining">짜투리 기간</param> /// <returns>기준 시각으로터 오프셋만큼 떨어진 시각</returns> protected DateTime? CalculateEnd(DateTime start, TimeSpan offset, SeekDirection seekDirection, SeekBoundaryMode seekBoundaryMode, out TimeSpan? remaining) { if(IsDebugEnabled) log.Debug("기준시각으로부터 오프셋만큼 떨어진 시각을 구합니다... " + @"start=[{0}], offset=[{1}], seekDirection=[{2}], seekBoundaryMode=[{3}]", start, offset, seekDirection, seekBoundaryMode); Guard.Assert(offset >= TimeSpan.Zero, "offset 값은 항상 0 이상이어야 합니다. offset=[{0}]", offset); remaining = offset; // search periods ITimePeriodCollection searchPeriods = new TimePeriodCollection(IncludePeriods); if(searchPeriods.Count == 0) searchPeriods.Add(TimeRange.Anytime); // available periods ITimePeriodCollection availablePeriods = new TimePeriodCollection(); if(ExcludePeriods.Count == 0) { availablePeriods.AddAll(searchPeriods); } else { // 예외 기간을 제외합니다. // var gapCalculator = new TimeGapCalculator<TimeRange>(); var query = searchPeriods #if !SILVERLIGHT .AsParallel() .AsOrdered() #endif .SelectMany(searchPeriod => ExcludePeriods.HasOverlapPeriods(searchPeriod) ? gapCalculator.GetGaps(ExcludePeriods, searchPeriod) // 예외 기간과 검색 기간에서 겹치지 않는 기간을 계산하여, 추려냅니다. : new TimePeriodCollection { searchPeriod } // 예외 기간과 겹쳐진 부분이 없다면, 기간 전체를 추가합니다. ); availablePeriods.AddAll(query); } // 유효한 Period가 없다면 중단합니다. if(availablePeriods.Count == 0) return null; // 기간중에 중복되는 부분의 없도록 유효한 기간을 결합합니다. if(availablePeriods.Count > 1) { var periodCombiner = new TimePeriodCombiner<TimeRange>(); availablePeriods = periodCombiner.CombinePeriods(availablePeriods); } // 첫 시작 기간을 찾습니다. // DateTime seekMoment; var startPeriod = (seekDirection == SeekDirection.Forward) ? FindNextPeriod(start, availablePeriods, out seekMoment) : FindPreviousPeriod(start, availablePeriods, out seekMoment); // 첫 시작 기간이 없다면 중단합니다. if(startPeriod == null) return null; // 오프셋 값이 0 이라면, 바로 다음 값이므로 seekMoment를 반환합니다. if(offset == TimeSpan.Zero) return seekMoment; if(seekDirection == SeekDirection.Forward) { for(var i = availablePeriods.IndexOf(startPeriod); i < availablePeriods.Count; i++) { var gap = availablePeriods[i]; var gapRemaining = gap.End - seekMoment; if(IsDebugEnabled) log.Debug("Seek Forward... gap=[{0}], gapRemaining=[{1}], remaining=[{2}], seekMoment=[{3}]", gap, gapRemaining, remaining, seekMoment); var isTargetPeriod = (seekBoundaryMode == SeekBoundaryMode.Fill) ? gapRemaining >= remaining : gapRemaining > remaining; if(isTargetPeriod) { var end = seekMoment + remaining.Value; remaining = null; return end; } remaining = remaining - gapRemaining; if(i == availablePeriods.Count - 1) return null; seekMoment = availablePeriods[i + 1].Start; // next period } } else { for(var i = availablePeriods.IndexOf(startPeriod); i >= 0; i--) { var gap = availablePeriods[i]; var gapRemaining = seekMoment - gap.Start; if(IsDebugEnabled) log.Debug("Seek Backward... gap=[{0}], gapRemaining=[{1}], remaining=[{2}], seekMoment=[{3}]", gap, gapRemaining, remaining, seekMoment); var isTargetPeriod = (seekBoundaryMode == SeekBoundaryMode.Fill) ? gapRemaining >= remaining : gapRemaining > remaining; if(isTargetPeriod) { var end = seekMoment - remaining.Value; remaining = null; return end; } remaining = remaining - gapRemaining; if(i == 0) return null; seekMoment = availablePeriods[i - 1].End; // previous period } } return null; }
public void StartTest() { var now = ClockProxy.Clock.Now; var timePeriods = new TimePeriodCollection(); Assert.AreEqual(timePeriods.Start, TimeSpec.MinPeriodTime); timePeriods.Add(new TimeBlock(now, DurationUtil.Hour)); Assert.AreEqual(timePeriods.Start, now); Assert.AreEqual(timePeriods.End, now.AddHours(1)); timePeriods.Clear(); Assert.AreEqual(timePeriods.Start, TimeSpec.MinPeriodTime); }
public void DurationTest() { var timePeriods = new TimePeriodCollection(); timePeriods.Duration.Should().Be(TimeSpec.MaxPeriodDuration); var duration = DurationUtil.Hour; timePeriods.Add(new TimeBlock(ClockProxy.Clock.Now, duration)); timePeriods.Duration.Should().Be(duration); }
public void EndTest() { var now = ClockProxy.Clock.Now; var timePeriods = new TimePeriodCollection(); timePeriods.End.Should().Be(TimeSpec.MaxPeriodTime); timePeriods.Add(new TimeBlock(DurationUtil.Hour, now)); timePeriods.End.Should().Be(now); timePeriods.Clear(); timePeriods.End.Should().Be(TimeSpec.MaxPeriodTime); }
public void ContainsPeriodTest() { var now = ClockProxy.Clock.Now; var schoolDay = new SchoolDay(now); var timePeriods = new TimePeriodCollection(schoolDay); var timeRange = new TimeRange(schoolDay.Lesson1.Start, schoolDay.Lesson1.End); Assert.IsFalse(timePeriods.Contains(timeRange)); Assert.IsTrue(timePeriods.ContainsPeriod(timeRange)); timePeriods.Add(timeRange); Assert.IsTrue(timePeriods.Contains(timeRange)); Assert.IsTrue(timePeriods.ContainsPeriod(timeRange)); }
public void RemoveTest() { var now = ClockProxy.Clock.Now; var schoolDay = new SchoolDay(now); var timePeriods = new TimePeriodCollection(); Assert.IsFalse(timePeriods.Contains(schoolDay.Lesson1)); timePeriods.Add(schoolDay.Lesson1); Assert.IsTrue(timePeriods.Contains(schoolDay.Lesson1)); timePeriods.Remove(schoolDay.Lesson1); Assert.IsFalse(timePeriods.Contains(schoolDay.Lesson1)); }
public void IsMomentTest() { var now = ClockProxy.Clock.Now; var timePeriods = new TimePeriodCollection(); Assert.IsFalse(timePeriods.IsMoment); timePeriods.Add(TimeRange.Anytime); Assert.IsFalse(timePeriods.IsMoment); timePeriods.Clear(); Assert.IsFalse(timePeriods.IsMoment); timePeriods.Add(new TimeRange(now)); Assert.IsTrue(timePeriods.IsMoment); timePeriods.Add(new TimeRange(now)); Assert.IsTrue(timePeriods.IsMoment); timePeriods.Clear(); Assert.IsTrue(timePeriods.IsAnytime); }