diff --git a/src/R3/Operators/MaxByMinByAsync.cs b/src/R3/Operators/MaxByMinByAsync.cs index acf1ff43..04948db4 100644 --- a/src/R3/Operators/MaxByMinByAsync.cs +++ b/src/R3/Operators/MaxByMinByAsync.cs @@ -41,6 +41,7 @@ protected override void OnNextCore(T value) { hasValue = true; latestValue = value; + latestKey = keySelector(value); return; } @@ -49,7 +50,6 @@ protected override void OnNextCore(T value) { latestValue = value; latestKey = key; - hasValue = true; } } @@ -91,6 +91,7 @@ protected override void OnNextCore(T value) { hasValue = true; latestValue = value; + latestKey = keySelector(value); return; } @@ -99,7 +100,6 @@ protected override void OnNextCore(T value) { latestValue = value; latestKey = key; - hasValue = true; } } diff --git a/tests/R3.Tests/OperatorTests/MaxByTest.cs b/tests/R3.Tests/OperatorTests/MaxByTest.cs index 06d98126..423d0e0b 100644 --- a/tests/R3.Tests/OperatorTests/MaxByTest.cs +++ b/tests/R3.Tests/OperatorTests/MaxByTest.cs @@ -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)); + } } diff --git a/tests/R3.Tests/OperatorTests/MaxTest.cs b/tests/R3.Tests/OperatorTests/MaxTest.cs index f3ed355c..51d74fbf 100644 --- a/tests/R3.Tests/OperatorTests/MaxTest.cs +++ b/tests/R3.Tests/OperatorTests/MaxTest.cs @@ -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] diff --git a/tests/R3.Tests/OperatorTests/MinByTest.cs b/tests/R3.Tests/OperatorTests/MinByTest.cs index 2bc1e217..dd6c4996 100644 --- a/tests/R3.Tests/OperatorTests/MinByTest.cs +++ b/tests/R3.Tests/OperatorTests/MinByTest.cs @@ -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)); + } } diff --git a/tests/R3.Tests/OperatorTests/MinMaxTest.cs b/tests/R3.Tests/OperatorTests/MinMaxTest.cs index 63bfa6ec..659cf65d 100644 --- a/tests/R3.Tests/OperatorTests/MinMaxTest.cs +++ b/tests/R3.Tests/OperatorTests/MinMaxTest.cs @@ -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() { diff --git a/tests/R3.Tests/OperatorTests/MinTest.cs b/tests/R3.Tests/OperatorTests/MinTest.cs index 5a9a22b3..f4aa8201 100644 --- a/tests/R3.Tests/OperatorTests/MinTest.cs +++ b/tests/R3.Tests/OperatorTests/MinTest.cs @@ -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() {