Example #1
0
        public void UnionTest()
        {
            int[] first  = new int[] { 0, 1, 2 };
            int[] second = new int[] { 3, 4, 5 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Union(first, second),
                EnumerableMonadExtensions.Union(first, second, EqualityComparer <int> .Default));

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

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

            first  = new int[] { 0, 1, 2 };
            second = new int[] { 2, 3, 4 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Union(first, second),
                EnumerableMonadExtensions.Union(first, second, EqualityComparer <int> .Default));
        }
Example #2
0
        public void TakeTest()
        {
            int[] enumerable = new int[] { 0, 1, 2 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Take(enumerable, 2),
                EnumerableMonadExtensions.Take(enumerable, 2));

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

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

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

            enumerable = new int[] { };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Take(enumerable, 100),
                EnumerableMonadExtensions.Take(enumerable, 100));
        }
Example #3
0
        public void WhereTest()
        {
            int[] enumerable = new int[] { 0, 1, 2 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Where(enumerable, x => x > 0),
                EnumerableMonadExtensions.Where(enumerable, x => x > 0));

            enumerable = new int[] { };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Where(enumerable, x => x > 0),
                EnumerableMonadExtensions.Where(enumerable, x => x > 0));
        }
Example #4
0
        public void SelectTest()
        {
            int[] enumerable = new int[] { 0, 1, 2 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Select(enumerable, x => x.ToString()),
                EnumerableMonadExtensions.Select4(enumerable, x => x.ToString()));

            enumerable = new int[] { };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Select(enumerable, x => x.ToString()),
                EnumerableMonadExtensions.Select4(enumerable, x => x.ToString()));
        }
Example #5
0
        public void DistinctTest()
        {
            int[] enumerable = new int[] { 0, 1, 2 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Distinct(enumerable),
                EnumerableMonadExtensions.Distinct(enumerable, EqualityComparer <int> .Default));

            enumerable = new int[] { 0, 1, 1, 1, 2, 2 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Distinct(enumerable),
                EnumerableMonadExtensions.Distinct(enumerable, EqualityComparer <int> .Default));
        }
Example #6
0
        public void TakeWhileTest()
        {
            int[] enumerable = new int[] { 0, 1, 2 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.TakeWhile(enumerable, x => x > 0),
                EnumerableMonadExtensions.TakeWhile(enumerable, x => x > 0));

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

            enumerable = new int[] { };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.TakeWhile(enumerable, x => x > 0),
                EnumerableMonadExtensions.TakeWhile(enumerable, x => x > 0));
        }
Example #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),
                EnumerableMonadExtensions.Concat(first, second));

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

            first  = new int[] { 0, 1, 2 };
            second = new int[] { };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Concat(first, second),
                EnumerableMonadExtensions.Concat(first, second));
        }
Example #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   = EnumerableMonadExtensions.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     = EnumerableMonadExtensions.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]);
            });
        }
Example #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),
                EnumerableMonadExtensions.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),
                EnumerableMonadExtensions.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),
                EnumerableMonadExtensions.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),
                EnumerableMonadExtensions.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),
                EnumerableMonadExtensions.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),
                EnumerableMonadExtensions.Zip(first, second, (x, y) => x * y));
        }
Example #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 = EnumerableMonadExtensions.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);
     });
 }