Ejemplo n.º 1
0
        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
Ejemplo n.º 2
0
        public void ClearTest()
        {
            TimePeriodCollection timePeriods = new TimePeriodCollection();

            Assert.Equal(0, timePeriods.Count);
            timePeriods.Clear();
            Assert.Equal(0, timePeriods.Count);

            timePeriods.AddAll(new SchoolDay());
            Assert.Equal(7, timePeriods.Count);
            timePeriods.Clear();
            Assert.Equal(0, timePeriods.Count);
        }         // ClearTest
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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 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);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
        public void IsAnytimeTest()
        {
            DateTime             now         = ClockProxy.Clock.Now;
            TimePeriodCollection timePeriods = new TimePeriodCollection();

            Assert.True(timePeriods.IsAnytime);

            timePeriods.Add(TimeRange.Anytime);
            Assert.True(timePeriods.IsAnytime);

            timePeriods.Clear();
            Assert.True(timePeriods.IsAnytime);

            timePeriods.Add(new TimeRange(TimeSpec.MinPeriodDate, now));
            Assert.False(timePeriods.IsAnytime);

            timePeriods.Add(new TimeRange(now, TimeSpec.MaxPeriodDate));
            Assert.True(timePeriods.IsAnytime);

            timePeriods.Clear();
            Assert.True(timePeriods.IsAnytime);
        }         // IsAnytimeTest
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
        public void StartTest()
        {
            DateTime             now         = ClockProxy.Clock.Now;
            TimePeriodCollection timePeriods = new TimePeriodCollection();

            Assert.Equal(timePeriods.Start, TimeSpec.MinPeriodDate);

            timePeriods.Add(new TimeBlock(now, Duration.Hour));
            Assert.Equal <DateTime>(timePeriods.Start, now);

            timePeriods.Clear();
            Assert.Equal(timePeriods.Start, TimeSpec.MinPeriodDate);
        }         // StartTest
Ejemplo n.º 12
0
        public void HasStartTest()
        {
            TimePeriodCollection timePeriods = new TimePeriodCollection();

            Assert.False(timePeriods.HasStart);

            timePeriods.Add(new TimeBlock(TimeSpec.MinPeriodDate, Duration.Hour));
            Assert.False(timePeriods.HasStart);

            timePeriods.Clear();
            timePeriods.Add(new TimeBlock(ClockProxy.Clock.Now, Duration.Hour));
            Assert.True(timePeriods.HasStart);
        }         // HasStartTest
Ejemplo n.º 13
0
        public void EndTest()
        {
            DateTime             now         = ClockProxy.Clock.Now;
            TimePeriodCollection timePeriods = new TimePeriodCollection();

            Assert.Equal(timePeriods.End, TimeSpec.MaxPeriodDate);

            timePeriods.Add(new TimeBlock(Duration.Hour, now));
            Assert.Equal <DateTime>(timePeriods.End, now);

            timePeriods.Clear();
            Assert.Equal(timePeriods.End, TimeSpec.MaxPeriodDate);
        }         // EndTest
Ejemplo n.º 14
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);
        }
Ejemplo n.º 15
0
        public void IsMomentTest()
        {
            DateTime             now         = ClockProxy.Clock.Now;
            TimePeriodCollection timePeriods = new TimePeriodCollection();

            Assert.False(timePeriods.IsMoment);

            timePeriods.Add(TimeRange.Anytime);
            Assert.False(timePeriods.IsMoment);

            timePeriods.Clear();
            Assert.False(timePeriods.IsMoment);

            timePeriods.Add(new TimeRange(now));
            Assert.True(timePeriods.IsMoment);

            timePeriods.Add(new TimeRange(now));
            Assert.True(timePeriods.IsMoment);

            timePeriods.Clear();
            Assert.True(timePeriods.IsAnytime);
        }         // IsMomentTest
Ejemplo n.º 16
0
        public void StartTest()
        {
            var now         = ClockProxy.Clock.Now;
            var timePeriods = new TimePeriodCollection();

            Assert.AreEqual(timePeriods.Start, TimeSpec.MinPeriodTime);

            timePeriods.Add(new TimeBlock(now, DurationUtil.Hour));
            Assert.AreEqual(timePeriods.Start, now);
            Assert.AreEqual(timePeriods.End, now.AddHours(1));

            timePeriods.Clear();
            Assert.AreEqual(timePeriods.Start, TimeSpec.MinPeriodTime);
        }
Ejemplo n.º 17
0
        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);
        }
Ejemplo n.º 18
0
        public void HasEndTest()
        {
            DateTime             now         = ClockProxy.Clock.Now;
            TimePeriodCollection timePeriods = new TimePeriodCollection();

            Assert.False(timePeriods.HasEnd);

            timePeriods.Add(new TimeBlock(Duration.Hour, TimeSpec.MaxPeriodDate));
            Assert.False(timePeriods.HasEnd);

            timePeriods.Clear();
            timePeriods.Add(new TimeBlock(now, Duration.Hour));
            Assert.True(timePeriods.HasEnd);
        }         // HasEndTest
Ejemplo n.º 19
0
        public void AddAllTest()
        {
            DateTime             now         = ClockProxy.Clock.Now;
            SchoolDay            schoolDay   = new SchoolDay(now);
            TimePeriodCollection timePeriods = new TimePeriodCollection();

            Assert.Equal(0, timePeriods.Count);

            timePeriods.AddAll(schoolDay);
            Assert.Equal(timePeriods.Count, schoolDay.Count);

            timePeriods.Clear();
            Assert.Equal(0, timePeriods.Count);
        }         // AddAllTest
Ejemplo n.º 20
0
        public void HasEndTest()
        {
            var now         = ClockProxy.Clock.Now;
            var timePeriods = new TimePeriodCollection();

            Assert.IsFalse(timePeriods.HasEnd);

            timePeriods.Add(new TimeBlock(DurationUtil.Hour, TimeSpec.MaxPeriodTime));
            Assert.IsFalse(timePeriods.HasEnd);

            timePeriods.Clear();
            timePeriods.Add(new TimeBlock(now, DurationUtil.Hour));
            Assert.IsTrue(timePeriods.HasEnd);
        }
Ejemplo n.º 21
0
        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);
        }
Ejemplo n.º 22
0
        public void AddTest()
        {
            TimePeriodCollection timePeriods = new TimePeriodCollection();

            Assert.Equal(0, timePeriods.Count);

            timePeriods.Add(new TimeRange());
            Assert.Equal(1, timePeriods.Count);

            timePeriods.Add(new TimeRange());
            Assert.Equal(2, timePeriods.Count);

            timePeriods.Clear();
            Assert.Equal(0, timePeriods.Count);
        }         // AddTest
        public void AddTest()
        {
            TimePeriodCollection timePeriods = new TimePeriodCollection();

            Assert.AreEqual(timePeriods.Count, 0);

            timePeriods.Add(new TimeRange());
            Assert.AreEqual(timePeriods.Count, 1);

            timePeriods.Add(new TimeRange());
            Assert.AreEqual(timePeriods.Count, 2);

            timePeriods.Clear();
            Assert.AreEqual(timePeriods.Count, 0);
        }         // AddTest
Ejemplo n.º 24
0
        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);
        }
Ejemplo n.º 25
0
        public void HasStartTest() {
            TimePeriodCollection timePeriods = new TimePeriodCollection();
            Assert.IsFalse(timePeriods.HasStart);

            timePeriods.Add(new TimeBlock(TimeSpec.MinPeriodTime, DurationUtil.Hour));
            Assert.IsFalse(timePeriods.HasStart);

            timePeriods.Clear();
            timePeriods.Add(new TimeBlock(ClockProxy.Clock.Now, DurationUtil.Hour));
            Assert.IsTrue(timePeriods.HasStart);
        }
Ejemplo n.º 26
0
        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);
        }
Ejemplo n.º 27
0
        public void HasEndTest() {
            var now = ClockProxy.Clock.Now;
            var timePeriods = new TimePeriodCollection();
            Assert.IsFalse(timePeriods.HasEnd);

            timePeriods.Add(new TimeBlock(DurationUtil.Hour, TimeSpec.MaxPeriodTime));
            Assert.IsFalse(timePeriods.HasEnd);

            timePeriods.Clear();
            timePeriods.Add(new TimeBlock(now, DurationUtil.Hour));
            Assert.IsTrue(timePeriods.HasEnd);
        }
Ejemplo n.º 28
0
        public void StartTest() {
            var now = ClockProxy.Clock.Now;
            var timePeriods = new TimePeriodCollection();
            Assert.AreEqual(timePeriods.Start, TimeSpec.MinPeriodTime);

            timePeriods.Add(new TimeBlock(now, DurationUtil.Hour));
            Assert.AreEqual(timePeriods.Start, now);
            Assert.AreEqual(timePeriods.End, now.AddHours(1));

            timePeriods.Clear();
            Assert.AreEqual(timePeriods.Start, TimeSpec.MinPeriodTime);
        }
Ejemplo n.º 29
0
        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);
        }
Ejemplo n.º 30
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));
        }
Ejemplo n.º 31
0
        public void SortByTest()
        {
            DateTime             now         = ClockProxy.Clock.Now;
            SchoolDay            schoolDay   = new SchoolDay(now);
            TimePeriodCollection timePeriods = new TimePeriodCollection();

            // start
            timePeriods.Add(schoolDay.Lesson4);
            timePeriods.Add(schoolDay.Break3);
            timePeriods.Add(schoolDay.Lesson3);
            timePeriods.Add(schoolDay.Break2);
            timePeriods.Add(schoolDay.Lesson2);
            timePeriods.Add(schoolDay.Break1);
            timePeriods.Add(schoolDay.Lesson1);

            timePeriods.SortBy(TimePeriodStartComparer.Comparer);

            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);

            timePeriods.SortReverseBy(TimePeriodStartComparer.Comparer);

            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);

            // end
            timePeriods.Clear();
            timePeriods.AddAll(schoolDay);

            timePeriods.SortReverseBy(TimePeriodEndComparer.Comparer);

            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.SortBy(TimePeriodEndComparer.Comparer);

            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);

            // duration
            timePeriods.Clear();
            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.SortReverseBy(TimePeriodDurationComparer.Comparer);

            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.SortBy(TimePeriodDurationComparer.Comparer);

            Assert.Equal(oneHour, timePeriods[0].Duration);
            Assert.Equal(twoHours, timePeriods[1].Duration);
            Assert.Equal(threeHours, timePeriods[2].Duration);
            Assert.Equal(fourHours, timePeriods[3].Duration);
        }         // SortByTest
Ejemplo n.º 32
0
        public void HasOverlapsTest()
        {
            DateTime start1 = ClockProxy.Clock.Now.Date;
            DateTime end1   = start1.AddDays(1);
            DateTime start2 = end1;
            DateTime end2   = start2.AddDays(1);

            TimePeriodCollection periods         = new TimePeriodCollection();
            TimeLine <TimeRange> timeLineMoments = new TimeLine <TimeRange>(periods, null, null);

            Assert.AreEqual(false, timeLineMoments.HasOverlaps());

            periods.Add(new TimeRange(start1, start1));
            Assert.AreEqual(false, timeLineMoments.HasOverlaps());
            periods.RemoveAt(periods.Count - 1);

            periods.Add(new TimeRange(start1, end1));
            Assert.AreEqual(false, timeLineMoments.HasOverlaps());

            periods.Add(new TimeRange(start1, end1));
            Assert.AreEqual(true, timeLineMoments.HasOverlaps());
            periods.RemoveAt(periods.Count - 1);
            Assert.AreEqual(false, timeLineMoments.HasOverlaps());

            periods.Add(new TimeRange(start1.AddHours(1), end1.AddHours(1)));
            Assert.AreEqual(true, timeLineMoments.HasOverlaps());
            periods.RemoveAt(periods.Count - 1);
            Assert.AreEqual(false, timeLineMoments.HasOverlaps());

            periods.Add(new TimeRange(start1.AddHours(-1), end1.AddHours(-1)));
            Assert.AreEqual(true, timeLineMoments.HasOverlaps());
            periods.RemoveAt(periods.Count - 1);
            Assert.AreEqual(false, timeLineMoments.HasOverlaps());

            periods.Add(new TimeRange(start1.AddHours(-1), end1.AddHours(+1)));
            Assert.AreEqual(true, timeLineMoments.HasOverlaps());
            periods.RemoveAt(periods.Count - 1);
            Assert.AreEqual(false, timeLineMoments.HasOverlaps());

            periods.Add(new TimeRange(start1.AddHours(+1), end1.AddHours(-1)));
            Assert.AreEqual(true, timeLineMoments.HasOverlaps());
            periods.RemoveAt(periods.Count - 1);
            Assert.AreEqual(false, timeLineMoments.HasOverlaps());

            periods.Add(new TimeRange(start2, end2));
            Assert.AreEqual(false, timeLineMoments.HasOverlaps());

            periods.Add(new TimeRange(start2, end2.AddHours(1)));
            Assert.AreEqual(true, timeLineMoments.HasOverlaps());
            periods.RemoveAt(periods.Count - 1);

            periods.Add(new TimeRange(start2, end2.AddHours(-1)));
            Assert.AreEqual(true, timeLineMoments.HasOverlaps());
            periods.RemoveAt(periods.Count - 1);

            periods.Add(new TimeRange(start1, end2));
            Assert.AreEqual(true, timeLineMoments.HasOverlaps());

            periods.RemoveAt(0);
            Assert.AreEqual(true, timeLineMoments.HasOverlaps());

            periods.RemoveAt(0);
            Assert.AreEqual(false, timeLineMoments.HasOverlaps());

            periods.Clear();
            Assert.AreEqual(false, timeLineMoments.HasOverlaps());
        }         // HasOverlapsTest
Ejemplo n.º 33
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);
        }
Ejemplo n.º 34
0
        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);
        }
Ejemplo n.º 35
0
        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);
        }
Ejemplo n.º 36
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));
        }
Ejemplo n.º 37
0
        public void GetFreeBusyRequestTimePeriodIntersectorTest()
        {
            //取得會議室資訊
            var calendarAttributes =
                "fullName,email";
            var searchMeetingRooms = new SearchCalendarResourcesRequest(calendarAttributes);

            ZmailRequest.ApiRequest = searchMeetingRooms;
            var zResquestRoom = ZmailDispatcher.SendRequest(ZmailRequest);
            var respRoom      = zResquestRoom.ApiResponse as SearchCalendarResourcesResponse;
            var crList        = respRoom?.CalendarResourceList;

            if (crList != null)
            {
                var crEmails = crList.Select(cr => cr.AttributesList.Where(ar => ar.Key.Equals("email")).Select(ar => ar.Value).FirstOrDefault());
                var sdate    = DateTime.Now;
                var edate    = sdate.AddDays(7);
                //多人請用逗號隔開
                var crEmailStrings = string.Join(",", crEmails.ToArray());
                var searchNames    = "[email protected],[email protected]," + crEmailStrings;
                ZmailRequest.ApiRequest = new GetFreeBusyRequest(sdate, edate, searchNames);
                var zResquest = ZmailDispatcher.SendRequest(ZmailRequest);
                var resp      = zResquest.ApiResponse as GetFreeBusyResponse;
                var wkHours   = resp?.Workinghours;
                if (wkHours != null)
                {
                    var periods = new Dictionary <string, TimePeriodCollection>();
                    var users   = wkHours.Users.Where(u => !crEmails.Contains(u.id));

                    //找出所有人的共同時間
                    var periodIntersector = new TimePeriodIntersector <TimeRange>();
                    var resultPeriods     = new TimePeriodCollection();
                    var idx = 0;
                    foreach (var user in users)
                    {
                        Console.WriteLine(user.id);
                        Console.WriteLine("Free");
                        var userPeriods = new TimePeriodCollection();

                        foreach (var f in user.Fs)
                        {
                            Console.WriteLine($" {f.s} - {f.e}");
                            userPeriods.Add(new TimeRange(f.s, f.e));
                        }
                        periods.Add(user.id, userPeriods);
                        if (idx == 0)
                        {
                            resultPeriods.AddAll(user.Fs.Select(f => new TimeRange(f.s, f.e)));
                        }
                        else
                        {
                            resultPeriods.AddAll(user.Fs.Select(f => new TimeRange(f.s, f.e)));
                            if (resultPeriods.Any())
                            {
                                var intersectedPeriods = periodIntersector.IntersectPeriods(resultPeriods, false);
                                resultPeriods.Clear();
                                resultPeriods.AddAll(intersectedPeriods.Select(p => new TimeRange(p.Start, p.End)));
                            }
                        }
                    }

                    Console.WriteLine("...共同的時間...");
                    foreach (var intersectedPeriod in resultPeriods)
                    {
                        Console.WriteLine("所有人共同的的時間 Period: " + intersectedPeriod);
                    }

                    //對應到會議室
                    var crs = wkHours.Users.Where(u => crEmails.Contains(u.id));

                    foreach (var cr in crList)
                    {
                        var email = cr.AttributesList.Where(ar => ar.Key.Equals("email"))
                                    .Select(ar => ar.Value)
                                    .FirstOrDefault();
                        var fullName = cr.AttributesList.Where(ar => ar.Key.Equals("fullName"))
                                       .Select(ar => ar.Value)
                                       .FirstOrDefault();

                        Console.WriteLine($"{fullName}:{email}");
                        var crHour = wkHours.Users.FirstOrDefault(u => u.id.Equals(email));
                        if (crHour != null)
                        {
                            var crPeriods = new TimePeriodCollection();
                            crPeriods.AddAll(resultPeriods.Select(p => new TimeRange(p.Start, p.End)));
                            crPeriods.AddAll(crHour.Fs.Select(f => new TimeRange(f.s, f.e)));
                            var intersectedPeriods = periodIntersector.IntersectPeriods(crPeriods, false);
                            Console.WriteLine($"{fullName}:{email}...共同的時間...");
                            foreach (var intersectedPeriod in intersectedPeriods)
                            {
                                Console.WriteLine("    Period: " + intersectedPeriod);
                            }
                        }
                    }
                }
            }
        }