Esempio n. 1
0
        public void TestThenBy()
        {
            var sequence = new[] { new Point(1, 2), new Point(1, 1), new Point(-1, 2), new Point(-1, 1) };

            sequence.OrderBy(t => t, Comparers.Create((Point p) => p.X).Reverse().ThenBy(Comparers.Create((Point p) => p.Y)))
            .SequenceShouldEqual(sequence.OrderByDescending(t => t.X).ThenBy(t => t.Y));
        }
Esempio n. 2
0
        public void TestComparerEquality()
        {
            Func <int, int> f = i => - i;

            TestEquality(Comparers.Create(f), Comparers.Create(f), Comparers.Create((int i) => i.ToString()));

            TestEquality(Comparers.Reverse <int>(), Comparers.Reverse <int>(), Comparers.Create((int i) => i.ToString()).Reverse());

            var first  = Comparers.Create((string s) => s.Length);
            var second = Comparers.Create((string s) => s[0]);

            TestEquality(first.ThenBy(second), first.ThenBy(second), second.ThenBy(first));

            TestEquality(Comparers.GetSequenceComparer <string>(), Comparers.GetSequenceComparer(Comparer <string> .Default), Comparers.GetSequenceComparer(StringComparer.OrdinalIgnoreCase));
        }
        private static bool SortBasedEquals <T>(IEnumerable <T> a, IEnumerable <T> b, IEqualityComparer <T> comparer)
        {
            var order = Comparers.Create((T item) => comparer.GetHashCode(item));

            return(a.OrderBy(x => x, order).SequenceEqual(b.OrderBy(x => x, order), comparer));
        }