diff --git a/src/libraries/System.Linq/tests/AggregateByTests.cs b/src/libraries/System.Linq/tests/AggregateByTests.cs index 6232ce24a6df4..b574660c9e5ac 100644 --- a/src/libraries/System.Linq/tests/AggregateByTests.cs +++ b/src/libraries/System.Linq/tests/AggregateByTests.cs @@ -93,25 +93,10 @@ public void AggregateBy_SourceThrowsOnCurrent() Assert.Throws(() => enumerator.MoveNext()); } - [Theory] - [ActiveIssue("https://github.com/dotnet/runtime/issues/92387", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))] - [MemberData(nameof(AggregateBy_TestData))] - public static void AggregateBy_HasExpectedOutput(IEnumerable source, Func keySelector, Func seedSelector, Func func, IEqualityComparer? comparer, IEnumerable> expected) - { - Assert.Equal(expected, source.AggregateBy(keySelector, seedSelector, func, comparer)); - } - - [Theory] - [ActiveIssue("https://github.com/dotnet/runtime/issues/92387", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))] - [MemberData(nameof(AggregateBy_TestData))] - public static void AggregateBy_RunOnce_HasExpectedOutput(IEnumerable source, Func keySelector, Func seedSelector, Func func, IEqualityComparer? comparer, IEnumerable> expected) - { - Assert.Equal(expected, source.RunOnce().AggregateBy(keySelector, seedSelector, func, comparer)); - } - - public static IEnumerable AggregateBy_TestData() + [Fact] + public void AggregateBy_HasExpectedOutput() { - yield return WrapArgs( + Validate( source: Enumerable.Empty(), keySelector: x => x, seedSelector: x => 0, @@ -119,7 +104,7 @@ public static IEnumerable AggregateBy_TestData() comparer: null, expected: Enumerable.Empty>()); - yield return WrapArgs( + Validate( source: Enumerable.Range(0, 10), keySelector: x => x, seedSelector: x => 0, @@ -127,7 +112,7 @@ public static IEnumerable AggregateBy_TestData() comparer: null, expected: Enumerable.Range(0, 10).Select(x => new KeyValuePair(x, x))); - yield return WrapArgs( + Validate( source: Enumerable.Range(5, 10), keySelector: x => true, seedSelector: x => 0, @@ -135,7 +120,7 @@ public static IEnumerable AggregateBy_TestData() comparer: null, expected: Enumerable.Repeat(true, 1).Select(x => new KeyValuePair(x, 95))); - yield return WrapArgs( + Validate( source: Enumerable.Range(0, 20), keySelector: x => x % 5, seedSelector: x => 0, @@ -143,7 +128,7 @@ public static IEnumerable AggregateBy_TestData() comparer: null, expected: Enumerable.Range(0, 5).Select(x => new KeyValuePair(x, 30 + 4 * x))); - yield return WrapArgs( + Validate( source: Enumerable.Repeat(5, 20), keySelector: x => x, seedSelector: x => 0, @@ -151,7 +136,7 @@ public static IEnumerable AggregateBy_TestData() comparer: null, expected: Enumerable.Repeat(5, 1).Select(x => new KeyValuePair(x, 100))); - yield return WrapArgs( + Validate( source: new string[] { "Bob", "bob", "tim", "Bob", "Tim" }, keySelector: x => x, seedSelector: x => string.Empty, @@ -165,7 +150,7 @@ public static IEnumerable AggregateBy_TestData() new("Tim", "Tim"), ]); - yield return WrapArgs( + Validate( source: new string[] { "Bob", "bob", "tim", "Bob", "Tim" }, keySelector: x => x, seedSelector: x => string.Empty, @@ -177,7 +162,7 @@ public static IEnumerable AggregateBy_TestData() new("tim", "timTim") ]); - yield return WrapArgs( + Validate( source: new (string Name, int Age)[] { ("Tom", 20), ("Dick", 30), ("Harry", 40) }, keySelector: x => x.Age, seedSelector: x => $"I am {x} and my name is ", @@ -190,7 +175,7 @@ public static IEnumerable AggregateBy_TestData() new(40, "I am 40 and my name is Harry") ]); - yield return WrapArgs( + Validate( source: new (string Name, int Age)[] { ("Tom", 20), ("Dick", 20), ("Harry", 40) }, keySelector: x => x.Age, seedSelector: x => $"I am {x} and my name is", @@ -202,7 +187,7 @@ public static IEnumerable AggregateBy_TestData() new(40, "I am 40 and my name is maybe Harry") ]); - yield return WrapArgs( + Validate( source: new (string Name, int Age)[] { ("Bob", 20), ("bob", 20), ("Harry", 20) }, keySelector: x => x.Name, seedSelector: x => 0, @@ -210,7 +195,7 @@ public static IEnumerable AggregateBy_TestData() comparer: null, expected: new string[] { "Bob", "bob", "Harry" }.Select(x => new KeyValuePair(x, 20))); - yield return WrapArgs( + Validate( source: new (string Name, int Age)[] { ("Bob", 20), ("bob", 30), ("Harry", 40) }, keySelector: x => x.Name, seedSelector: x => 0, @@ -222,8 +207,11 @@ public static IEnumerable AggregateBy_TestData() new("Harry", 40) ]); - object[] WrapArgs(IEnumerable source, Func keySelector, Func seedSelector, Func func, IEqualityComparer? comparer, IEnumerable> expected) - => new object[] { source, keySelector, seedSelector, func, comparer, expected }; + static void Validate(IEnumerable source, Func keySelector, Func seedSelector, Func func, IEqualityComparer? comparer, IEnumerable> expected) + { + Assert.Equal(expected, source.AggregateBy(keySelector, seedSelector, func, comparer)); + Assert.Equal(expected, source.RunOnce().AggregateBy(keySelector, seedSelector, func, comparer)); + } } [Fact] diff --git a/src/libraries/System.Linq/tests/CountByTests.cs b/src/libraries/System.Linq/tests/CountByTests.cs index 258a067ece505..cd041051d8098 100644 --- a/src/libraries/System.Linq/tests/CountByTests.cs +++ b/src/libraries/System.Linq/tests/CountByTests.cs @@ -57,55 +57,40 @@ public void CountBy_SourceThrowsOnCurrent() Assert.Throws(() => enumerator.MoveNext()); } - [Theory] - [ActiveIssue("https://github.com/dotnet/runtime/issues/92387", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))] - [MemberData(nameof(CountBy_TestData))] - public static void CountBy_HasExpectedOutput(IEnumerable source, Func keySelector, IEqualityComparer? comparer, IEnumerable> expected) - { - Assert.Equal(expected, source.CountBy(keySelector, comparer)); - } - - [Theory] - [ActiveIssue("https://github.com/dotnet/runtime/issues/92387", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))] - [MemberData(nameof(CountBy_TestData))] - public static void CountBy_RunOnce_HasExpectedOutput(IEnumerable source, Func keySelector, IEqualityComparer? comparer, IEnumerable> expected) - { - Assert.Equal(expected, source.RunOnce().CountBy(keySelector, comparer)); - } - - public static IEnumerable CountBy_TestData() + [Fact] + public void CountBy_HasExpectedOutput() { - yield return WrapArgs( + Validate( source: Enumerable.Empty(), keySelector: x => x, comparer: null, expected: Enumerable.Empty>()); - yield return WrapArgs( + Validate( source: Enumerable.Range(0, 10), keySelector: x => x, comparer: null, expected: Enumerable.Range(0, 10).Select(x => new KeyValuePair(x, 1))); - yield return WrapArgs( + Validate( source: Enumerable.Range(5, 10), keySelector: x => true, comparer: null, expected: Enumerable.Repeat(true, 1).Select(x => new KeyValuePair(x, 10))); - yield return WrapArgs( + Validate( source: Enumerable.Range(0, 20), keySelector: x => x % 5, comparer: null, expected: Enumerable.Range(0, 5).Select(x => new KeyValuePair(x, 4))); - yield return WrapArgs( + Validate( source: Enumerable.Repeat(5, 20), keySelector: x => x, comparer: null, expected: Enumerable.Repeat(5, 1).Select(x => new KeyValuePair(x, 20))); - yield return WrapArgs( + Validate( source: new string[] { "Bob", "bob", "tim", "Bob", "Tim" }, keySelector: x => x, null, @@ -117,7 +102,7 @@ public static IEnumerable CountBy_TestData() new("Tim", 1) ]); - yield return WrapArgs( + Validate( source: new string[] { "Bob", "bob", "tim", "Bob", "Tim" }, keySelector: x => x, StringComparer.OrdinalIgnoreCase, @@ -127,13 +112,13 @@ public static IEnumerable CountBy_TestData() new("tim", 2) ]); - yield return WrapArgs( + Validate( source: new (string Name, int Age)[] { ("Tom", 20), ("Dick", 30), ("Harry", 40) }, keySelector: x => x.Age, comparer: null, expected: new int[] { 20, 30, 40 }.Select(x => new KeyValuePair(x, 1))); - yield return WrapArgs( + Validate( source: new (string Name, int Age)[] { ("Tom", 20), ("Dick", 20), ("Harry", 40) }, keySelector: x => x.Age, comparer: null, @@ -143,13 +128,13 @@ public static IEnumerable CountBy_TestData() new(40, 1) ]); - yield return WrapArgs( + Validate( source: new (string Name, int Age)[] { ("Bob", 20), ("bob", 30), ("Harry", 40) }, keySelector: x => x.Name, comparer: null, expected: new string[] { "Bob", "bob", "Harry" }.Select(x => new KeyValuePair(x, 1))); - yield return WrapArgs( + Validate( source: new (string Name, int Age)[] { ("Bob", 20), ("bob", 30), ("Harry", 40) }, keySelector: x => x.Name, comparer: StringComparer.OrdinalIgnoreCase, @@ -159,8 +144,11 @@ public static IEnumerable CountBy_TestData() new("Harry", 1) ]); - object[] WrapArgs(IEnumerable source, Func keySelector, IEqualityComparer? comparer, IEnumerable> expected) - => new object[] { source, keySelector, comparer, expected }; + static void Validate(IEnumerable source, Func keySelector, IEqualityComparer? comparer, IEnumerable> expected) + { + Assert.Equal(expected, source.CountBy(keySelector, comparer)); + Assert.Equal(expected, source.RunOnce().CountBy(keySelector, comparer)); + } } } }