public void ToArray_FailOnExtremelyLargeCollection()
        {
            var largeSeq        = new FastInfiniteEnumerator <byte>();
            var thrownException = Assert.ThrowsAny <Exception>(() => { largeSeq.ToArray(); });

            Assert.True(thrownException.GetType() == typeof(OverflowException) || thrownException.GetType() == typeof(OutOfMemoryException));
        }
示例#2
0
        public void IteratorStateShouldNotChangeIfNumberOfElementsIsUnbounded()
        {
            // With https://github.com/dotnet/corefx/pull/13628, Skip and Take return
            // the same type of iterator. For Take, there is a limit, or upper bound,
            // on how many items can be returned from the iterator. An integer field,
            // _state, is incremented to keep track of this and to stop enumerating once
            // we pass that limit. However, for Skip, there is no such limit and the
            // iterator can contain an unlimited number of items (including past int.MaxValue).

            // This test makes sure that, in Skip, _state is not incorrectly incremented,
            // so that it does not overflow to a negative number and enumeration does not
            // stop prematurely.

            var iterator = new FastInfiniteEnumerator <int>().Skip(1).GetEnumerator();

            iterator.MoveNext(); // Make sure the underlying enumerator has been initialized.

            FieldInfo state = iterator.GetType().GetTypeInfo()
                              .GetField("_state", BindingFlags.Instance | BindingFlags.NonPublic);

            // On platforms that do not have this change, the optimization may not be present
            // and the iterator may not have a field named _state. In that case, nop.
            if (state != null)
            {
                state.SetValue(iterator, int.MaxValue);

                for (int i = 0; i < 10; i++)
                {
                    Assert.True(iterator.MoveNext());
                }
            }
        }
        public void IndexOverflow()
        {
            var selected = new FastInfiniteEnumerator <int>().SelectMany((e, i) => Enumerable.Empty <int>());

            using (var en = selected.GetEnumerator())
                Assert.Throws <OverflowException>(() =>
                {
                    while (en.MoveNext())
                    {
                    }
                });
        }
示例#4
0
        public void IndexTakeWhileOverflowBeyondIntMaxValueElements()
        {
            var taken = new FastInfiniteEnumerator <int>().TakeWhile((e, i) => true);

            using (var en = taken.GetEnumerator())
                Assert.Throws <OverflowException>(() =>
                {
                    while (en.MoveNext())
                    {
                    }
                });
        }
示例#5
0
        public void IndexOverflows()
        {
            var infiniteWhere = new FastInfiniteEnumerator <int>().Where((e, i) => true);

            using (var en = infiniteWhere.GetEnumerator())
                Assert.Throws <OverflowException>(() =>
                {
                    while (en.MoveNext())
                    {
                    }
                });
        }
示例#6
0
 public void IndexOverflows()
 {
     var infiniteWhere = new FastInfiniteEnumerator<int>().Where((e, i) => true);
     using (var en = infiniteWhere.GetEnumerator())
         Assert.Throws<OverflowException>(() =>
         {
             while (en.MoveNext())
             {
             }
         });
 }
示例#7
0
        public void Overflow()
        {
            var selected = new FastInfiniteEnumerator<int>().Select((e, i) => e);
            using (var en = selected.GetEnumerator())
                Assert.Throws<OverflowException>(() =>
                {
                    while (en.MoveNext())
                    {

                    }
                });
        }
示例#8
0
 public void IndexTakeWhileOverflowBeyondIntMaxValueElements()
 {
     var taken = new FastInfiniteEnumerator<int>().TakeWhile((e, i) => true);
     
     using(var en = taken.GetEnumerator())
         Assert.Throws<OverflowException>(() =>
         {
             while(en.MoveNext())
             {
             }
         });
 }