Esempio n. 1
0
        public void GroupByTest()
        {
            int[] enumerable = new int[] { 0, 1, 2, 4, 5, 6 };
            IGrouping <int, int>[] expected = Enumerable.ToArray(Enumerable.GroupBy(enumerable, value => value % 3, value => value));
            IGrouping <int, int>[] actual   = Enumerable.ToArray(EnumerableExtensions.GroupBy(enumerable, value => value % 3, value => value, EqualityComparer <int> .Default));
            Assert.AreEqual(Enumerable.Count(expected), Enumerable.Count(actual));
            expected.ForEach((group, index) =>
            {
                Assert.AreEqual(group.Key, actual[index].Key);
                EnumerableAssert.AreSequentialEqual(group, actual[index]);
            });

            enumerable = new int[] { };
            expected   = Enumerable.ToArray(Enumerable.GroupBy(enumerable, value => value % 3, value => value));
            actual     = Enumerable.ToArray(EnumerableExtensions.GroupBy(enumerable, value => value % 3, value => value, EqualityComparer <int> .Default));
            Assert.AreEqual(Enumerable.Count(expected), Enumerable.Count(actual));
            expected.ForEach((group, index) =>
            {
                Assert.AreEqual(group.Key, actual[index].Key);
                EnumerableAssert.AreSequentialEqual(group, actual[index]);
            });
        }
Esempio n. 2
0
        public void ZipTest()
        {
            int[] first  = new int[] { 0, 1, 2 };
            int[] second = new int[] { 3, 4, 5 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Zip(first, second, (x, y) => x * y),
                EnumerableExtensions.Zip(first, second, (x, y) => x * y));

            first  = new int[] { 0, 1, 2 };
            second = new int[] { };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Zip(first, second, (x, y) => x * y),
                EnumerableExtensions.Zip(first, second, (x, y) => x * y));

            first  = new int[] { };
            second = new int[] { 3, 4, 5 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Zip(first, second, (x, y) => x * y),
                EnumerableExtensions.Zip(first, second, (x, y) => x * y));

            first  = new int[] { 0, 1, 2 };
            second = new int[] { 2, 3, 4 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Zip(first, second, (x, y) => x * y),
                EnumerableExtensions.Zip(first, second, (x, y) => x * y));

            first  = new int[] { 0, 1 };
            second = new int[] { 2, 3, 4 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Zip(first, second, (x, y) => x * y),
                EnumerableExtensions.Zip(first, second, (x, y) => x * y));

            first  = new int[] { 0, 1, 2 };
            second = new int[] { 2, 3 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Zip(first, second, (x, y) => x * y),
                EnumerableExtensions.Zip(first, second, (x, y) => x * y));
        }