-
-
Notifications
You must be signed in to change notification settings - Fork 108
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
6 changed files
with
264 additions
and
10 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
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
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,89 @@ | ||
namespace R3.Tests.OperatorTests; | ||
|
||
public class SelectTest | ||
{ | ||
[Fact] | ||
public void Select() | ||
{ | ||
var subject = new Subject<int>(); | ||
using var list = subject.Select(x => x * 2).ToLiveList(); | ||
|
||
subject.OnNext(10); | ||
list.AssertEqual([20]); | ||
|
||
subject.OnNext(20); | ||
list.AssertEqual([20, 40]); | ||
|
||
subject.OnNext(40); | ||
list.AssertEqual([20, 40, 80]); | ||
|
||
subject.OnCompleted(); | ||
list.AssertIsCompleted(); | ||
} | ||
|
||
// WhereSelect | ||
[Fact] | ||
public void WhereSelect() | ||
{ | ||
var subject = new Subject<int>(); | ||
using var list = subject.Where(x => x % 2 == 0).Select(x => x * 2).ToLiveList(); | ||
|
||
subject.OnNext(10); | ||
list.AssertEqual([20]); | ||
|
||
subject.OnNext(11); | ||
list.AssertEqual([20]); | ||
|
||
subject.OnNext(20); | ||
list.AssertEqual([20, 40]); | ||
|
||
subject.OnNext(40); | ||
list.AssertEqual([20, 40, 80]); | ||
|
||
subject.OnNext(99); | ||
list.AssertEqual([20, 40, 80]); | ||
|
||
subject.OnCompleted(); | ||
list.AssertIsCompleted(); | ||
} | ||
|
||
// SelectWithIndex | ||
[Fact] | ||
public void SelectWithIndex() | ||
{ | ||
var subject = new Subject<int>(); | ||
using var list = subject.Select((x, i) => x * 2 + i).ToLiveList(); | ||
|
||
subject.OnNext(10); | ||
list.AssertEqual([20]); | ||
|
||
subject.OnNext(20); | ||
list.AssertEqual([20, 41]); | ||
|
||
subject.OnNext(40); | ||
list.AssertEqual([20, 41, 82]); | ||
|
||
subject.OnCompleted(); | ||
list.AssertIsCompleted(); | ||
} | ||
|
||
// Select State | ||
[Fact] | ||
public void SelectState() | ||
{ | ||
var subject = new Subject<int>(); | ||
using var list = subject.Select("a", (x, state) => x * 2 + state).ToLiveList(); | ||
|
||
subject.OnNext(10); | ||
list.AssertEqual(["20a"]); | ||
|
||
subject.OnNext(20); | ||
list.AssertEqual(["20a", "40a"]); | ||
|
||
subject.OnNext(40); | ||
list.AssertEqual(["20a", "40a", "80a"]); | ||
|
||
subject.OnCompleted(); | ||
list.AssertIsCompleted(); | ||
} | ||
} |
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