Esempio n. 1
0
 public void RemoveAtTest()
 {
     try
     {
         int[] removeAt = Enumerable.Range(0, 5).RemoveAt(-1).ToArray();
         Assert.Fail(string.Join(", ", removeAt.Select(int32 => int32.ToString())));
     }
     catch (ArgumentOutOfRangeException exception)
     {
         Assert.AreEqual("index", exception.ParamName);
     }
     EnumerableAssert.AreSequentialEqual(new int[] { 1, 2, 3, 4 }, Enumerable.Range(0, 5).RemoveAt(0));
     EnumerableAssert.AreSequentialEqual(new int[] { 0, 2, 3, 4 }, Enumerable.Range(0, 5).RemoveAt(1));
     EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 3, 4 }, Enumerable.Range(0, 5).RemoveAt(2));
     EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 2, 4 }, Enumerable.Range(0, 5).RemoveAt(3));
     EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 2, 3 }, Enumerable.Range(0, 5).RemoveAt(4));
     try
     {
         int[] removeAt = Enumerable.Range(0, 5).RemoveAt(5).ToArray();
         Assert.Fail(string.Join(", ", removeAt.Select(int32 => int32.ToString())));
     }
     catch (ArgumentOutOfRangeException exception)
     {
         Assert.AreEqual("index", exception.ParamName);
     }
     try
     {
         int[] removeAt = Enumerable.Range(0, 5).RemoveAt(6).ToArray();
         Assert.Fail(string.Join(", ", removeAt.Select(int32 => int32.ToString())));
     }
     catch (ArgumentOutOfRangeException exception)
     {
         Assert.AreEqual("index", exception.ParamName);
     }
 }
Esempio n. 2
0
        public void TakeTest()
        {
            int[] enumerable = new int[] { 0, 1, 2 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Take(enumerable, 2),
                EnumerableExtensions.Take(enumerable, 2));

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

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

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

            enumerable = new int[] { };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Take(enumerable, 100),
                EnumerableExtensions.Take(enumerable, 100));
        }
Esempio n. 3
0
 public void InsertTest()
 {
     try
     {
         int[] insert = Enumerable.Range(0, 5).Insert(-1, 5).ToArray();
         Assert.Fail(string.Join(", ", insert.Select(int32 => int32.ToString())));
     }
     catch (ArgumentOutOfRangeException exception)
     {
         Assert.AreEqual("index", exception.ParamName);
     }
     EnumerableAssert.AreSequentialEqual(new int[] { 5, 0, 1, 2, 3, 4 }, Enumerable.Range(0, 5).Insert(0, 5));
     EnumerableAssert.AreSequentialEqual(new int[] { 0, 5, 1, 2, 3, 4 }, Enumerable.Range(0, 5).Insert(1, 5));
     EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 5, 2, 3, 4 }, Enumerable.Range(0, 5).Insert(2, 5));
     EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 2, 5, 3, 4 }, Enumerable.Range(0, 5).Insert(3, 5));
     EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 2, 3, 5, 4 }, Enumerable.Range(0, 5).Insert(4, 5));
     EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 2, 3, 4, 5 }, Enumerable.Range(0, 5).Insert(5, 5));
     try
     {
         int[] insert = Enumerable.Range(0, 5).Insert(6, 5).ToArray();
         Assert.Fail(string.Join(", ", insert.Select(int32 => int32.ToString())));
     }
     catch (ArgumentOutOfRangeException exception)
     {
         Assert.AreEqual("index", exception.ParamName);
     }
 }
Esempio n. 4
0
        public void ExceptTest()
        {
            int[] first  = new int[] { 0, 1, 2 };
            int[] second = new int[] { 3, 4, 5 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Except(first, second),
                EnumerableExtensions.Except(first, second, EqualityComparer <int> .Default));

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

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

            first  = new int[] { 0, 1, 2 };
            second = new int[] { 2, 3, 4 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Except(first, second),
                EnumerableExtensions.Except(first, second, EqualityComparer <int> .Default));
        }
Esempio n. 5
0
 public void RemoveTest()
 {
     EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 2, 3, 4 }, Enumerable.Range(0, 5).Remove(-1));
     EnumerableAssert.AreSequentialEqual(new int[] { 1, 2, 3, 4 }, Enumerable.Range(0, 5).Remove(0));
     EnumerableAssert.AreSequentialEqual(new int[] { 0, 2, 3, 4 }, Enumerable.Range(0, 5).Remove(1));
     EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 3, 4 }, Enumerable.Range(0, 5).Remove(2));
     EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 2, 4 }, Enumerable.Range(0, 5).Remove(3));
     EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 2, 3 }, Enumerable.Range(0, 5).Remove(4));
     EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 2, 3, 4 }, Enumerable.Range(0, 5).Remove(5));
     EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 2, 3, 4 }, Enumerable.Range(0, 5).Remove(6));
 }
Esempio n. 6
0
        public void Reverse2Test()
        {
            int[] enumerable = new int[] { 0, 1, 2 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Reverse(enumerable),
                DeferredExecution.CompiledReverseGenerator(enumerable));

            enumerable = new int[] { };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Reverse(enumerable),
                DeferredExecution.CompiledReverseGenerator(enumerable));
        }
Esempio n. 7
0
        public void EnumerableTest()
        {
            EnumerableAssert.AreSequentialEqual(
                EnumerableEx.Return(1),
                IteratorPattern.FromValue(1));

            object value = new object();

            EnumerableAssert.AreSequentialEqual(
                EnumerableEx.Return(value),
                IteratorPattern.FromValue(value));
        }
Esempio n. 8
0
        public void WhereTest()
        {
            int[] enumerable = new int[] { 0, 1, 2 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Where(enumerable, x => x > 0),
                IteratorPattern.Where(enumerable, x => x > 0));

            enumerable = new int[] { };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Where(enumerable, x => x > 0),
                IteratorPattern.Where(enumerable, x => x > 0));
        }
Esempio n. 9
0
        public void DistinctTest()
        {
            int[] enumerable = new int[] { 0, 1, 2 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Distinct(enumerable),
                EnumerableExtensions.Distinct(enumerable, EqualityComparer <int> .Default));

            enumerable = new int[] { 0, 1, 1, 1, 2, 2 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Distinct(enumerable),
                EnumerableExtensions.Distinct(enumerable, EqualityComparer <int> .Default));
        }
Esempio n. 10
0
        public void WhereTest()
        {
            int[] enumerable = new int[] { 0, 1, 2 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Where(enumerable, x => x > 0),
                EnumerableExtensions.Where(enumerable, x => x > 0));

            enumerable = new int[] { };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Where(enumerable, x => x > 0),
                EnumerableExtensions.Where(enumerable, x => x > 0));
        }
Esempio n. 11
0
        public void SelectTest()
        {
            int[] enumerable = new int[] { 0, 1, 2 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Select(enumerable, x => x.ToString()),
                EnumerableExtensions.Select(enumerable, x => x.ToString()));

            enumerable = new int[] { };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Select(enumerable, x => x.ToString()),
                EnumerableExtensions.Select(enumerable, x => x.ToString()));
        }
Esempio n. 12
0
        public void SelectTest()
        {
            int[] enumerable = new int[] { 0, 1, 2 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Select(enumerable, x => x.ToString()),
                IteratorPattern.Select(enumerable, x => x.ToString()));

            enumerable = new int[] { };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Select(enumerable, x => x.ToString()),
                IteratorPattern.Select(enumerable, x => x.ToString()));
        }
        public void MultipleTest()
        {
            SinglyLinkedListNode <int> head     = new SinglyLinkedListNode <int>(0, new SinglyLinkedListNode <int>(1, new SinglyLinkedListNode <int>(2, new SinglyLinkedListNode <int>(3))));
            LinkedListSequence <int>   sequence = new LinkedListSequence <int>(head);
            List <int> list = new List <int>();

            foreach (int value in sequence)
            {
                list.Add(value);
            }

            EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 2, 3 }, list);
        }
Esempio n. 14
0
 public void RemoveAllTest()
 {
     EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 2, 3, 4 }, Enumerable.Range(0, 5).RemoveAll(-1));
     EnumerableAssert.AreSequentialEqual(new int[] { 1, 2, 3, 4 }, Enumerable.Range(0, 5).RemoveAll(0));
     EnumerableAssert.AreSequentialEqual(new int[] { 0, 2, 3, 4 }, Enumerable.Range(0, 5).RemoveAll(1));
     EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 3, 4 }, Enumerable.Range(0, 5).RemoveAll(2));
     EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 2, 4 }, Enumerable.Range(0, 5).RemoveAll(3));
     EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 2, 3 }, Enumerable.Range(0, 5).RemoveAll(4));
     EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 2, 3, 4 }, Enumerable.Range(0, 5).RemoveAll(5));
     EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 2, 3, 4 }, Enumerable.Range(0, 5).RemoveAll(6));
     EnumerableAssert.AreSequentialEqual(new int[] { }, Enumerable.Repeat(0, 5).RemoveAll(0));
     EnumerableAssert.AreSequentialEqual(new int[] { 0, 0, 0, 0, 0 }, Enumerable.Repeat(0, 5).RemoveAll(1));
     EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 2, 3, 0, 1, 2, 3 }, Enumerable.Range(0, 5).Concat(Enumerable.Range(0, 5)).RemoveAll(4));
     EnumerableAssert.AreSequentialEqual(new int[] { 1, 2, 3, 4, 1, 2, 3, 4 }, Enumerable.Range(0, 5).Concat(Enumerable.Range(0, 5)).RemoveAll(0));
 }
Esempio n. 15
0
        public void TakeWhileTest()
        {
            int[] enumerable = new int[] { 0, 1, 2 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.TakeWhile(enumerable, x => x > 0),
                EnumerableExtensions.TakeWhile(enumerable, x => x > 0));

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

            enumerable = new int[] { };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.TakeWhile(enumerable, x => x > 0),
                EnumerableExtensions.TakeWhile(enumerable, x => x > 0));
        }
Esempio n. 16
0
        public void RetryTest()
        {
            int count = 0;

            int[] retry = EnumerableX.Create(() =>
            {
                count++;
                if (count < 5)
                {
                    throw new OperationCanceledException();
                }
                return(count);
            })
                          .Take(2)
                          .Retry <int, OperationCanceledException>(5)
                          .ToArray();
            EnumerableAssert.AreSequentialEqual(new int[] { 5, 6 }, retry);
        }
Esempio n. 17
0
        public void RepeatTest()
        {
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Repeat(1, 5),
                IteratorPattern.Repeat(1, 5));
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Repeat(1, 0),
                IteratorPattern.Repeat(1, 0));
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Repeat(1, 1),
                IteratorPattern.Repeat(1, 1));

            object value = new object();

            EnumerableAssert.AreSequentialEqual(
                Enumerable.Repeat(value, 10),
                IteratorPattern.Repeat(value, 10));
        }
Esempio n. 18
0
        public void ConcatTest()
        {
            int[] first  = new int[] { 0, 1, 2 };
            int[] second = new int[] { 3, 4, 5 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Concat(first, second),
                EnumerableExtensions.Concat(first, second));

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

            first  = new int[] { 0, 1, 2 };
            second = new int[] { };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Concat(first, second),
                EnumerableExtensions.Concat(first, second));
        }
Esempio n. 19
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. 20
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));
        }