Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/Cysharp/R3
Browse files Browse the repository at this point in the history
  • Loading branch information
neuecc committed Jul 23, 2024
2 parents 142ef1e + bcd41da commit 9de02ab
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/R3/Operators/MaxByMinByAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ protected override void OnNextCore(T value)
{
hasValue = true;
latestValue = value;
latestKey = keySelector(value);
return;
}

Expand All @@ -49,7 +50,6 @@ protected override void OnNextCore(T value)
{
latestValue = value;
latestKey = key;
hasValue = true;
}
}

Expand Down Expand Up @@ -91,6 +91,7 @@ protected override void OnNextCore(T value)
{
hasValue = true;
latestValue = value;
latestKey = keySelector(value);
return;
}

Expand All @@ -99,7 +100,6 @@ protected override void OnNextCore(T value)
{
latestValue = value;
latestKey = key;
hasValue = true;
}
}

Expand Down
20 changes: 19 additions & 1 deletion tests/R3.Tests/OperatorTests/MaxByTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,29 @@
public class MaxByTest
{
[Fact]
public async Task MaxBy()
public async Task First()
{
var items = new[] { (3, 1), (2, 2), (1, 3) }.ToObservable();

var task = items.MaxByAsync(static x => x.Item1);
(await task).Should().Be((3, 1));
}

[Fact]
public async Task Last()
{
var items = new[] { (1, 3), (2, 2), (3, 1) }.ToObservable();

var task = items.MaxByAsync(static x => x.Item1);
(await task).Should().Be((3, 1));
}

[Fact]
public async Task Midway()
{
var items = new[] { (2, 2), (3, 1), (1, 3) }.ToObservable();

var task = items.MaxByAsync(static x => x.Item1);
(await task).Should().Be((3, 1));
}
}
25 changes: 23 additions & 2 deletions tests/R3.Tests/OperatorTests/MaxTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,29 @@ public async Task One()
[Fact]
public async Task MultipleValue()
{
var min = await new[] { 1, 10, 1, 3, 4, 6, 7, 4 }.ToObservable().MaxAsync();
min.Should().Be(10);
var max = await new[] { 1, 10, 1, 3, 4, 6, 7, 4 }.ToObservable().MaxAsync();
max.Should().Be(10);
}

[Fact]
public async Task First()
{
var max = await new[] { 10, 1, 3, 4, 6, 7, 5 }.ToObservable().MaxAsync();
max.Should().Be(10);
}

[Fact]
public async Task Last()
{
var max = await new[] { 6, 2, 7, 1, 3, 4, 10 }.ToObservable().MaxAsync();
max.Should().Be(10);
}

[Fact]
public async Task Midway()
{
var max = await new[] { 6, 2, 7, 10, 3, 4, 1 }.ToObservable().MaxAsync();
max.Should().Be(10);
}

[Fact]
Expand Down
20 changes: 19 additions & 1 deletion tests/R3.Tests/OperatorTests/MinByTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,29 @@
public class MinByTest
{
[Fact]
public async Task MinBy()
public async Task First()
{
var items = new[] { (1, 3), (2, 2), (3, 1) }.ToObservable();

var task = items.MinByAsync(static x => x.Item1);
(await task).Should().Be((1, 3));
}

[Fact]
public async Task Last()
{
var items = new[] { (3, 1), (2, 2), (1, 3) }.ToObservable();

var task = items.MinByAsync(static x => x.Item1);
(await task).Should().Be((1, 3));
}

[Fact]
public async Task Midway()
{
var items = new[] { (2, 2), (1, 3), (3, 1) }.ToObservable();

var task = items.MinByAsync(static x => x.Item1);
(await task).Should().Be((1, 3));
}
}
21 changes: 21 additions & 0 deletions tests/R3.Tests/OperatorTests/MinMaxTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,27 @@ public async Task MultipleValues()
(await source.MinMaxAsync(x => x * 10)).Should().Be((10, 100));
}

[Fact]
public async Task First()
{
var minMax = await new[] { 1, 5, 3, 4, 6, 7, 10 }.ToObservable().MinMaxAsync();
minMax.Should().Be((1, 10));
}

[Fact]
public async Task Last()
{
var minMax = await new[] { 10, 2, 3, 4, 6, 7, 1 }.ToObservable().MinMaxAsync();
minMax.Should().Be((1, 10));
}

[Fact]
public async Task Midway()
{
var minMax = await new[] { 2, 4, 10, 3, 1, 6, 7, 5 }.ToObservable().MinMaxAsync();
minMax.Should().Be((1, 10));
}

[Fact]
public async Task Error()
{
Expand Down
21 changes: 21 additions & 0 deletions tests/R3.Tests/OperatorTests/MinTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,27 @@ public async Task MultipleValue()
min.Should().Be(1);
}

[Fact]
public async Task First()
{
var min = await new[] { 1, 10, 3, 4, 6, 7, 5 }.ToObservable().MinAsync();
min.Should().Be(1);
}

[Fact]
public async Task Last()
{
var min = await new[] { 2, 10, 3, 4, 6, 7, 1 }.ToObservable().MinAsync();
min.Should().Be(1);
}

[Fact]
public async Task Midway()
{
var min = await new[] { 2, 10, 3, 4, 1, 6, 7, 5 }.ToObservable().MinAsync();
min.Should().Be(1);
}

[Fact]
public async Task Error()
{
Expand Down

0 comments on commit 9de02ab

Please sign in to comment.