public void ExecutionIsDeferred()
 {
     IEnumerableWithCount<int> throwingEnumerable = new ThrowingEnumerable(15);
     Assert.AreEqual(15, throwingEnumerable.Count);
     IEnumerableWithCount<int> result = throwingEnumerable.Take(10);
     Assert.AreEqual(10, result.Count);
 }
Esempio n. 2
0
        public void ExecutionIsDeferred()
        {
            var outer = new ThrowingEnumerable();
            var inner = new ThrowingEnumerable();

            outer.Join(inner, x => x, y => y, (x, y) => x + y);
        }
Esempio n. 3
0
 public void ExecutionIsDeferred()
 {
     var outer = new ThrowingEnumerable();
     var inner = new ThrowingEnumerable();
     // No exception
     outer.Join(inner, x => x, y => y, (x, y) => x + y);
 }
Esempio n. 4
0
        public void ExecutionIsDeferred()
        {
            var first  = new ThrowingEnumerable();
            var second = new ThrowingEnumerable();

            first.Zip(second, (x, y) => x + y);
        }
Esempio n. 5
0
        public void ExecutionIsDeferred()
        {
            IEnumerable source = new ThrowingEnumerable();

            // No exception
            source.OfType <string>();
        }
 public void ExecutionIsDeferredAndCountWorks()
 {
     IEnumerableWithCount<int> first = new ThrowingEnumerable(5);
     IEnumerableWithCount<int> second = new ThrowingEnumerable(7);
     IEnumerableWithCount<int> result = first.Zip(second, (x, y) => x + y);
     Assert.AreEqual(5, result.Count);
 }
 public void DoesNotIterateForCount()
 {
     IEnumerableWithCount<int> throwingEnumerable = new ThrowingEnumerable(5);
     IOrderedEnumerableWithCount<int> orderBy = throwingEnumerable.OrderBy(x => x);
     IOrderedEnumerableWithCount<int> result = orderBy.ThenBy(x => x);
     Assert.AreEqual(5, result.Count);
 }
 public void DoesNotRequireEnumerationOfEitherInput()
 {
     IEnumerableWithCount<int> first = new ThrowingEnumerable(7);
     IEnumerableWithCount<int> second = new ThrowingEnumerable(10);
     IEnumerableWithCount<int> result = first.Concat(second);
     Assert.AreEqual(17, result.Count);
 }
 public void CountOptimization()
 {
     // The counts are different, so we don't need to iterate
     var first = new ThrowingEnumerable(5);
     var second = new ThrowingEnumerable(10);
     Assert.IsFalse(first.SequenceEqual(second));
 }
Esempio n. 10
0
        public void ExecutionIsDeferred()
        {
            var first  = new ThrowingEnumerable();
            var second = new ThrowingEnumerable();

            new AdjustedZipEnumerable <ThrowingEnumerable, ThrowingEnumerable.Enumerator, int, ThrowingEnumerable, ThrowingEnumerable.Enumerator, int, int, AddOperator>(first, second);
        }
 public void CountDoesNotEnumerate()
 {
     IEnumerableWithCount source = new ThrowingEnumerable(7);
     // No exception
     IEnumerableWithCount<string> result = source.Cast<string>();
     Assert.AreEqual(7, result.Count);
 }
Esempio n. 12
0
        public static void Append1()
        {
            IEnumerable <int> source = new ThrowingEnumerable <int>();

            var q = Assert.DoesNotThrow(() => source.Append(1));

            Assert.ThrowsOnNext(q);
        }
Esempio n. 13
0
        public static void CollectAny1a()
        {
            IEnumerable <Either <int, int> > source = new ThrowingEnumerable <Either <int, int> >();

            var q = Assert.DoesNotThrow(() => source.CollectAny());

            Assert.ThrowsOnNext(q);
        }
        public static void CollectImpl1a()
        {
            IEnumerable <Either <int, int> > source = new ThrowingEnumerable <Either <int, int> >();

            var q = Assert.DoesNotThrow(() => source.CollectImpl());

            q.OnLeft(x => Assert.ThrowsOnNext(x));
            q.OnRight(x => Assert.Fail());
        }
Esempio n. 15
0
        public void FirstSequenceIsNotUsedUntilQueryIsIterated()
        {
            var query = new ThrowingEnumerable().Union(new[] { 1, 2 });

            using (var enumerator = query.GetEnumerator()) // No exception expected here
            {
                Assert.Throws(typeof(InvalidOperationException), () => enumerator.MoveNext());
            }
        }
Esempio n. 16
0
        public void FirstSequenceIsNotAccessedBeforeFirstUse()
        {
            var first = new ThrowingEnumerable();
            var query = first.Concat(new[] { 1, 2, 3 });

            using (var iterator = query.GetEnumerator())
            {
                Assert.Throws(typeof(InvalidOperationException), () => iterator.MoveNext());
            }
        }
Esempio n. 17
0
        public void NoSequencesUsedBeforeIteration()
        {
            var first  = new ThrowingEnumerable();
            var second = new ThrowingEnumerable();
            var query  = first.Union(second);

            using (query.GetEnumerator())
            {
            }
        }
Esempio n. 18
0
        public static void Prepend1()
        {
            IEnumerable <int> source = new ThrowingEnumerable <int>();

            var q = Assert.DoesNotThrow(() => source.Prepend(1));

            // We bypass the first iteration (we just prepended 1 to the sequence,
            // iterating won't throw immediately).
            Assert.ThrowsAfter(q, 1);
        }
        public static void Zip1a()
        {
            IEnumerable <int> first = new ThrowingEnumerable <int>();
            var second = Enumerable.Range(0, 1);
            Func <int, int, Either <int, int> > resultSelector = (i, j) => Either <int, int> .OfLeft(i + j);

            var q = Assert.DoesNotThrow(() => Either.Zip(first, second, resultSelector));

            q.OnLeft(x => Assert.ThrowsOnNext(x));
            q.OnRight(x => Assert.Fail());
        }
Esempio n. 20
0
 public void FirstSequenceIsNotUsedUntilQueryIsIterated()
 {
     var first = new ThrowingEnumerable();
     int[] second = { 2 };
     var query = first.Union(second);
     using (var iterator = query.GetEnumerator())
     {
         // Still no exception... until we call MoveNext
         Assert.Throws<InvalidOperationException>(() => iterator.MoveNext());
     }
 }
Esempio n. 21
0
 public void NoSequencesUsedBeforeIteration()
 {
     var first = new ThrowingEnumerable();
     var second = new ThrowingEnumerable();
     // No exceptions!
     var query = first.Union(second);
     // Still no exceptions... we're not calling MoveNext.
     using (var iterator = query.GetEnumerator())
     {
     }
 }
Esempio n. 22
0
        public void SecondSequenceIsNotAccessedBeforeFirstUse()
        {
            var second = new ThrowingEnumerable();
            var query = new[] { 1, 2 }.Concat(second);

            using (var iterator = query.GetEnumerator())
            {
                Assert.IsTrue(iterator.MoveNext());
                Assert.IsTrue(iterator.MoveNext());
                Assert.Throws(typeof(InvalidOperationException), () => iterator.MoveNext());
            }
        }
Esempio n. 23
0
        public void NoSequencesUsedBeforeIteration()
        {
            var first  = new ThrowingEnumerable();
            var second = new ThrowingEnumerable();
            // No exceptions!
            var query = first.Union(second);

            // Still no exceptions... we're not calling MoveNext.
            using (var iterator = query.GetEnumerator())
            {
            }
        }
 public void FirstSequenceIsntAccessedBeforeFirstUse()
 {
     IEnumerableWithCount<int> first = new ThrowingEnumerable(0);
     IEnumerableWithCount<int> second = new int[] { 5 }.AsEnumerableWithCount();
     // No exception yet...
     var query = first.Concat(second);
     // Still no exception...
     using (var iterator = query.GetEnumerator())
     {
         // Now it will go bang
         Assert.Throws<InvalidOperationException>(() => iterator.MoveNext());
     }
 }
Esempio n. 25
0
        public void FirstSequenceIsNotUsedUntilQueryIsIterated()
        {
            var first = new ThrowingEnumerable();

            int[] second = { 2 };
            var   query  = first.Union(second);

            using (var iterator = query.GetEnumerator())
            {
                // Still no exception... until we call MoveNext
                Assert.Throws <InvalidOperationException>(() => iterator.MoveNext());
            }
        }
Esempio n. 26
0
        public void FirstSequenceIsntAccessedBeforeFirstUse()
        {
            IEnumerable <int> first  = new ThrowingEnumerable();
            IEnumerable <int> second = new int[] { 5 };
            // No exception yet...
            var query = first.Concat(second);

            // Still no exception...
            using (var iterator = query.GetEnumerator())
            {
                // Now it will go bang
                Assert.Throws <InvalidOperationException>(() => iterator.MoveNext());
            }
        }
Esempio n. 27
0
        public void FirstSequenceIsntAccessedBeforeFirstUse()
        {
            var first = new ThrowingEnumerable();

            int[] second = { 5 };
            // No exception yet...
            var query = new ConcatEnumerable <ThrowingEnumerable, ThrowingEnumerable.Enumerator, ArrayEnumerable <int>, ArrayEnumerable <int> .Enumerator, int>(first, second.AsRefEnumerable());

            // Still no exception...
            using (var iterator = query.GetEnumerator())
            {
                // Now it will go bang
                Assert.Throws <InvalidOperationException>(() => iterator.MoveNext());
            }
        }
 public void SecondSequenceIsntAccessedBeforeFirstUse()
 {
     IEnumerableWithCount<int> first = new int[] { 5 }.AsEnumerableWithCount();
     IEnumerableWithCount<int> second = new ThrowingEnumerable(0);
     // No exception yet...
     var query = first.Concat(second);
     // Still no exception...
     using (var iterator = query.GetEnumerator())
     {
         // First element is fine...
         Assert.IsTrue(iterator.MoveNext());
         Assert.AreEqual(5, iterator.Current);
         // Now it will go bang, as we move into the second sequence
         Assert.Throws<InvalidOperationException>(() => iterator.MoveNext());
     }
 }
Esempio n. 29
0
        public void SecondSequenceIsNotUsedUntilFirstIsExhausted()
        {
            int[] first = { 3, 5, 3 };
            var second = new ThrowingEnumerable();
            using (var iterator = first.Union(second).GetEnumerator())
            {
                // Check the first two elements...
                Assert.IsTrue(iterator.MoveNext());
                Assert.AreEqual(3, iterator.Current);
                Assert.IsTrue(iterator.MoveNext());
                Assert.AreEqual(5, iterator.Current);

                // But as soon as we move past the first sequence, bang!
                Assert.Throws<InvalidOperationException>(() => iterator.MoveNext());
            }
        }
Esempio n. 30
0
        public void SecondSequenceIsNotUsedUntilFirstIsExhausted()
        {
            int[] first  = { 3, 5, 3 };
            var   second = new ThrowingEnumerable();

            using (var iterator = first.Union(second).GetEnumerator())
            {
                // Check the first two elements...
                Assert.IsTrue(iterator.MoveNext());
                Assert.AreEqual(3, iterator.Current);
                Assert.IsTrue(iterator.MoveNext());
                Assert.AreEqual(5, iterator.Current);

                // But as soon as we move past the first sequence, bang!
                Assert.Throws <InvalidOperationException>(() => iterator.MoveNext());
            }
        }
Esempio n. 31
0
        public void SecondSequenceIsntAccessedBeforeFirstUse()
        {
            IEnumerable <int> first  = new int[] { 5 };
            IEnumerable <int> second = new ThrowingEnumerable();
            // No exception yet...
            var query = first.Concat(second);

            // Still no exception...
            using (var iterator = query.GetEnumerator())
            {
                // First element is fine...
                Assert.IsTrue(iterator.MoveNext());
                Assert.AreEqual(5, iterator.Current);
                // Now it will go bang, as we move into the second sequence
                Assert.Throws <InvalidOperationException>(() => iterator.MoveNext());
            }
        }
Esempio n. 32
0
        public void DoesNotCallGetEnumerator()
        {
            var source = new ThrowingEnumerable();

            Assert.AreSame(source, source.AsEnumerable());
        }
 public void WithIndexExecutionIsDeferred()
 {
     ThrowingEnumerable.AssertDeferred(src => src.Select((x, index) => x + index));
 }
 public void ExecutionIsDeferred()
 {
     ThrowingEnumerable.AssertDeferred(src => src.Select(x => x * 2));
 }
 public void DoesNotIterateWhenEmpty()
 {
     IEnumerableWithCount<int> source = new ThrowingEnumerable(0);
     Assert.AreEqual(0, source.LastOrDefault());
 }
Esempio n. 36
0
 public void DoesNotCallGetEnumerator()
 {
     var source = new ThrowingEnumerable();
     Assert.AreSame(source, source.AsEnumerable());
 }
 public void MultipleElementSequenceDoesNotIterate()
 {
     IEnumerableWithCount<int> source = new ThrowingEnumerable(2);
     Assert.Throws<InvalidOperationException>(() => source.SingleOrDefault());
 }
 public void ExecutionIsDeferred()
 {
     IEnumerableWithCount<int> throwingEnumerable = new ThrowingEnumerable(0);
     IOrderedEnumerableWithCount<int> orderBy = throwingEnumerable.OrderBy(x => x);
     IOrderedEnumerableWithCount<int> result = orderBy.ThenBy(x => x);
 }
Esempio n. 39
0
 public void WithIndexExecutionIsDeferred()
 {
     ThrowingEnumerable.AssertDeferred(src => new WhereIndexEnumerable <ThrowingEnumerable, ThrowingEnumerable.Enumerator, int, PredicateGreaterThan>(new ThrowingEnumerable(), new PredicateGreaterThan(0)));
 }
 public void DoesNotIterateForCount()
 {
     IEnumerableWithCount<int> source = new ThrowingEnumerable(3);
     IEnumerableWithCount<int> result = source.OrderByDescending(x => x);
     Assert.AreEqual(3, result.Count);
 }
 public void DoesNotCallGetEnumerator()
 {
     IEnumerableWithCount<int> source = new ThrowingEnumerable(0);
     Assert.AreSame(source, source.AsEnumerable());
 }
 public void DoesNotIterateOnOvershootIndex()
 {
     IEnumerableWithCount<int> source = new ThrowingEnumerable(7);
     Assert.AreEqual(0, source.ElementAtOrDefault(7));
 }
Esempio n. 43
0
 public void ExecutionIsDeferred()
 {
     var outer = new ThrowingEnumerable();
     var inner = new ThrowingEnumerable();
     // No exception
     var join = new JoinEnumerable <ThrowingEnumerable, ThrowingEnumerable.Enumerator, int, ThrowingEnumerable, ThrowingEnumerable.Enumerator, int, int, AsIs <int>, AsIs <int>, DefaultEqualityComparer <int>, int, AddInt>(outer, inner, default, default, default, default, Allocator.Temp);
 public void DoesNotIterate()
 {
     IEnumerableWithCount<int> source = new ThrowingEnumerable(5);
     Assert.AreEqual(5, source.Count);
 }
Esempio n. 45
0
 public void NoSequencesUsedBeforeIteration()
 {
     var first  = new ThrowingEnumerable();
     var second = new ThrowingEnumerable();
     // No exceptions!
     var query = new SetOperationEnumerable <ThrowingEnumerable, ThrowingEnumerable.Enumerator, ThrowingEnumerable, ThrowingEnumerable.Enumerator, int, IntersectOperation <ThrowingEnumerable, ThrowingEnumerable.Enumerator, ThrowingEnumerable, ThrowingEnumerable.Enumerator, int, DefaultEqualityComparer <int> > >(first, second, default, Allocator.Persistent);
 public void ExecutionIsDeferred()
 {
     IEnumerableWithCount<int> throwingEnumerable = new ThrowingEnumerable(0);
     throwingEnumerable.Reverse();
 }
Esempio n. 47
0
 public void DoesNotEnumerateWhenNotEmpty()
 {
     IEnumerableWithCount<int> source = new ThrowingEnumerable(7);
     // No exception
     Assert.IsTrue(source.Any());
 }
Esempio n. 48
0
 public void ExecutionIsDeferred()
 {
     ThrowingEnumerable.AssertDeferred(src => src.Where((x, i) => x > 0));
 }
Esempio n. 49
0
        public void SourceSequenceIsReadEagerly()
        {
            var source = new ThrowingEnumerable();

            Assert.Throws <InvalidOperationException>(() => source.ToLookup(x => x));
        }
Esempio n. 50
0
 public void ExecutionIsDeferred()
 {
     IEnumerable source = new ThrowingEnumerable();
     // No exception
     source.OfType<string>();
 }
Esempio n. 51
0
 public void ExecutionIsDeferred()
 {
     ThrowingEnumerable.AssertDeferred(src =>
                                       new SelectEnumerable <ThrowingEnumerable, ThrowingEnumerable.Enumerator, int, int, DelegateFuncToStructOperatorAction <int, int> >(src, new DelegateFuncToStructOperatorAction <int, int>(x => x * 2)));
 }
 public void ExecutionIsDeferred()
 {
     IEnumerableWithCount<int> throwingEnumerable = new ThrowingEnumerable(0);
     throwingEnumerable.OrderByDescending(x => x);
 }
 public void EmptySequenceDoesNotIterate()
 {
     IEnumerableWithCount<int> source = new ThrowingEnumerable(0);
     Assert.AreEqual(0, source.SingleOrDefault());
 }
 public void DoesNotIterateWhenEmpty()
 {
     IEnumerableWithCount<int> source = new ThrowingEnumerable(0);
     Assert.Throws<InvalidOperationException>(() => source.Last());
 }
Esempio n. 55
0
 public void ExecutionIsDeferred()
 {
     var first = new ThrowingEnumerable();
     var second = new ThrowingEnumerable();
     first.Zip(second, (x, y) => x + y);
 }
 public void SourceSequenceIsReadEagerly()
 {
     var source = new ThrowingEnumerable();
     Assert.Throws<InvalidOperationException>(() => source.ToLookup(x => x));
 }
 public void DoesNotIterateForCount()
 {
     IEnumerableWithCount<int> source = new ThrowingEnumerable(10);
     IEnumerableWithCount<int> result = source.Select(x => x * 2);
     Assert.AreEqual(10, result.Count);
 }
Esempio n. 58
0
 public void ExecutionIsDeferred()
 {
     var outer = new ThrowingEnumerable();
     var inner = new ThrowingEnumerable();
     outer.GroupJoin(inner, x => x, y => y, (x, y) => x + y.Count());
 }
Esempio n. 59
0
 public void WithIndexExecutionIsDeferred()
 {
     ThrowingEnumerable.AssertDeferred(src =>
                                       new SelectIndexEnumerable <ThrowingEnumerable, ThrowingEnumerable.Enumerator, int, long, DelegateFuncToSelectIndexStructOperator <int, long> >(src, new DelegateFuncToSelectIndexStructOperator <int, long>((x, index) => x + index)));
 }