Example #1
0
        public void InsidePeriodsTimePeriodTest()
        {
            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.InsidePeriods(timeRange1).Count);
            Assert.Equal(1, timePeriods.InsidePeriods(timeRange2).Count);
            Assert.Equal(1, timePeriods.InsidePeriods(timeRange3).Count);
            Assert.Equal(2, timePeriods.InsidePeriods(timeRange4).Count);
            Assert.Equal(1, timePeriods.InsidePeriods(timeRange5).Count);

            ITimeRange            test1          = timeRange1.Copy(new TimeSpan(100, 0, 0, 0).Negate());
            ITimePeriodCollection insidePeriods1 = timePeriods.InsidePeriods(test1);

            Assert.Equal(0, insidePeriods1.Count);

            ITimeRange            test2          = timeRange1.Copy(new TimeSpan(100, 0, 0, 0));
            ITimePeriodCollection insidePeriods2 = timePeriods.InsidePeriods(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.InsidePeriods(test3);

            Assert.Equal(1, insidePeriods3.Count);

            TimeRange             test4          = new TimeRange(new DateTime(now.Year, now.Month, 14), new DateTime(now.Year, now.Month, 17));
            ITimePeriodCollection insidePeriods4 = timePeriods.InsidePeriods(test4);

            Assert.Equal(1, insidePeriods4.Count);
        }         // InsidePeriodsTimePeriodTest
Example #2
0
        public void InsidePeriodsTimePeriodTest()
        {
            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));

            TimePeriodCollection timePeriods = new TimePeriodCollection {
                timeRange1, timeRange2, timeRange3, timeRange4, timeRange5
            };

            timePeriods.InsidePeriods(timeRange1).Count().Should().Be(5);
            timePeriods.InsidePeriods(timeRange2).Count().Should().Be(1);
            timePeriods.InsidePeriods(timeRange3).Count().Should().Be(1);
            timePeriods.InsidePeriods(timeRange4).Count().Should().Be(2);
            timePeriods.InsidePeriods(timeRange5).Count().Should().Be(1);

            var test1          = timeRange1.Copy(new TimeSpan(100, 0, 0, 0).Negate());
            var insidePeriods1 = timePeriods.InsidePeriods(test1).ToList();

            insidePeriods1.Count.Should().Be(0);

            var test2          = timeRange1.Copy(new TimeSpan(100, 0, 0, 0));
            var insidePeriods2 = timePeriods.InsidePeriods(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.InsidePeriods(test3).ToList();

            insidePeriods3.Count.Should().Be(1);

            var test4          = new TimeRange(new DateTime(now.Year, now.Month, 14), new DateTime(now.Year, now.Month, 17));
            var insidePeriods4 = timePeriods.InsidePeriods(test4).ToList();

            insidePeriods4.Count.Should().Be(1);
        }
        public void InsidePeriodsTimePeriodTest() {
            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));

            TimePeriodCollection timePeriods = new TimePeriodCollection { timeRange1, timeRange2, timeRange3, timeRange4, timeRange5 };

            timePeriods.InsidePeriods(timeRange1).Count().Should().Be(5);
            timePeriods.InsidePeriods(timeRange2).Count().Should().Be(1);
            timePeriods.InsidePeriods(timeRange3).Count().Should().Be(1);
            timePeriods.InsidePeriods(timeRange4).Count().Should().Be(2);
            timePeriods.InsidePeriods(timeRange5).Count().Should().Be(1);

            var test1 = timeRange1.Copy(new TimeSpan(100, 0, 0, 0).Negate());
            var insidePeriods1 = timePeriods.InsidePeriods(test1).ToList();
            insidePeriods1.Count.Should().Be(0);

            var test2 = timeRange1.Copy(new TimeSpan(100, 0, 0, 0));
            var insidePeriods2 = timePeriods.InsidePeriods(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.InsidePeriods(test3).ToList();
            insidePeriods3.Count.Should().Be(1);

            var test4 = new TimeRange(new DateTime(now.Year, now.Month, 14), new DateTime(now.Year, now.Month, 17));
            var insidePeriods4 = timePeriods.InsidePeriods(test4).ToList();
            insidePeriods4.Count.Should().Be(1);
        }