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