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)); } } }
public void TakeLastDisposesSequenceEnumerator() { using (var seq = TestingSequence.Of(1, 2, 3)) { seq.TakeLast(1).Consume(); } }
public void ZipDisposesInnerSequencesCaseGetEnumeratorThrows() { using var s1 = TestingSequence.Of(1, 2); Assert.Throws <InvalidOperationException>(() => s1.EquiZip(new BreakingSequence <int>(), Tuple.Create).Consume()); }
public void TestInterleaveDoNotCallGetEnumeratorEagerly() { var sequenceA = TestingSequence.Of(1); var sequenceB = new BreakingSequence <int>(); sequenceA.Interleave(sequenceB).Take(1).Consume(); }
public void StartsWithDisposesBothSequenceEnumerators() { using var first = TestingSequence.Of(1, 2, 3); using var second = TestingSequence.Of(1); first.StartsWith(second); }
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(); }
public void CompareCountDisposesSequenceEnumerators() { using var seq1 = TestingSequence.Of <int>(); using var seq2 = TestingSequence.Of <int>(); Assert.AreEqual(0, seq1.CompareCount(seq2)); }
public void TestInterleaveDisposesOnError() { using (var sequenceA = TestingSequence.Of <int>()) { Assert.Throws <InvalidOperationException>(() => // Expected and thrown by BreakingSequence sequenceA.Interleave(new BreakingSequence <int>()).Consume()); } }
public void CompareCountDisposesSecondEnumerator() { var collection = new BreakingCollection <int>(0); using var seq = TestingSequence.Of <int>(); Assert.AreEqual(0, collection.CompareCount(seq)); }
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(); } }
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()); }
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()); }
public void EndsWithDisposesBothSequenceEnumerators() { using (var first = TestingSequence.Of(1, 2, 3)) using (var second = TestingSequence.Of(1)) { first.EndsWith(second); } }
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()); }
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()); }
public void CompareCountDisposesFirstEnumerator() { var collection = new BreakingCollection <int>(0); using (var seq = TestingSequence.Of <int>()) { Assert.AreEqual(0, seq.CompareCount(collection)); } }
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()); }
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()); }
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()); }
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)); } }
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)); } }
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 } } }
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 } } }
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 } } }
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(); } } }
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()); }
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()); }
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)); }
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()); } } }