コード例 #1
0
        public void TakeTest()
        {
            int[] enumerable = new int[] { 0, 1, 2 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Take(enumerable, 2),
                EnumerableSelectManyExtensions.Take(enumerable, 2));

            enumerable = new int[] { 0, 1, 1, 1, 2, 2 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Take(enumerable, 0),
                EnumerableSelectManyExtensions.Take(enumerable, 0));

            enumerable = new int[] { 0, 1, 1, 1, 2, 2 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Take(enumerable, -1),
                EnumerableSelectManyExtensions.Take(enumerable, -1));

            enumerable = new int[] { 0, 1, 1, 1, 2, 2 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Take(enumerable, 100),
                EnumerableSelectManyExtensions.Take(enumerable, 100));

            enumerable = new int[] { };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Take(enumerable, 100),
                EnumerableSelectManyExtensions.Take(enumerable, 100));
        }
コード例 #2
0
        public void ExceptTest()
        {
            int[] first  = new int[] { 0, 1, 2 };
            int[] second = new int[] { 3, 4, 5 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Except(first, second),
                EnumerableSelectManyExtensions.Except(first, second, EqualityComparer <int> .Default));

            first  = new int[] { 0, 1, 2 };
            second = new int[] { };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Except(first, second),
                EnumerableSelectManyExtensions.Except(first, second, EqualityComparer <int> .Default));

            first  = new int[] { };
            second = new int[] { 3, 4, 5 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Except(first, second),
                EnumerableSelectManyExtensions.Except(first, second, EqualityComparer <int> .Default));

            first  = new int[] { 0, 1, 2 };
            second = new int[] { 2, 3, 4 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Except(first, second),
                EnumerableSelectManyExtensions.Except(first, second, EqualityComparer <int> .Default));
        }
コード例 #3
0
        public void WhereTest()
        {
            int[] enumerable = new int[] { 0, 1, 2 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Where(enumerable, x => x > 0),
                EnumerableSelectManyExtensions.Where(enumerable, x => x > 0));

            enumerable = new int[] { };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Where(enumerable, x => x > 0),
                EnumerableSelectManyExtensions.Where(enumerable, x => x > 0));
        }
コード例 #4
0
        public void DistinctTest()
        {
            int[] enumerable = new int[] { 0, 1, 2 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Distinct(enumerable),
                EnumerableSelectManyExtensions.Distinct(enumerable, EqualityComparer <int> .Default));

            enumerable = new int[] { 0, 1, 1, 1, 2, 2 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Distinct(enumerable),
                EnumerableSelectManyExtensions.Distinct(enumerable, EqualityComparer <int> .Default));
        }
コード例 #5
0
        public void SelectTest()
        {
            int[] enumerable = new int[] { 0, 1, 2 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Select(enumerable, x => x.ToString()),
                EnumerableSelectManyExtensions.Select4(enumerable, x => x.ToString()));

            enumerable = new int[] { };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Select(enumerable, x => x.ToString()),
                EnumerableSelectManyExtensions.Select4(enumerable, x => x.ToString()));
        }
コード例 #6
0
        public void TakeWhileTest()
        {
            int[] enumerable = new int[] { 0, 1, 2 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.TakeWhile(enumerable, x => x > 0),
                EnumerableSelectManyExtensions.TakeWhile(enumerable, x => x > 0));

            enumerable = new int[] { 2, 1, 0, -1 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.TakeWhile(enumerable, x => x > 0),
                EnumerableSelectManyExtensions.TakeWhile(enumerable, x => x > 0));

            enumerable = new int[] { };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.TakeWhile(enumerable, x => x > 0),
                EnumerableSelectManyExtensions.TakeWhile(enumerable, x => x > 0));
        }
コード例 #7
0
        public void ConcatTest()
        {
            int[] first  = new int[] { 0, 1, 2 };
            int[] second = new int[] { 3, 4, 5 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Concat(first, second),
                EnumerableSelectManyExtensions.Concat(first, second));

            first  = new int[] { };
            second = new int[] { 3, 4, 5 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Concat(first, second),
                EnumerableSelectManyExtensions.Concat(first, second));

            first  = new int[] { 0, 1, 2 };
            second = new int[] { };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Concat(first, second),
                EnumerableSelectManyExtensions.Concat(first, second));
        }
コード例 #8
0
        public void GroupByTest()
        {
            int[] enumerable = new int[] { 0, 1, 2, 4, 5, 6 };
            IGrouping <int, int>[] expected = Enumerable.GroupBy(enumerable, value => value % 3, value => value).ToArray();
            IGrouping <int, int>[] actual   = EnumerableSelectManyExtensions.GroupBy(enumerable, value => value % 3, value => value, EqualityComparer <int> .Default).ToArray();
            Assert.AreEqual(expected.Count(), actual.Count());
            expected.ForEach((group, index) =>
            {
                Assert.AreEqual(group.Key, actual[index].Key);
                EnumerableAssert.AreSequentialEqual(group, actual[index]);
            });

            enumerable = new int[] { };
            expected   = Enumerable.GroupBy(enumerable, value => value % 3, value => value).ToArray();
            actual     = EnumerableSelectManyExtensions.GroupBy(enumerable, value => value % 3, value => value, EqualityComparer <int> .Default).ToArray();
            Assert.AreEqual(expected.Count(), actual.Count());
            expected.ForEach((group, index) =>
            {
                Assert.AreEqual(group.Key, actual[index].Key);
                EnumerableAssert.AreSequentialEqual(group, actual[index]);
            });
        }
コード例 #9
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),
                EnumerableSelectManyExtensions.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),
                EnumerableSelectManyExtensions.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),
                EnumerableSelectManyExtensions.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),
                EnumerableSelectManyExtensions.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),
                EnumerableSelectManyExtensions.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),
                EnumerableSelectManyExtensions.Zip(first, second, (x, y) => x * y));
        }
コード例 #10
0
 public void GroupJoinTest()
 {
     Tuple <int, string>[] categories = new Tuple <int, string>[]
     {
         new Tuple <int, string>(1, "A"),
         new Tuple <int, string>(2, "B"),
         new Tuple <int, string>(3, "C"),
     };
     Tuple <int, string, int>[] products = new Tuple <int, string, int>[]
     {
         new Tuple <int, string, int>(1, "aa", 1),
         new Tuple <int, string, int>(2, "bb", 1),
         new Tuple <int, string, int>(3, "cc", 2),
         new Tuple <int, string, int>(4, "dd", 2),
         new Tuple <int, string, int>(5, "ee", 2),
     };
     Tuple <string, int>[] expected = Enumerable.GroupJoin(
         categories,
         products,
         category => category.Item1,
         product => product.Item3,
         (category, categoryProducts) => new Tuple <string, int>(category.Item2, categoryProducts.Count())).ToArray();
     Tuple <string, int>[] actual = EnumerableSelectManyExtensions.GroupJoin(
         categories,
         products,
         category => category.Item1,
         product => product.Item3,
         (category, categoryProducts) => new Tuple <string, int>(category.Item2, categoryProducts.Count()),
         EqualityComparer <int> .Default).ToArray();
     Assert.AreEqual(expected.Count(), actual.Count());
     expected.ForEach((product, index) =>
     {
         Assert.AreEqual(product.Item1, actual[index].Item1);
         Assert.AreEqual(product.Item2, actual[index].Item2);
     });
 }