public void OverlapPeriodsTest() { 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, 13)); var timeRange5 = new TimeRange(new DateTime(now.Year, now.Month, 15), new DateTime(now.Year, now.Month, 17)); var timePeriods = new TimePeriodCollection { timeRange1, timeRange2, timeRange3, timeRange4, timeRange5 }; timePeriods.OverlapPeriods(timeRange1).Count().Should().Be(5); timePeriods.OverlapPeriods(timeRange2).Count().Should().Be(3); timePeriods.OverlapPeriods(timeRange3).Count().Should().Be(2); timePeriods.OverlapPeriods(timeRange4).Count().Should().Be(3); timePeriods.OverlapPeriods(timeRange5).Count().Should().Be(2); var test1 = timeRange1.Copy(new TimeSpan(100, 0, 0, 0).Negate()); var insidePeriods1 = timePeriods.OverlapPeriods(test1).ToList(); insidePeriods1.Count.Should().Be(0); var test2 = timeRange1.Copy(new TimeSpan(100, 0, 0, 0)); var insidePeriods2 = timePeriods.OverlapPeriods(test2).ToList(); insidePeriods2.Count.Should().Be(0); var test3 = new TimeRange(new DateTime(now.Year, now.Month, 9), new DateTime(now.Year, now.Month, 11)); var insidePeriods3 = timePeriods.OverlapPeriods(test3).ToList(); insidePeriods3.Count.Should().Be(3); var test4 = new TimeRange(new DateTime(now.Year, now.Month, 14), new DateTime(now.Year, now.Month, 17)); var insidePeriods4 = timePeriods.OverlapPeriods(test4).ToList(); insidePeriods4.Count.Should().Be(3); }
public void OverlapPeriodsTest() { 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.OverlapPeriods(timeRange1).Count); Assert.Equal(3, timePeriods.OverlapPeriods(timeRange2).Count); Assert.Equal(2, timePeriods.OverlapPeriods(timeRange3).Count); Assert.Equal(3, timePeriods.OverlapPeriods(timeRange4).Count); Assert.Equal(2, timePeriods.OverlapPeriods(timeRange5).Count); ITimeRange test1 = timeRange1.Copy(new TimeSpan(100, 0, 0, 0).Negate()); ITimePeriodCollection insidePeriods1 = timePeriods.OverlapPeriods(test1); Assert.Equal(0, insidePeriods1.Count); ITimeRange test2 = timeRange1.Copy(new TimeSpan(100, 0, 0, 0)); ITimePeriodCollection insidePeriods2 = timePeriods.OverlapPeriods(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.OverlapPeriods(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.OverlapPeriods(test4); Assert.Equal(3, insidePeriods4.Count); } // OverlapPeriodsTest
public void OverlapPeriodsTest() { 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, 13)); var timeRange5 = new TimeRange(new DateTime(now.Year, now.Month, 15), new DateTime(now.Year, now.Month, 17)); var timePeriods = new TimePeriodCollection { timeRange1, timeRange2, timeRange3, timeRange4, timeRange5 }; timePeriods.OverlapPeriods(timeRange1).Count().Should().Be(5); timePeriods.OverlapPeriods(timeRange2).Count().Should().Be(3); timePeriods.OverlapPeriods(timeRange3).Count().Should().Be(2); timePeriods.OverlapPeriods(timeRange4).Count().Should().Be(3); timePeriods.OverlapPeriods(timeRange5).Count().Should().Be(2); var test1 = timeRange1.Copy(new TimeSpan(100, 0, 0, 0).Negate()); var insidePeriods1 = timePeriods.OverlapPeriods(test1).ToList(); insidePeriods1.Count.Should().Be(0); var test2 = timeRange1.Copy(new TimeSpan(100, 0, 0, 0)); var insidePeriods2 = timePeriods.OverlapPeriods(test2).ToList(); insidePeriods2.Count.Should().Be(0); var test3 = new TimeRange(new DateTime(now.Year, now.Month, 9), new DateTime(now.Year, now.Month, 11)); var insidePeriods3 = timePeriods.OverlapPeriods(test3).ToList(); insidePeriods3.Count.Should().Be(3); var test4 = new TimeRange(new DateTime(now.Year, now.Month, 14), new DateTime(now.Year, now.Month, 17)); var insidePeriods4 = timePeriods.OverlapPeriods(test4).ToList(); insidePeriods4.Count.Should().Be(3); }