Skip to content

Commit

Permalink
Update existing tests to exercise said bug
Browse files Browse the repository at this point in the history
  • Loading branch information
atifaziz committed Jan 20, 2023
1 parent 78c7b8a commit 7a85c95
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions MoreLinq.Test/ExcludeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void TestExcludeNegativeCountException()
[Test]
public void TestExcludeWithCountEqualsZero()
{
var sequence = Enumerable.Range(1, 10);
using var sequence = Enumerable.Range(1, 10).AsTestingSequence();
var resultA = sequence.Exclude(5, 0);

Assert.That(resultA, Is.SameAs(sequence));
Expand Down Expand Up @@ -88,10 +88,11 @@ public void TestExcludeEmptySequence()
public void TestExcludeSequenceHead()
{
const int count = 10;
var sequence = Enumerable.Range(1, count);
var xs = Enumerable.Range(1, count);
using var sequence = xs.AsTestingSequence();
var result = sequence.Exclude(0, count / 2);

Assert.That(result, Is.EqualTo(sequence.Skip(count / 2)));
Assert.That(result, Is.EqualTo(xs.Skip(count / 2)));
}

/// <summary>
Expand All @@ -101,10 +102,11 @@ public void TestExcludeSequenceHead()
public void TestExcludeSequenceTail()
{
const int count = 10;
var sequence = Enumerable.Range(1, count);
var xs = Enumerable.Range(1, count);
using var sequence = xs.AsTestingSequence();
var result = sequence.Exclude(count / 2, count);

Assert.That(result, Is.EqualTo(sequence.Take(count / 2)));
Assert.That(result, Is.EqualTo(xs.Take(count / 2)));
}

/// <summary>
Expand All @@ -116,10 +118,11 @@ public void TestExcludeSequenceMiddle()
const int count = 10;
const int startIndex = 3;
const int excludeCount = 5;
var sequence = Enumerable.Range(1, count);
var xs = Enumerable.Range(1, count);
using var sequence = xs.AsTestingSequence();
var result = sequence.Exclude(startIndex, excludeCount);

Assert.That(result, Is.EqualTo(sequence.Take(startIndex).Concat(sequence.Skip(startIndex + excludeCount))));
Assert.That(result, Is.EqualTo(xs.Take(startIndex).Concat(xs.Skip(startIndex + excludeCount))));
}

/// <summary>
Expand All @@ -129,7 +132,7 @@ public void TestExcludeSequenceMiddle()
public void TestExcludeEntireSequence()
{
const int count = 10;
var sequence = Enumerable.Range(1, count);
using var sequence = Enumerable.Range(1, count).AsTestingSequence();
var result = sequence.Exclude(0, count);

Assert.That(result, Is.Empty);
Expand All @@ -142,10 +145,11 @@ public void TestExcludeEntireSequence()
public void TestExcludeCountGreaterThanSequenceLength()
{
const int count = 10;
var sequence = Enumerable.Range(1, count);
var xs = Enumerable.Range(1, count);
using var sequence = xs.AsTestingSequence();
var result = sequence.Exclude(1, count * 10);

Assert.That(result, Is.EqualTo(sequence.Take(1)));
Assert.That(result, Is.EqualTo(xs.Take(1)));
}

/// <summary>
Expand All @@ -155,19 +159,11 @@ public void TestExcludeCountGreaterThanSequenceLength()
public void TestExcludeStartIndexGreaterThanSequenceLength()
{
const int count = 10;
var sequence = Enumerable.Range(1, count);
var xs = Enumerable.Range(1, count);
using var sequence = xs.AsTestingSequence();
var result = sequence.Exclude(count + 5, count);

Assert.That(result, Is.EqualTo(sequence));
}

[TestCase(new[] { 0, 1, 2, 3, 4, 5 }, 0, 6, ExpectedResult = new int[0])]
[TestCase(new[] { 0, 1, 2, 3, 4, 5 }, 2, 6, ExpectedResult = new[] { 0, 1 })]
[TestCase(new[] { 0, 1, 2, 3, 4, 5 }, 0, 3, ExpectedResult = new[] { 3, 4, 5 })]
[TestCase(new[] { 0, 1, 2, 3, 4, 5 }, 2, 3, ExpectedResult = new[] { 0, 1, 5 })]
public int[] TestExclude(int[] source, int startIndex, int count)
{
return source.AsTestingSequence().Exclude(startIndex, count).ToArray();
Assert.That(result, Is.EqualTo(xs));
}
}
}

0 comments on commit 7a85c95

Please sign in to comment.