Esempio n. 1
0
        public void TestKeyComparer_OrderByDescending_WithComparison_NullKeySelector_Throws()
        {
            Func <int, int>      keySelector   = null;
            Func <int, int, int> keyComparison = Comparer <int> .Default.Compare;

            KeyComparer <int> .OrderByDescending <int>(keySelector, keyComparison);
        }
Esempio n. 2
0
        public void TestKeyComparer_OrderByDescending_NullKeyComparison_Throws()
        {
            Func <int, int>      keySelector   = i => i;
            Func <int, int, int> keyComparison = null;

            KeyComparer <int> .OrderByDescending <int>(keySelector, keyComparison);
        }
Esempio n. 3
0
        public void TestKeyComparer_Descending_SortStringsByLength()
        {
            Random random = new Random();

            string[] names = { "Bob", "George", "Mary", "Jessica", "David" };

            IComparer <string> comparer = KeyComparer <string> .OrderByDescending(item => item.Length);

            Array.Sort(names, comparer);

            string[] expected = { "Jessica", "George", "David", "Mary", "Bob" };
            CollectionAssert.AreEqual(expected, names, "The names were not sorted by length.");
        }
Esempio n. 4
0
        public void TestKeyComparer_OrderByDescending_WithKeyComparison()
        {
            // build a week, starting on a Sunday
            DateTime firstDate = new DateTime(2013, 1, 6);

            DateTime[] week = new DateTime[]
            {
                new DateTime(2013, 1, 6),
                new DateTime(2013, 1, 7),
                new DateTime(2013, 1, 8),
                new DateTime(2013, 1, 9),
                new DateTime(2013, 1, 10),
                new DateTime(2013, 1, 11),
                new DateTime(2013, 1, 12),
            };

            // force Mondays to come last!
            IComparer <DayOfWeek> dayComparer = NullComparer <DayOfWeek> .Default.ThenBy(day => (DayOfWeek)((int)(day + 6) % 7));

            Array.Sort(week, KeyComparer <DateTime> .OrderByDescending(d => d.DayOfWeek, dayComparer.Compare));

            Assert.AreEqual(firstDate.AddDays(1), week[week.Length - 1], "Monday did not appear at the end of the week.");
        }
Esempio n. 5
0
        public void TestKeyComparer_OrderByDescending_NullKeySelector_Throws()
        {
            Func <int, int> keySelector = null;

            KeyComparer <int> .OrderByDescending <int>(keySelector);
        }