-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restore
Slice
to supported operator (#588)
- Loading branch information
1 parent
7126989
commit a10f2e8
Showing
2 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
namespace Test; | ||
|
||
/// <summary> | ||
/// Verify the behavior of the Slice operator | ||
/// </summary> | ||
public class SliceTests | ||
{ | ||
/// <summary> | ||
/// Verify that Slice evaluates in a lazy manner. | ||
/// </summary> | ||
[Fact] | ||
public void TestSliceIsLazy() | ||
{ | ||
_ = new BreakingSequence<int>().Slice(10, 10); | ||
} | ||
|
||
public static IEnumerable<object[]> GetSequences() => | ||
Enumerable.Range(1, 5) | ||
.GetCollectionSequences() | ||
.Select(x => new object[] { x }); | ||
|
||
[Theory] | ||
[MemberData(nameof(GetSequences))] | ||
public void TestSliceIdentity(IDisposableEnumerable<int> seq) | ||
{ | ||
using (seq) | ||
{ | ||
var result = seq.Slice(0, 5); | ||
result.AssertSequenceEqual(1, 2, 3, 4, 5); | ||
} | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(GetSequences))] | ||
public void TestSliceFirstItem(IDisposableEnumerable<int> seq) | ||
{ | ||
using (seq) | ||
{ | ||
var result = seq.Slice(0, 1); | ||
result.AssertSequenceEqual(1); | ||
} | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(GetSequences))] | ||
public void TestSliceLastItem(IDisposableEnumerable<int> seq) | ||
{ | ||
using (seq) | ||
{ | ||
var result = seq.Slice(4, 1); | ||
result.AssertSequenceEqual(5); | ||
} | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(GetSequences))] | ||
public void TestSliceSmallerThanSequence(IDisposableEnumerable<int> seq) | ||
{ | ||
using (seq) | ||
{ | ||
var result = seq.Slice(1, 2); | ||
result.AssertSequenceEqual(2, 3); | ||
} | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(GetSequences))] | ||
public void TestSliceLongerThanSequence(IDisposableEnumerable<int> seq) | ||
{ | ||
using (seq) | ||
{ | ||
var result = seq.Slice(3, 5); | ||
result.AssertSequenceEqual(4, 5); | ||
} | ||
} | ||
} |