Esempio n. 1
0
        public void FlattenFullIteratedDisposesInnerSequences()
        {
            using (var inner1 = TestingSequence.Of(4, 5))
                using (var inner2 = TestingSequence.Of(true, false))
                    using (var inner3 = TestingSequence.Of <object>(6, inner2, 7))
                    {
                        var source = new object[]
                        {
                            inner1,
                            inner3,
                        };

                        var expectations = new object[]
                        {
                            4,
                            5,
                            6,
                            true,
                            false,
                            7,
                        };

                        using (var test = source.AsTestingSequence())
                        {
                            Assert.That(test.Flatten(), Is.EquivalentTo(expectations));
                        }
                    }
        }
Esempio n. 2
0
 public void TakeLastDisposesSequenceEnumerator()
 {
     using (var seq = TestingSequence.Of(1, 2, 3))
     {
         seq.TakeLast(1).Consume();
     }
 }
Esempio n. 3
0
        public void ZipDisposesInnerSequencesCaseGetEnumeratorThrows()
        {
            using var s1 = TestingSequence.Of(1, 2);

            Assert.Throws <InvalidOperationException>(() =>
                                                      s1.EquiZip(new BreakingSequence <int>(), Tuple.Create).Consume());
        }
Esempio n. 4
0
        public void TestInterleaveDoNotCallGetEnumeratorEagerly()
        {
            var sequenceA = TestingSequence.Of(1);
            var sequenceB = new BreakingSequence <int>();

            sequenceA.Interleave(sequenceB).Take(1).Consume();
        }
Esempio n. 5
0
        public void StartsWithDisposesBothSequenceEnumerators()
        {
            using var first  = TestingSequence.Of(1, 2, 3);
            using var second = TestingSequence.Of(1);

            first.StartsWith(second);
        }
Esempio n. 6
0
        public void BothSequencesDisposedWithUnequalLengthsAndShorterFirst()
        {
            using var longer  = TestingSequence.Of(1, 2, 3);
            using var shorter = TestingSequence.Of(1, 2);

            shorter.ZipShortest(longer, (x, y) => x + y).Consume();
        }
Esempio n. 7
0
        public void CompareCountDisposesSequenceEnumerators()
        {
            using var seq1 = TestingSequence.Of <int>();
            using var seq2 = TestingSequence.Of <int>();

            Assert.AreEqual(0, seq1.CompareCount(seq2));
        }
Esempio n. 8
0
 public void TestInterleaveDisposesOnError()
 {
     using (var sequenceA = TestingSequence.Of <int>())
     {
         Assert.Throws <InvalidOperationException>(() => // Expected and thrown by BreakingSequence
                                                   sequenceA.Interleave(new BreakingSequence <int>()).Consume());
     }
 }
Esempio n. 9
0
        public void CompareCountDisposesSecondEnumerator()
        {
            var collection = new BreakingCollection <int>(0);

            using var seq = TestingSequence.Of <int>();

            Assert.AreEqual(0, collection.CompareCount(seq));
        }
Esempio n. 10
0
 public void BothSequencesDisposedWithUnequalLengthsAndLongerFirst()
 {
     using (var longer = TestingSequence.Of(1, 2, 3))
         using (var shorter = TestingSequence.Of(1, 2))
         {
             longer.ZipLongest(shorter, (x, y) => x + y).Consume();
         }
 }
Esempio n. 11
0
        public void TestInterleaveDisposesOnErrorAtMoveNext()
        {
            using var sequenceA = TestingSequence.Of <int>();
            using var sequenceB = MoreEnumerable.From <int>(() => throw new TestException()).AsTestingSequence();

            // Expected and thrown by sequenceB
            Assert.Throws <TestException>(() => sequenceA.Interleave(sequenceB).Consume());
        }
Esempio n. 12
0
        public void TestInterleaveDisposesOnErrorAtGetEnumerator()
        {
            using var sequenceA = TestingSequence.Of <int>();
            var sequenceB = new BreakingSequence <int>();

            // Expected and thrown by BreakingSequence
            Assert.Throws <InvalidOperationException>(() => sequenceA.Interleave(sequenceB).Consume());
        }
Esempio n. 13
0
 public void EndsWithDisposesBothSequenceEnumerators()
 {
     using (var first = TestingSequence.Of(1, 2, 3))
         using (var second = TestingSequence.Of(1))
         {
             first.EndsWith(second);
         }
 }
Esempio n. 14
0
        public void TestSortedMergeDisposesOnError()
        {
            using var sequenceA = TestingSequence.Of <int>();

            // Expected and thrown by BreakingSequence
            Assert.Throws <InvalidOperationException>(() =>
                                                      sequenceA.SortedMerge(OrderByDirection.Ascending, new BreakingSequence <int>()).Consume());
        }
Esempio n. 15
0
        public void BothSequencesDisposedWithUnequalLengthsAndShorterFirst()
        {
            using var longer  = TestingSequence.Of(1, 2, 3);
            using var shorter = TestingSequence.Of(1, 2);

            // Yes, this will throw... but then we should still have disposed both sequences
            Assert.Throws <InvalidOperationException>(() =>
                                                      shorter.EquiZip(longer, (x, y) => x + y).Consume());
        }
Esempio n. 16
0
        public void CompareCountDisposesFirstEnumerator()
        {
            var collection = new BreakingCollection <int>(0);

            using (var seq = TestingSequence.Of <int>())
            {
                Assert.AreEqual(0, seq.CompareCount(collection));
            }
        }
Esempio n. 17
0
        public void TransposeWithOneNullRow()
        {
            using var seq1   = TestingSequence.Of(10, 11);
            using var seq2   = TestingSequence.Of <int>();
            using var seq3   = TestingSequence.Of(30, 31, 32);
            using var matrix = TestingSequence.Of(seq1, seq2, seq3, null);

            Assert.Throws <NullReferenceException>(() =>
                                                   matrix.Transpose().FirstOrDefault());
        }
Esempio n. 18
0
        public void MoveNextIsNotCalledUnnecessarily()
        {
            using var s1 = TestingSequence.Of(1, 2);
            using var s2 = TestingSequence.Of(1, 2, 3);
            using var s3 = MoreEnumerable.From(() => 1,
                                               () => 2,
                                               () => throw new TestException())
                           .AsTestingSequence();

            Assert.Throws <InvalidOperationException>(() =>
                                                      s1.EquiZip(s2, s3, (x, y, z) => x + y + z).Consume());
        }
Esempio n. 19
0
        public void FlattenInterruptedIterationDisposesInnerSequences()
        {
            using var inner1 = TestingSequence.Of(4, 5);
            using var inner2 = MoreEnumerable.From(() => true,
                                                   () => false,
                                                   () => throw new TestException())
                               .AsTestingSequence();
            using var inner3 = TestingSequence.Of <object>(6, inner2, 7);
            using var source = TestingSequence.Of <object>(inner1, inner3);

            Assert.Throws <TestException>(() =>
                                          source.Flatten().Consume());
        }
Esempio n. 20
0
 public void MoveNextIsNotCalledUnnecessarilyWhenFirstIsShorter()
 {
     using (var s1 = TestingSequence.Of(1, 2))
         using (var s2 = MoreEnumerable.From(() => 4,
                                             () => 5,
                                             () => throw new TestException())
                         .AsTestingSequence())
         {
             var zipped = s1.ZipShortest(s2, Tuple.Create);
             Assert.That(zipped, Is.Not.Null);
             zipped.AssertSequenceEqual((1, 4), (2, 5));
         }
 }
Esempio n. 21
0
 public void ZipShortestNotIterateUnnecessaryElements()
 {
     using (var s1 = MoreEnumerable.From(() => 4,
                                         () => 5,
                                         () => 6,
                                         () => throw new TestException())
                     .AsTestingSequence())
         using (var s2 = TestingSequence.Of(1, 2))
         {
             var zipped = s1.ZipShortest(s2, Tuple.Create);
             Assert.That(zipped, Is.Not.Null);
             zipped.AssertSequenceEqual((4, 1), (5, 2));
         }
 }
Esempio n. 22
0
 public void TestSortedMergeDisposesOnError()
 {
     using (var sequenceA = TestingSequence.Of <int>())
     {
         try
         {
             sequenceA.SortedMerge(OrderByDirection.Ascending, new BreakingSequence <int>()).ToArray();
             Assert.Fail("{0} was expected", typeof(InvalidOperationException));
         }
         catch (InvalidOperationException)
         {
             // Expected and thrown by BreakingSequence
         }
     }
 }
Esempio n. 23
0
 public void TestInterleaveDisposesOnError()
 {
     using (var sequenceA = TestingSequence.Of <int>())
     {
         try
         {
             sequenceA.Interleave(new BreakingSequence <int>()).ToArray();
             Assert.Fail("{0} was expected", typeof(InvalidOperationException));
         }
         catch (InvalidOperationException)
         {
             // Expected and thrown by BreakingSequence
         }
     }
 }
Esempio n. 24
0
 public void BothSequencesDisposedWithUnequalLengthsAndShorterFirst()
 {
     using (var longer = TestingSequence.Of(1, 2, 3))
         using (var shorter = TestingSequence.Of(1, 2))
         {
             // Yes, this will throw... but then we should still have disposed both sequences
             try
             {
                 shorter.EquiZip(longer, (x, y) => x + y).Consume();
             }
             catch (InvalidOperationException)
             {
                 // Expected
             }
         }
 }
Esempio n. 25
0
        public void ZipLongestDisposeSequencesEagerly()
        {
            var shorter = TestingSequence.Of(1, 2, 3);
            var longer  = MoreEnumerable.Generate(1, x => x + 1);
            var zipped  = shorter.ZipLongest(longer, Tuple.Create);

            var count = 0;

            foreach (var _ in zipped.Take(10))
            {
                if (++count == 4)
                {
                    ((IDisposable)shorter).Dispose();
                }
            }
        }
Esempio n. 26
0
        public void TransposeWithRowsOfSameLength()
        {
            var expectations = new[]
            {
                new [] { 10, 20, 30 },
                new [] { 11, 21, 31 },
                new [] { 12, 22, 32 },
                new [] { 13, 23, 33 },
            };

            using var row1   = TestingSequence.Of(10, 11, 12, 13);
            using var row2   = TestingSequence.Of(20, 21, 22, 23);
            using var row3   = TestingSequence.Of(30, 31, 32, 33);
            using var matrix = TestingSequence.Of(row1, row2, row3);

            AssertMatrix(expectations, matrix.Transpose());
        }
Esempio n. 27
0
        public void TransposeWithRowsOfDifferentLengths()
        {
            var expectations = new[]
            {
                new[] { 10, 20, 30 },
                new[] { 11, 31 },
                new[] { 32 }
            };

            using var row1   = TestingSequence.Of(10, 11);
            using var row2   = TestingSequence.Of(20);
            using var row3   = TestingSequence.Of <int>();
            using var row4   = TestingSequence.Of(30, 31, 32);
            using var matrix = TestingSequence.Of(row1, row2, row3, row4);

            AssertMatrix(expectations, matrix.Transpose());
        }
Esempio n. 28
0
        public void FlattenFullIteratedDisposesInnerSequences()
        {
            var expectations = new object[]
            {
                4,
                5,
                6,
                true,
                false,
                7,
            };

            using var inner1 = TestingSequence.Of(4, 5);
            using var inner2 = TestingSequence.Of(true, false);
            using var inner3 = TestingSequence.Of <object>(6, inner2, 7);
            using var source = TestingSequence.Of <object>(inner1, inner3);

            Assert.That(source.Flatten(), Is.EqualTo(expectations));
        }
Esempio n. 29
0
        public void FlattenInterruptedIterationDisposesInnerSequences()
        {
            using (var inner1 = TestingSequence.Of(4, 5))
                using (var inner2 = MoreEnumerable.From(() => true,
                                                        () => false,
                                                        () => throw new InvalidOperationException())
                                    .AsTestingSequence())
                    using (var inner3 = TestingSequence.Of <object>(6, inner2, 7))
                    {
                        var source = new object[]
                        {
                            inner1,
                            inner3,
                        };

                        using (var test = source.AsTestingSequence())
                        {
                            Assert.Throws <InvalidOperationException>(() =>
                                                                      test.Flatten().Consume());
                        }
                    }
        }