-
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from Cysharp/operator-unit-tests
Operator unit tests
- Loading branch information
Showing
11 changed files
with
202 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
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,12 @@ | ||
namespace R3.Tests.OperatorTests; | ||
|
||
public class DefaultIfEmptyTest | ||
{ | ||
[Fact] | ||
public void DefaultIfEmpty() | ||
{ | ||
using var list = Observable.Empty<int>().DefaultIfEmpty().ToLiveList(); | ||
|
||
list.AssertEqual([0]); | ||
} | ||
} |
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,28 @@ | ||
namespace R3.Tests.OperatorTests; | ||
|
||
public class DistinctByTest | ||
{ | ||
[Fact] | ||
public void DistinctBy() | ||
{ | ||
var source = new Subject<(int, int)>(); | ||
|
||
using var list = source.DistinctBy(static x => x.Item1).ToLiveList(); | ||
|
||
source.OnNext((1, 10)); | ||
source.OnNext((2, 20)); | ||
source.OnNext((3, 30)); | ||
source.OnNext((1, 100)); | ||
source.OnNext((2, 200)); | ||
source.OnNext((3, 300)); | ||
source.OnNext((4, 400)); | ||
|
||
list.AssertEqual( | ||
[ | ||
(1, 10), | ||
(2, 20), | ||
(3, 30), | ||
(4, 400) | ||
]); | ||
} | ||
} |
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,22 @@ | ||
namespace R3.Tests.OperatorTests; | ||
|
||
public class DistinctTest | ||
{ | ||
[Fact] | ||
public void Distinct() | ||
{ | ||
var source = new Subject<int>(); | ||
|
||
using var list = source.Distinct().ToLiveList(); | ||
|
||
source.OnNext(1); | ||
source.OnNext(2); | ||
source.OnNext(3); | ||
source.OnNext(1); | ||
source.OnNext(2); | ||
source.OnNext(3); | ||
source.OnNext(4); | ||
|
||
list.AssertEqual([1, 2, 3, 4]); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
tests/R3.Tests/OperatorTests/DistinctUntilChangedByTest.cs
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,28 @@ | ||
namespace R3.Tests.OperatorTests; | ||
|
||
public class DistinctUntilChangedByTest | ||
{ | ||
[Fact] | ||
public void DistinctUntilChangedBy() | ||
{ | ||
var source = new Subject<(int, int)>(); | ||
|
||
using var list = source.DistinctUntilChangedBy(static x => x.Item1).ToLiveList(); | ||
|
||
source.OnNext((1, 10)); | ||
source.OnNext((2, 20)); | ||
source.OnNext((3, 30)); | ||
source.OnNext((3, 300)); | ||
source.OnNext((2, 200)); | ||
source.OnNext((1, 100)); | ||
|
||
list.AssertEqual( | ||
[ | ||
(1, 10), | ||
(2, 20), | ||
(3, 30), | ||
(2, 200), | ||
(1, 100) | ||
]); | ||
} | ||
} |
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,21 @@ | ||
namespace R3.Tests.OperatorTests; | ||
|
||
public class DistinctUntilChangedTest | ||
{ | ||
[Fact] | ||
public void DistinctUntilChanged() | ||
{ | ||
var source = new Subject<int>(); | ||
|
||
using var list = source.DistinctUntilChanged().ToLiveList(); | ||
|
||
source.OnNext(1); | ||
source.OnNext(2); | ||
source.OnNext(3); | ||
source.OnNext(3); | ||
source.OnNext(2); | ||
source.OnNext(1); | ||
|
||
list.AssertEqual([1, 2, 3, 2, 1]); | ||
} | ||
} |
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,16 @@ | ||
namespace R3.Tests.OperatorTests; | ||
|
||
public class PairwiseTest | ||
{ | ||
[Fact] | ||
public void Pairwise() | ||
{ | ||
using var list = Observable.Range(1, 3).Pairwise().ToLiveList(); | ||
|
||
list.AssertEqual( | ||
[ | ||
(1, 2), | ||
(2, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
namespace R3.Tests.OperatorTests; | ||
|
||
public class ScanTest | ||
{ | ||
[Fact] | ||
public void Scan() | ||
{ | ||
using var list = Observable | ||
.Range(1, 3) | ||
.Scan(static (first, second) => first + second) | ||
.ToLiveList(); | ||
|
||
list.AssertEqual([ 1, 3, 6 ]); | ||
} | ||
|
||
[Fact] | ||
public void ScanWithSeed() | ||
{ | ||
using var list = Observable | ||
.Range(1, 3) | ||
.Scan(1, static (first, second) => first + second) | ||
.ToLiveList(); | ||
|
||
list.AssertEqual([ 2, 4, 7]); | ||
} | ||
} |
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,39 @@ | ||
namespace R3.Tests.OperatorTests; | ||
|
||
public class SwitchTest | ||
{ | ||
[Fact] | ||
public void Switch() | ||
{ | ||
var sources = new Subject<Observable<int>>(); | ||
|
||
using var list = sources.Switch().ToLiveList(); | ||
|
||
var source1 = new Subject<int>(); | ||
var source2 = new Subject<int>(); | ||
|
||
sources.OnNext(source1); | ||
|
||
list.AssertEmpty(); | ||
|
||
source1.OnNext(1); | ||
source1.OnNext(2); | ||
|
||
sources.OnNext(source2); | ||
|
||
source2.OnNext(10); | ||
|
||
source1.OnNext(3); | ||
|
||
list.AssertEqual([1, 2, 10]); | ||
|
||
source1.OnCompleted(); | ||
source2.OnCompleted(); | ||
|
||
list.AssertIsNotCompleted(); | ||
|
||
sources.OnCompleted(); | ||
|
||
list.AssertIsCompleted(); | ||
} | ||
} |