示例#1
0
        public void CopyTest()
        {
            var readOnlyTimeRange = new TimeRange(_start, _end);

            readOnlyTimeRange.Copy().Should().Be(readOnlyTimeRange);
            readOnlyTimeRange.Copy(TimeSpan.Zero).Should().Be(readOnlyTimeRange);

            var timeRange = new TimeRange(_start, _end);

            timeRange.Start.Should().Be(_start);
            timeRange.End.Should().Be(_end);

            var noMoveTimeRange = timeRange.Copy(TimeSpan.Zero);

            noMoveTimeRange.Start.Should().Be(timeRange.Start);
            noMoveTimeRange.End.Should().Be(timeRange.End);
            noMoveTimeRange.Duration.Should().Be(timeRange.Duration);
            noMoveTimeRange.Should().Be(timeRange);

            var forwardOffset    = new TimeSpan(2, 30, 15);
            var forwardTimeRange = timeRange.Copy(forwardOffset);

            forwardTimeRange.Start.Should().Be(_start.Add(forwardOffset));
            forwardTimeRange.End.Should().Be(_end.Add(forwardOffset));
            forwardTimeRange.Duration.Should().Be(duration);

            var backwardOffset    = new TimeSpan(-1, 10, 30);
            var backwardTimeRange = timeRange.Copy(backwardOffset);

            backwardTimeRange.Start.Should().Be(_start.Add(backwardOffset));
            backwardTimeRange.End.Should().Be(_end.Add(backwardOffset));
            backwardTimeRange.Duration.Should().Be(duration);
        }
        public void CopyTest()
        {
            TimeRange readOnlyTimeRange = new TimeRange(start, end);

            Assert.Equal(readOnlyTimeRange.Copy(TimeSpan.Zero), readOnlyTimeRange);

            TimeRange timeRange = new TimeRange(start, end);

            Assert.Equal(timeRange.Start, start);
            Assert.Equal(timeRange.End, end);

            ITimeRange noMoveTimeRange = timeRange.Copy(TimeSpan.Zero);

            Assert.Equal(noMoveTimeRange.Start, start);
            Assert.Equal(noMoveTimeRange.End, end);
            Assert.Equal(noMoveTimeRange.Duration, duration);

            TimeSpan   forwardOffset    = new TimeSpan(2, 30, 15);
            ITimeRange forwardTimeRange = timeRange.Copy(forwardOffset);

            Assert.Equal(forwardTimeRange.Start, start.Add(forwardOffset));
            Assert.Equal(forwardTimeRange.End, end.Add(forwardOffset));

            TimeSpan   backwardOffset    = new TimeSpan(-1, 10, 30);
            ITimeRange backwardTimeRange = timeRange.Copy(backwardOffset);

            Assert.Equal(backwardTimeRange.Start, start.Add(backwardOffset));
            Assert.Equal(backwardTimeRange.End, end.Add(backwardOffset));
        }         // CopyTest
示例#3
0
        public void IntersectionPeriodsTimePeriodTest()
        {
            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.IntersectionPeriods(timeRange1).Count().Should().Be(5);
            timePeriods.IntersectionPeriods(timeRange2).Count().Should().Be(3);
            timePeriods.IntersectionPeriods(timeRange3).Count().Should().Be(4);
            timePeriods.IntersectionPeriods(timeRange4).Count().Should().Be(4);
            timePeriods.IntersectionPeriods(timeRange5).Count().Should().Be(3);

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

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

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

            insidePeriods4.Count.Should().Be(3);
        }
示例#4
0
        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 IntersectionPeriodsTimePeriodTest() {
            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.IntersectionPeriods(timeRange1).Count().Should().Be(5);
            timePeriods.IntersectionPeriods(timeRange2).Count().Should().Be(3);
            timePeriods.IntersectionPeriods(timeRange3).Count().Should().Be(4);
            timePeriods.IntersectionPeriods(timeRange4).Count().Should().Be(4);
            timePeriods.IntersectionPeriods(timeRange5).Count().Should().Be(3);

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

            var test2 = timeRange1.Copy(new TimeSpan(100, 0, 0, 0));
            var insidePeriods2 = timePeriods.IntersectionPeriods(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.IntersectionPeriods(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.IntersectionPeriods(test4).ToList();
            insidePeriods4.Count.Should().Be(3);
        }
示例#6
0
        public void CopyTest() {
            var readOnlyTimeRange = new TimeRange(_start, _end);
            readOnlyTimeRange.Copy().Should().Be(readOnlyTimeRange);
            readOnlyTimeRange.Copy(TimeSpan.Zero).Should().Be(readOnlyTimeRange);

            var timeRange = new TimeRange(_start, _end);
            timeRange.Start.Should().Be(_start);
            timeRange.End.Should().Be(_end);

            var noMoveTimeRange = timeRange.Copy(TimeSpan.Zero);

            noMoveTimeRange.Start.Should().Be(timeRange.Start);
            noMoveTimeRange.End.Should().Be(timeRange.End);
            noMoveTimeRange.Duration.Should().Be(timeRange.Duration);
            noMoveTimeRange.Should().Be(timeRange);

            var forwardOffset = new TimeSpan(2, 30, 15);
            var forwardTimeRange = timeRange.Copy(forwardOffset);

            forwardTimeRange.Start.Should().Be(_start.Add(forwardOffset));
            forwardTimeRange.End.Should().Be(_end.Add(forwardOffset));
            forwardTimeRange.Duration.Should().Be(duration);

            var backwardOffset = new TimeSpan(-1, 10, 30);
            var backwardTimeRange = timeRange.Copy(backwardOffset);

            backwardTimeRange.Start.Should().Be(_start.Add(backwardOffset));
            backwardTimeRange.End.Should().Be(_end.Add(backwardOffset));
            backwardTimeRange.Duration.Should().Be(duration);
        }