diff --git a/X10D.Tests/src/Linq/EnumerableTests.cs b/X10D.Tests/src/Linq/EnumerableTests.cs index 6d55bb025..99fe9ac77 100644 --- a/X10D.Tests/src/Linq/EnumerableTests.cs +++ b/X10D.Tests/src/Linq/EnumerableTests.cs @@ -12,7 +12,7 @@ public void Except_ShouldFilterElements_GivenMatchingElements() int[] source = Enumerable.Range(1, 10).ToArray(); int[] result = source.Except(5).ToArray(); - Assert.That(result, Is.EquivalentTo(new[] {1, 2, 3, 4, 6, 7, 8, 9, 10})); + Assert.That(result, Is.EquivalentTo(new[] { 1, 2, 3, 4, 6, 7, 8, 9, 10 })); } [Test] @@ -54,7 +54,7 @@ public void MinMax_ShouldReturnCorrectValues_UsingDefaultComparer() [Test] public void MinMax_ShouldReturnCorrectSelectedValues_UsingDefaultComparer() { - IEnumerable source = Enumerable.Range(1, 10).Select(i => new Person {Age = i}); + IEnumerable source = Enumerable.Range(1, 10).Select(i => new Person { Age = i }); (int minimum, int maximum) = source.MinMax(p => p.Age); Assert.Multiple(() => { @@ -62,7 +62,7 @@ public void MinMax_ShouldReturnCorrectSelectedValues_UsingDefaultComparer() Assert.That(maximum, Is.EqualTo(10)); }); - source = Enumerable.Range(1, 10).Select(i => new Person {Age = i}).ToArray(); + source = Enumerable.Range(1, 10).Select(i => new Person { Age = i }).ToArray(); (minimum, maximum) = source.MinMax(p => p.Age); Assert.Multiple(() => { @@ -74,7 +74,7 @@ public void MinMax_ShouldReturnCorrectSelectedValues_UsingDefaultComparer() [Test] public void MinMax_ShouldReturnOppositeSelectedValues_UsingInverseComparer() { - IEnumerable source = Enumerable.Range(1, 10).Select(i => new Person {Age = i}); + IEnumerable source = Enumerable.Range(1, 10).Select(i => new Person { Age = i }); (int minimum, int maximum) = source.MinMax(p => p.Age, new InverseComparer()); Assert.Multiple(() => { @@ -82,7 +82,7 @@ public void MinMax_ShouldReturnOppositeSelectedValues_UsingInverseComparer() Assert.That(maximum, Is.EqualTo(1)); }); - source = Enumerable.Range(1, 10).Select(i => new Person {Age = i}).ToArray(); + source = Enumerable.Range(1, 10).Select(i => new Person { Age = i }).ToArray(); (minimum, maximum) = source.MinMax(p => p.Age, new InverseComparer()); Assert.Multiple(() => { @@ -113,36 +113,65 @@ public void MinMax_ShouldReturnOppositeValues_UsingInverseComparer() public void MinMax_ShouldThrowArgumentNullException_GivenNullSelector() { IEnumerable source = []; - Assert.Throws(() => source.MinMax((Func)(null!))); - Assert.Throws(() => source.MinMax((Func)(null!), null)); + + Assert.Multiple(() => + { + Assert.Throws(() => source.MinMax((Func)(null!))); + Assert.Throws(() => source.MinMax((Func)(null!), null)); + }); } [Test] public void MinMax_ShouldThrowArgumentNullException_GivenNullSource() { IEnumerable? source = null; - Assert.Throws(() => source!.MinMax()); - Assert.Throws(() => source!.MinMax(v => v)); - Assert.Throws(() => source!.MinMax(null)); - Assert.Throws(() => source!.MinMax(v => v, null)); + + Assert.Multiple(() => + { + Assert.Throws(() => source!.MinMax()); + Assert.Throws(() => source!.MinMax(v => v)); + Assert.Throws(() => source!.MinMax(null)); + Assert.Throws(() => source!.MinMax(v => v, null)); + }); } [Test] public void MinMax_ShouldThrowInvalidOperationException_GivenEmptySource() { - Assert.Throws(() => Enumerable.Empty().MinMax()); - Assert.Throws(() => Array.Empty().MinMax()); - Assert.Throws(() => new List().MinMax()); - - Assert.Throws(() => Enumerable.Empty().MinMax(i => i * 2)); - Assert.Throws(() => Array.Empty().MinMax(i => i * 2)); - Assert.Throws(() => new List().MinMax(i => i * 2)); + Assert.Multiple(() => + { + Assert.Throws(() => + { + Empty().MinMax(); + return; + + static IEnumerable Empty() + { + yield break; + } + }); + Assert.Throws(() => Array.Empty().MinMax()); + Assert.Throws(() => new List().MinMax()); + + Assert.Throws(() => + { + Empty().MinMax(i => i * 2); + return; + + static IEnumerable Empty() + { + yield break; + } + }); + Assert.Throws(() => Array.Empty().MinMax(i => i * 2)); + Assert.Throws(() => new List().MinMax(i => i * 2)); + }); } [Test] public void MinMaxBy_ShouldReturnCorrectSelectedValues_UsingDefaultComparer() { - IEnumerable source = Enumerable.Range(1, 10).Select(i => new Person {Age = i}); + IEnumerable source = Enumerable.Range(1, 10).Select(i => new Person { Age = i }); (Person minimum, Person maximum) = source.MinMaxBy(p => p.Age); Assert.Multiple(() => { @@ -150,7 +179,7 @@ public void MinMaxBy_ShouldReturnCorrectSelectedValues_UsingDefaultComparer() Assert.That(maximum.Age, Is.EqualTo(10)); }); - source = Enumerable.Range(1, 10).Select(i => new Person {Age = i}).ToArray(); + source = Enumerable.Range(1, 10).Select(i => new Person { Age = i }).ToArray(); (minimum, maximum) = source.MinMaxBy(p => p.Age); Assert.Multiple(() => { @@ -162,7 +191,7 @@ public void MinMaxBy_ShouldReturnCorrectSelectedValues_UsingDefaultComparer() [Test] public void MinMaxBy_ShouldReturnOppositeSelectedValues_UsingInverseComparer() { - IEnumerable source = Enumerable.Range(1, 10).Select(i => new Person {Age = i}); + IEnumerable source = Enumerable.Range(1, 10).Select(i => new Person { Age = i }); (Person minimum, Person maximum) = source.MinMaxBy(p => p.Age, new InverseComparer()); Assert.Multiple(() => { @@ -170,7 +199,7 @@ public void MinMaxBy_ShouldReturnOppositeSelectedValues_UsingInverseComparer() Assert.That(maximum.Age, Is.EqualTo(1)); }); - source = Enumerable.Range(1, 10).Select(i => new Person {Age = i}).ToArray(); + source = Enumerable.Range(1, 10).Select(i => new Person { Age = i }).ToArray(); (minimum, maximum) = source.MinMaxBy(p => p.Age, new InverseComparer()); Assert.Multiple(() => { @@ -182,7 +211,7 @@ public void MinMaxBy_ShouldReturnOppositeSelectedValues_UsingInverseComparer() [Test] public void MinMaxBy_ShouldThrowArgumentNullException_GivenNullSelector() { - Person[] source = Enumerable.Range(1, 10).Select(i => new Person {Age = i}).ToArray(); + Person[] source = Enumerable.Range(1, 10).Select(i => new Person { Age = i }).ToArray(); Assert.Throws(() => source.MinMaxBy((Func)null!)); Assert.Throws(() => source.MinMaxBy((Func)null!, null)); @@ -201,8 +230,14 @@ public void MinMaxBy_ShouldThrowInvalidOperationException_GivenEmptySource() { Assert.Throws(() => { - IEnumerable source = []; + IEnumerable source = Empty(); _ = source.MinMaxBy(p => p.Age); + return; + + static IEnumerable Empty() + { + yield break; + } }); Assert.Throws(() =>