-
-
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.
- Loading branch information
1 parent
82afd2a
commit ac8c83b
Showing
2 changed files
with
112 additions
and
4 deletions.
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,68 @@ | ||
namespace Test.Async; | ||
|
||
public class RepeatTest | ||
{ | ||
[Theory] | ||
[InlineData(1)] | ||
[InlineData(10)] | ||
[InlineData(50)] | ||
public async Task RepeatItemForeverBehavior(int repeats) | ||
{ | ||
var result = AsyncSuperEnumerable.Repeat(42); | ||
|
||
Assert.True(await result | ||
.Take(repeats) | ||
.AssertCount(repeats) | ||
.AllAsync(x => x == 42)); | ||
} | ||
|
||
[Fact] | ||
public void RepeatIsLazy() | ||
{ | ||
_ = new AsyncBreakingSequence<int>().Repeat(4); | ||
} | ||
|
||
[Fact] | ||
public void RepeatValidatesArguments() | ||
{ | ||
_ = Assert.Throws<ArgumentOutOfRangeException>("count", () => | ||
new AsyncBreakingSequence<int>().Repeat(0)); | ||
} | ||
|
||
[Fact] | ||
public async Task RepeatBehavior() | ||
{ | ||
await using var sequence = Enumerable.Range(1, 10).AsTestingSequence(); | ||
|
||
var result = sequence.Repeat(3); | ||
|
||
var expected = Enumerable.Empty<int>(); | ||
for (var i = 0; i < 3; i++) | ||
expected = expected.Concat(Enumerable.Range(1, 10)); | ||
|
||
await result.AssertSequenceEqual(expected); | ||
} | ||
|
||
[Fact] | ||
public void RepeatForeverIsLazy() | ||
{ | ||
_ = new AsyncBreakingSequence<int>().Repeat(); | ||
} | ||
|
||
[Theory] | ||
[InlineData(1)] | ||
[InlineData(10)] | ||
[InlineData(50)] | ||
public async Task RepeatForeverBehavior(int repeats) | ||
{ | ||
await using var sequence = Enumerable.Range(1, 10).AsTestingSequence(); | ||
|
||
var result = sequence.Repeat(); | ||
|
||
var expected = Enumerable.Empty<int>(); | ||
for (var i = 0; i < repeats; i++) | ||
expected = expected.Concat(Enumerable.Range(1, 10)); | ||
|
||
await result.Take(repeats * 10).AssertSequenceEqual(expected); | ||
} | ||
} |