Copy() 공개 메소드

public Copy ( ) : ITimeRange
리턴 ITimeRange
예제 #1
0
        public void CopyTest()
        {
            TimeRange readOnlyTimeRange = new TimeRange( start, end );
            Assert.AreEqual( readOnlyTimeRange.Copy( TimeSpan.Zero ), readOnlyTimeRange );

            TimeRange timeRange = new TimeRange( start, end );
            Assert.AreEqual( timeRange.Start, start );
            Assert.AreEqual( timeRange.End, end );

            ITimeRange noMoveTimeRange = timeRange.Copy( TimeSpan.Zero );
            Assert.AreEqual( noMoveTimeRange.Start, start );
            Assert.AreEqual( noMoveTimeRange.End, end );
            Assert.AreEqual( noMoveTimeRange.Duration, duration );

            TimeSpan forwardOffset = new TimeSpan( 2, 30, 15 );
            ITimeRange forwardTimeRange = timeRange.Copy( forwardOffset );
            Assert.AreEqual( forwardTimeRange.Start, start.Add( forwardOffset ) );
            Assert.AreEqual( forwardTimeRange.End, end.Add( forwardOffset ) );

            TimeSpan backwardOffset = new TimeSpan( -1, 10, 30 );
            ITimeRange backwardTimeRange = timeRange.Copy( backwardOffset );
            Assert.AreEqual( backwardTimeRange.Start, start.Add( backwardOffset ) );
            Assert.AreEqual( backwardTimeRange.End, end.Add( backwardOffset ) );
        }
        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.AreEqual( timePeriods.OverlapPeriods( timeRange1 ).Count, 5 );
            Assert.AreEqual( timePeriods.OverlapPeriods( timeRange2 ).Count, 3 );
            Assert.AreEqual( timePeriods.OverlapPeriods( timeRange3 ).Count, 2 );
            Assert.AreEqual( timePeriods.OverlapPeriods( timeRange4 ).Count, 3 );
            Assert.AreEqual( timePeriods.OverlapPeriods( timeRange5 ).Count, 2 );

            ITimeRange test1 = timeRange1.Copy( new TimeSpan( 100, 0, 0, 0 ).Negate() );
            ITimePeriodCollection insidePeriods1 = timePeriods.OverlapPeriods( test1 );
            Assert.AreEqual( insidePeriods1.Count, 0 );

            ITimeRange test2 = timeRange1.Copy( new TimeSpan( 100, 0, 0, 0 ) );
            ITimePeriodCollection insidePeriods2 = timePeriods.OverlapPeriods( test2 );
            Assert.AreEqual( insidePeriods2.Count, 0 );

            TimeRange test3 = new TimeRange( new DateTime( now.Year, now.Month, 9 ), new DateTime( now.Year, now.Month, 11 ) );
            ITimePeriodCollection insidePeriods3 = timePeriods.OverlapPeriods( test3 );
            Assert.AreEqual( insidePeriods3.Count, 3 );

            TimeRange test4 = new TimeRange( new DateTime( now.Year, now.Month, 14 ), new DateTime( now.Year, now.Month, 17 ) );
            ITimePeriodCollection insidePeriods4 = timePeriods.OverlapPeriods( test4 );
            Assert.AreEqual( insidePeriods4.Count, 3 );
        }