// ---------------------------------------------------------------------- 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 SortByEndTest() { DateTime now = ClockProxy.Clock.Now; SchoolDay schoolDay = new SchoolDay(now); TimePeriodCollection timePeriods = new TimePeriodCollection(); timePeriods.AddAll(schoolDay); timePeriods.SortByEnd(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.SortByEnd(); 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); } // SortByEndTest
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() { var now = ClockProxy.Clock.Now; var timeRange1 = new TimeRange(new DateTime(now.Year, now.Month, 8), new DateTime(now.Year, now.Month, 18)); var timeRange2 = new TimeRange(new DateTime(now.Year, now.Month, 10), new DateTime(now.Year, now.Month, 11)); var timeRange3 = new TimeRange(new DateTime(now.Year, now.Month, 13), new DateTime(now.Year, now.Month, 15)); var timeRange4 = new TimeRange(new DateTime(now.Year, now.Month, 9), new DateTime(now.Year, now.Month, 14)); var timeRange5 = new TimeRange(new DateTime(now.Year, now.Month, 16), new DateTime(now.Year, now.Month, 17)); TimePeriodCollection timePeriods = new TimePeriodCollection { timeRange1, timeRange2, timeRange3, timeRange4, timeRange5 }; timePeriods.RelationPeriods(timeRange1, PeriodRelation.ExactMatch).Count().Should().Be(1); timePeriods.RelationPeriods(timeRange2, PeriodRelation.ExactMatch).Count().Should().Be(1); timePeriods.RelationPeriods(timeRange3, PeriodRelation.ExactMatch).Count().Should().Be(1); timePeriods.RelationPeriods(timeRange4, PeriodRelation.ExactMatch).Count().Should().Be(1); timePeriods.RelationPeriods(timeRange5, PeriodRelation.ExactMatch).Count().Should().Be(1); // all Assert.AreEqual( timePeriods.RelationPeriods(new TimeRange(new DateTime(now.Year, now.Month, 7), new DateTime(now.Year, now.Month, 19)), PeriodRelation.Enclosing).Count(), 5); // timerange3 Assert.AreEqual( timePeriods.RelationPeriods( new TimeRange(new DateTime(now.Year, now.Month, 11), new DateTime(now.Year, now.Month, 16)), PeriodRelation.Enclosing).Count(), 1); }
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 async Task WithTaskFactory_When_Tasks_Added_Then_Execution_Time_Of_The_Tasks_Does_Not_Intersect() { const int NUMBER_OF_TASKS = 100; const int DEFAULT_THREAD_SLEEP = 20; const int BEGIN_TASK_THREAD_SLEEP = 1; var tasks = Enumerable.Range(0, NUMBER_OF_TASKS) .Select(i => TestTaskFactory.StartNew(() => { Thread.Sleep(BEGIN_TASK_THREAD_SLEEP); var startTime = DateTime.Now; var duration = StopWatchUtils.MeasureActionTime(() => Thread.Sleep(DEFAULT_THREAD_SLEEP)); return(new TimeRange(startTime, duration, isReadOnly: true)); })) .ToArray(); await Task.WhenAll(tasks); var timeRanges = tasks.Select(task => task.Result); var timePeriodCollection = new TimePeriodCollection(timeRanges); var timePeriodIntersector = new TimePeriodIntersector <TimeRange>(); var intersectPeriods = timePeriodIntersector.IntersectPeriods(timePeriodCollection); Assert.IsTrue(!intersectPeriods.Any()); }
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
/// <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)); }
} // 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 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
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 static void TestTimeGap() { var schedule = new TimeBlock(new DateTime(2018, 10, 10, 08, 30, 00), Duration.Minutes(180)); var bookings = new TimePeriodCollection { new TimeRange(new DateTime(2018, 10, 10, 08, 00, 0), Duration.Minutes(60)), new TimeRange(new DateTime(2018, 10, 10, 09, 30, 0), Duration.Minutes(30)), new TimeRange(new DateTime(2018, 10, 10, 10, 00, 0), Duration.Minutes(30)), }; var selected = new TimeBlock(new DateTime(2018, 10, 10, 09, 30, 0), Duration.Minutes(30)); Console.WriteLine($"Selected: {selected}"); Console.WriteLine(); // calculate the gaps using the time calendar as period mapper var availableTimes = new TimeGapCalculator <TimeBlock>() .GetGaps(bookings, schedule) .Where(t => t.Duration >= selected.Duration) .SelectMany(t => t.Split(selected.Duration)); foreach (var t in availableTimes) { Console.WriteLine($"Result: {t}"); } }
public void CalendarGetGapTest() { // simmulation of some reservations var periods = new TimePeriodCollection { new DayRangeCollection(2011, 3, 7, 2), new DayRangeCollection(2011, 3, 16, 2) }; // the overall search range var limits = new CalendarTimeRange(new DateTime(2011, 3, 4), new DateTime(2011, 3, 21)); var days = new DayRangeCollection(limits.Start, limits.Duration.Days + 1); // limits의 내부이고, 주말인 DayRange를 추가합니다. var excludeDays = days.GetDays().Where(day => limits.HasInside(day) && day.DayOfWeek.IsWeekEnd()); periods.AddAll(excludeDays.Cast <ITimePeriod>()); var gapCalculator = new TimeGapCalculator <TimeRange>(new TimeCalendar()); var gaps = gapCalculator.GetGaps(periods, limits); gaps.Count.Should().Be(4); gaps[0].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 4), DurationUtil.Days(1))).Should().Be.True(); gaps[1].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 9), DurationUtil.Days(3))).Should().Be.True(); gaps[2].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 14), DurationUtil.Days(2))).Should().Be.True(); gaps[3].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 18), DurationUtil.Days(1))).Should().Be.True(); }
private static decimal GetOverlapFactor(TimeRange period, ITimeRange reference, bool toReference) { TimePeriodCollection periods = new TimePeriodCollection { reference, period }; TimePeriodIntersector <TimeRange> periodIntersector = new TimePeriodIntersector <TimeRange>(); ITimePeriodCollection intersectedPeriods = periodIntersector.IntersectPeriods(periods); try { if (toReference) { return((decimal)intersectedPeriods.TotalDuration.TotalSeconds / (decimal)reference.Duration.TotalSeconds); } else // to self { return((decimal)intersectedPeriods.TotalDuration.TotalSeconds / (decimal)period.Duration.TotalSeconds); } } catch (DivideByZeroException) { return(0.0M); } }
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 CopyConstructorTest() { var timePeriods = new TimePeriodCollection(_timeRangeTestData.AllPeriods); timePeriods.Count.Should().Be(_timeRangeTestData.AllPeriods.Count); timePeriods.HasStart.Should().Be.True(); timePeriods.HasEnd.Should().Be.True(); timePeriods.IsReadOnly.Should().Be.False(); }
public void DefaultConstructorTest() { var timePeriods = new TimePeriodCollection(); timePeriods.Count.Should().Be(0); timePeriods.HasStart.Should().Be.False(); timePeriods.HasEnd.Should().Be.False(); timePeriods.IsReadOnly.Should().Be.False(); }
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 DefaultConstructorTest() { TimePeriodCollection timePeriods = new TimePeriodCollection(); Assert.Equal(0, timePeriods.Count); Assert.False(timePeriods.HasStart); Assert.False(timePeriods.HasEnd); Assert.False(timePeriods.IsReadOnly); } // DefaultConstructorTest
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 CopyConstructorTest() { TimePeriodCollection timePeriods = new TimePeriodCollection(timeRangeTestData.AllPeriods); Assert.Equal <int>(timePeriods.Count, timeRangeTestData.AllPeriods.Count); Assert.True(timePeriods.HasStart); Assert.True(timePeriods.HasEnd); Assert.False(timePeriods.IsReadOnly); } // CopyConstructorTest
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 CountTest() { var timePeriods = new TimePeriodCollection(); timePeriods.Count.Should().Be(0); timePeriods.AddAll(_timeRangeTestData.AllPeriods); timePeriods.Count.Should().Be(_timeRangeTestData.AllPeriods.Count); timePeriods.Clear(); timePeriods.Count.Should().Be(0); }
public void PeriodEqualsLimitsTest() { var limits = new TimeRange(new DateTime(2011, 3, 1), new DateTime(2011, 3, 5)); var gapCalculator = new TimeGapCalculator<TimeRange>(); var excludePeriods = new TimePeriodCollection { limits }; var gaps = gapCalculator.GetGaps(excludePeriods, limits); gaps.Count.Should().Be(0); }
/// <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); }
} // FirstDayOfWeek // ---------------------------------------------------------------------- public ITimePeriodCollection GetDays() { TimePeriodCollection days = new TimePeriodCollection(); DateTime startDate = new DateTime(Start.Year, Start.Month, Start.Day); for (int day = 0; day < TimeSpec.DaysPerWeek; day++) { days.Add(new Day(startDate.AddDays(day), Calendar)); } return(days); } // GetDays
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 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 CountTest() { TimePeriodCollection timePeriods = new TimePeriodCollection(); Assert.Equal(0, timePeriods.Count); timePeriods.AddAll(timeRangeTestData.AllPeriods); Assert.Equal <int>(timePeriods.Count, timeRangeTestData.AllPeriods.Count); timePeriods.Clear(); Assert.Equal(0, timePeriods.Count); } // CountTest
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 RemoveTest() { DateTime now = ClockProxy.Clock.Now; SchoolDay schoolDay = new SchoolDay(now); TimePeriodCollection timePeriods = new TimePeriodCollection(); Assert.False(timePeriods.Contains(schoolDay.Lesson1)); timePeriods.Add(schoolDay.Lesson1); Assert.True(timePeriods.Contains(schoolDay.Lesson1)); timePeriods.Remove(schoolDay.Lesson1); Assert.False(timePeriods.Contains(schoolDay.Lesson1)); } // RemoveTest
public void ItemIndexTest() { var timePeriods = new TimePeriodCollection(); var schoolDay = new SchoolDay(); timePeriods.AddAll(schoolDay); Assert.AreEqual(timePeriods[0], schoolDay.Lesson1); Assert.AreEqual(timePeriods[1], schoolDay.Break1); Assert.AreEqual(timePeriods[2], schoolDay.Lesson2); Assert.AreEqual(timePeriods[3], schoolDay.Break2); Assert.AreEqual(timePeriods[4], schoolDay.Lesson3); Assert.AreEqual(timePeriods[5], schoolDay.Break3); Assert.AreEqual(timePeriods[6], schoolDay.Lesson4); }
public void PeriodOutsideTouchingLimitsTest() { var limits = new MonthRange(2011, 3); // new TimeRange(new DateTime(2011, 3, 1), new DateTime(2011, 3, 31)); var gapCalculator = new TimeGapCalculator<TimeRange>(); var excludePeriods = new TimePeriodCollection { new TimeRange(new DateTime(2011, 2, 1), new DateTime(2011, 3, 5)), new TimeRange(new DateTime(2011, 3, 20), new DateTime(2011, 4, 15)) }; var gaps = gapCalculator.GetGaps(excludePeriods, limits); gaps.Count.Should().Be(1); gaps[0].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 5), new DateTime(2011, 3, 20))).Should().Be.True(); }
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 EndMoveTest() { var schoolDay = new SchoolDay(); var timePeriods = new TimePeriodCollection(schoolDay); var end = schoolDay.End; timePeriods.End = end.AddHours(0); timePeriods.End.Should().Be(end); timePeriods.End = end.AddHours(1); timePeriods.End.Should().Be(end.AddHours(1)); timePeriods.End = end.AddHours(-1); timePeriods.End.Should().Be(end.AddHours(-1)); }
public void MoveTest() { var now = ClockProxy.Clock.Now; var schoolDay = new SchoolDay(now); var timePeriods = new TimePeriodCollection(schoolDay); var startDate = schoolDay.Start; var endDate = schoolDay.End; var startDuration = timePeriods.Duration; var duration = DurationUtil.Hour; timePeriods.Move(duration); timePeriods.Start.Should().Be(startDate.Add(duration)); timePeriods.End.Should().Be(endDate.Add(duration)); timePeriods.Duration.Should().Be(startDuration); }
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 GetRelationTest() { var now = ClockProxy.Clock.Now; var offset = DurationUtil.Second; var testData = new TimeRangePeriodRelationTestData(now, now.AddHours(1), offset); var timePeriods = new TimePeriodCollection { testData.Reference }; timePeriods.GetRelation(testData.Before).Should().Be(PeriodRelation.Before); timePeriods.GetRelation(testData.StartTouching).Should().Be(PeriodRelation.StartTouching); timePeriods.GetRelation(testData.StartInside).Should().Be(PeriodRelation.StartInside); timePeriods.GetRelation(testData.InsideStartTouching).Should().Be(PeriodRelation.InsideStartTouching); timePeriods.GetRelation(testData.EnclosingStartTouching).Should().Be(PeriodRelation.EnclosingStartTouching); timePeriods.GetRelation(testData.Enclosing).Should().Be(PeriodRelation.Enclosing); timePeriods.GetRelation(testData.EnclosingEndTouching).Should().Be(PeriodRelation.EnclosingEndTouching); timePeriods.GetRelation(testData.ExactMatch).Should().Be(PeriodRelation.ExactMatch); timePeriods.GetRelation(testData.Inside).Should().Be(PeriodRelation.Inside); timePeriods.GetRelation(testData.InsideEndTouching).Should().Be(PeriodRelation.InsideEndTouching); timePeriods.GetRelation(testData.EndInside).Should().Be(PeriodRelation.EndInside); timePeriods.GetRelation(testData.EndTouching).Should().Be(PeriodRelation.EndTouching); timePeriods.GetRelation(testData.After).Should().Be(PeriodRelation.After); }
public void CalendarGetGapTest() { // simmulation of some reservations var periods = new TimePeriodCollection { new DayRangeCollection(2011, 3, 7, 2), new DayRangeCollection(2011, 3, 16, 2) }; // the overall search range var limits = new CalendarTimeRange(new DateTime(2011, 3, 4), new DateTime(2011, 3, 21)); var days = new DayRangeCollection(limits.Start, limits.Duration.Days + 1); // limits의 내부이고, 주말인 DayRange를 추가합니다. var excludeDays = days.GetDays().Where(day => limits.HasInside(day) && day.DayOfWeek.IsWeekEnd()); periods.AddAll(excludeDays.Cast<ITimePeriod>()); var gapCalculator = new TimeGapCalculator<TimeRange>(new TimeCalendar()); var gaps = gapCalculator.GetGaps(periods, limits); gaps.Count.Should().Be(4); gaps[0].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 4), DurationUtil.Days(1))).Should().Be.True(); gaps[1].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 9), DurationUtil.Days(3))).Should().Be.True(); gaps[2].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 14), DurationUtil.Days(2))).Should().Be.True(); gaps[3].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 18), DurationUtil.Days(1))).Should().Be.True(); }
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 IndexOfTest() { var now = ClockProxy.Clock.Now; var schoolDay = new SchoolDay(now); var timePeriods = new TimePeriodCollection(); timePeriods.IndexOf(new TimeRange()).Should().Be(-1); timePeriods.IndexOf(new TimeBlock()).Should().Be(-1); timePeriods.AddAll(schoolDay); timePeriods.IndexOf(schoolDay.Lesson1).Should().Be(0); timePeriods.IndexOf(schoolDay.Break1).Should().Be(1); timePeriods.IndexOf(schoolDay.Lesson2).Should().Be(2); timePeriods.IndexOf(schoolDay.Break2).Should().Be(3); timePeriods.IndexOf(schoolDay.Lesson3).Should().Be(4); timePeriods.IndexOf(schoolDay.Break3).Should().Be(5); timePeriods.IndexOf(schoolDay.Lesson4).Should().Be(6); timePeriods.Remove(schoolDay.Lesson1); timePeriods.IndexOf(schoolDay.Lesson1).Should().Be(-1); timePeriods.IndexOf(schoolDay.Break1).Should().Be(0); }
public void CopyToTest() { var now = ClockProxy.Clock.Now; var schoolDay = new SchoolDay(now); var timePeriods = new TimePeriodCollection(schoolDay); var array = new ITimePeriod[schoolDay.Count]; timePeriods.CopyTo(array, 0); array[0].Should().Be(schoolDay.Lesson1); array[1].Should().Be(schoolDay.Break1); array[2].Should().Be(schoolDay.Lesson2); array[3].Should().Be(schoolDay.Break2); array[4].Should().Be(schoolDay.Lesson3); array[5].Should().Be(schoolDay.Break3); array[6].Should().Be(schoolDay.Lesson4); }
public void SimleGapsTest() { var limits = new TimeRange(new DateTime(2011, 3, 1), new DateTime(2011, 3, 20)); var gapCalculator = new TimeGapCalculator<TimeRange>(); var excludeRange = new TimeRange(new DateTime(2011, 3, 10), new DateTime(2011, 3, 15)); var excludePeriods = new TimePeriodCollection { excludeRange }; var gaps = gapCalculator.GetGaps(excludePeriods, limits); gaps.Count.Should().Be(2); gaps[0].IsSamePeriod(new TimeRange(limits.Start, excludeRange.Start)).Should().Be.True(); gaps[1].IsSamePeriod(new TimeRange(excludeRange.End, limits.End)).Should().Be.True(); }
public void RemoveAtTest() { var now = ClockProxy.Clock.Now; var schoolDay = new SchoolDay(now); var timePeriods = new TimePeriodCollection(schoolDay); // inside timePeriods[2].Should().Be(schoolDay.Lesson2); timePeriods.RemoveAt(2); timePeriods[2].Should().Be(schoolDay.Break2); // first timePeriods[0].Should().Be(schoolDay.Lesson1); timePeriods.RemoveAt(0); timePeriods[0].Should().Be(schoolDay.Break1); // last timePeriods[timePeriods.Count - 1].Should().Be(schoolDay.Lesson4); timePeriods.RemoveAt(timePeriods.Count - 1); timePeriods[timePeriods.Count - 1].Should().Be(schoolDay.Break3); }
public void IsSamePeriodTest() { var now = ClockProxy.Clock.Now; var schoolDay = new SchoolDay(now); var timePeriods = new TimePeriodCollection(schoolDay); Assert.IsTrue(timePeriods.IsSamePeriod(timePeriods)); Assert.IsTrue(timePeriods.IsSamePeriod(schoolDay)); Assert.IsTrue(schoolDay.IsSamePeriod(schoolDay)); Assert.IsTrue(schoolDay.IsSamePeriod(timePeriods)); Assert.IsFalse(timePeriods.IsSamePeriod(TimeBlock.Anytime)); Assert.IsFalse(schoolDay.IsSamePeriod(TimeBlock.Anytime)); timePeriods.RemoveAt(0); Assert.IsFalse(timePeriods.IsSamePeriod(schoolDay)); }
public void OverlapsWithTest() { var now = ClockProxy.Clock.Now; var offset = DurationUtil.Second; var testData = new TimeRangePeriodRelationTestData(now, now.AddHours(1), offset); var timePeriods = new TimePeriodCollection { testData.Reference }; Assert.IsFalse(timePeriods.OverlapsWith(testData.Before)); Assert.IsFalse(timePeriods.OverlapsWith(testData.StartTouching)); Assert.IsTrue(timePeriods.OverlapsWith(testData.StartInside)); Assert.IsTrue(timePeriods.OverlapsWith(testData.InsideStartTouching)); Assert.IsTrue(timePeriods.OverlapsWith(testData.EnclosingStartTouching)); Assert.IsTrue(timePeriods.OverlapsWith(testData.Enclosing)); Assert.IsTrue(timePeriods.OverlapsWith(testData.EnclosingEndTouching)); Assert.IsTrue(timePeriods.OverlapsWith(testData.ExactMatch)); Assert.IsTrue(timePeriods.OverlapsWith(testData.Inside)); Assert.IsTrue(timePeriods.OverlapsWith(testData.InsideEndTouching)); Assert.IsTrue(timePeriods.OverlapsWith(testData.EndInside)); Assert.IsFalse(timePeriods.OverlapsWith(testData.EndTouching)); Assert.IsFalse(timePeriods.OverlapsWith(testData.After)); }
public void MomentPeriodTest() { var limits = new TimeRange(new DateTime(2011, 3, 1), new DateTime(2011, 3, 20)); var gapCalculator = new TimeGapCalculator<TimeRange>(); var excludePeriods = new TimePeriodCollection { new TimeRange(new DateTime(2011, 3, 10), new DateTime(2011, 3, 10)) }; //! Gap 검사 시에 Moment는 제외된다!!! var gaps = gapCalculator.GetGaps(excludePeriods, limits); gaps.Count.Should().Be(1); gaps[0].IsSamePeriod(limits).Should().Be.True(); }
public void OverlappingPeriods3Test() { var limits = new TimeRange(new DateTime(2011, 3, 29), new DateTime(2011, 4, 1)); var gapCalculator = new TimeGapCalculator<TimeRange>(); var excludePeriods = new TimePeriodCollection { new TimeRange(new DateTime(2011, 3, 30, 00, 00, 0), new DateTime(2011, 3, 31, 00, 00, 0)), new TimeRange(new DateTime(2011, 3, 30, 00, 00, 0), new DateTime(2011, 3, 31, 00, 00, 0)) }; ITimePeriodCollection gaps = gapCalculator.GetGaps(excludePeriods, limits); gaps.Count.Should().Be(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)))); }
public void AddAllTest() { var now = ClockProxy.Clock.Now; var schoolDay = new SchoolDay(now); var timePeriods = new TimePeriodCollection(); timePeriods.Count.Should().Be(0); timePeriods.AddAll(schoolDay); timePeriods.Count.Should().Be(schoolDay.Count); timePeriods.Clear(); timePeriods.Count.Should().Be(0); }
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 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 ClearTest() { var timePeriods = new TimePeriodCollection(); timePeriods.Count.Should().Be(0); timePeriods.Clear(); timePeriods.Count.Should().Be(0); timePeriods.AddAll(new SchoolDay()); timePeriods.Count.Should().Be(7); timePeriods.Clear(); timePeriods.Count.Should().Be(0); }
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); }
public void PeriodTouchingLimitsStartTest() { var limits = new TimeRange(new DateTime(2011, 3, 1), new DateTime(2011, 3, 20)); var gapCalculator = new TimeGapCalculator<TimeRange>(); var excludePeriods = new TimePeriodCollection { new TimeRange(new DateTime(2011, 3, 1), new DateTime(2011, 3, 10)) }; var gaps = gapCalculator.GetGaps(excludePeriods, limits); gaps.Count.Should().Be(1); gaps[0].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 10), new DateTime(2011, 3, 20))).Should().Be.True(); }