-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
4 changed files
with
400 additions
and
0 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,92 @@ | ||
// Copyright (c) David Karnok & Contributors. | ||
// Licensed under the Apache 2.0 License. | ||
// See LICENSE file in the project root for full license information. | ||
|
||
using Xunit; | ||
using async_enumerable_dotnet; | ||
using System.Linq; | ||
using System; | ||
|
||
namespace async_enumerable_dotnet_test | ||
{ | ||
public class CombineLatestTest | ||
{ | ||
[Fact] | ||
public async void Empty() | ||
{ | ||
await AsyncEnumerable.CombineLatest<int, int>(v => v.Sum()) | ||
.AssertResult(); | ||
} | ||
|
||
[Fact] | ||
public async void Single() | ||
{ | ||
await AsyncEnumerable.CombineLatest(v => v.Sum() + 1, | ||
AsyncEnumerable.Just(1)) | ||
.AssertResult(2); | ||
} | ||
|
||
[Fact] | ||
public async void One_Item_Each() | ||
{ | ||
await AsyncEnumerable.CombineLatest(v => v.Sum(), AsyncEnumerable.Just(1), AsyncEnumerable.Just(2)) | ||
.AssertResult(3); | ||
} | ||
|
||
[Fact] | ||
public async void One_Is_Empty() | ||
{ | ||
await AsyncEnumerable.CombineLatest(v => v.Sum(), AsyncEnumerable.Empty<int>(), AsyncEnumerable.Just(2)) | ||
.AssertResult(); | ||
} | ||
|
||
[Fact] | ||
public async void Two_Is_Empty() | ||
{ | ||
await AsyncEnumerable.CombineLatest(v => v.Sum(), AsyncEnumerable.Just(1), AsyncEnumerable.Empty<int>()) | ||
.AssertResult(); | ||
} | ||
|
||
[Fact] | ||
public async void ZigZag() | ||
{ | ||
var t = 200; | ||
if (Environment.GetEnvironmentVariable("CI") != null) | ||
{ | ||
t = 2000; | ||
} | ||
await AsyncEnumerable.CombineLatest(v => v.Sum(), | ||
AsyncEnumerable.Interval(1, 5, TimeSpan.FromMilliseconds(t)), | ||
AsyncEnumerable.Interval(1, 5, TimeSpan.FromMilliseconds(t + t / 2), TimeSpan.FromMilliseconds(t)).Map(v => v * 10) | ||
) | ||
.AssertResult(11, 12, 22, 23, 33, 34, 44, 45, 55); | ||
} | ||
|
||
[Fact] | ||
public async void Second_Many() | ||
{ | ||
var t = 200; | ||
if (Environment.GetEnvironmentVariable("CI") != null) | ||
{ | ||
t = 2000; | ||
} | ||
await AsyncEnumerable.CombineLatest(v => v.Sum(), | ||
AsyncEnumerable.Just(10L), | ||
AsyncEnumerable.Interval(1, 5, TimeSpan.FromMilliseconds(t + t / 2), TimeSpan.FromMilliseconds(t)) | ||
) | ||
.AssertResult(11, 12, 13, 14, 15); | ||
} | ||
|
||
[Fact] | ||
public async void Error() | ||
{ | ||
await AsyncEnumerable.CombineLatest(v => v.Sum(), | ||
AsyncEnumerable.Just<int>(1), | ||
AsyncEnumerable.Just(2).ConcatWith( | ||
AsyncEnumerable.Error<int>(new InvalidOperationException()) | ||
) | ||
) | ||
.AssertFailure(typeof(InvalidOperationException), 3); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.