From d13131eeedaaf1267d1490b060aecb28eea419e2 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Mon, 1 Jul 2024 09:56:16 -0400 Subject: [PATCH] Address test feedback --- .../ConcurrentDictionaryTests.cs | 33 ++++++++----------- .../Generic/CollectionExtensionsTests.cs | 33 ++++++++----------- 2 files changed, 28 insertions(+), 38 deletions(-) diff --git a/src/libraries/System.Collections.Concurrent/tests/ConcurrentDictionary/ConcurrentDictionaryTests.cs b/src/libraries/System.Collections.Concurrent/tests/ConcurrentDictionary/ConcurrentDictionaryTests.cs index 3302686ac06b6..ce05af556da9c 100644 --- a/src/libraries/System.Collections.Concurrent/tests/ConcurrentDictionary/ConcurrentDictionaryTests.cs +++ b/src/libraries/System.Collections.Concurrent/tests/ConcurrentDictionary/ConcurrentDictionaryTests.cs @@ -1105,28 +1105,23 @@ public void GetAlternateLookup_FailsWhenIncompatible() Assert.False(dictionary.TryGetAlternateLookup(out _)); } + public static IEnumerable Dictionary_GetAlternateLookup_OperationsMatchUnderlyingDictionary_MemberData() + { + yield return new object[] { EqualityComparer.Default }; + yield return new object[] { StringComparer.Ordinal }; + yield return new object[] { StringComparer.OrdinalIgnoreCase }; + yield return new object[] { StringComparer.InvariantCulture }; + yield return new object[] { StringComparer.InvariantCultureIgnoreCase }; + yield return new object[] { StringComparer.CurrentCulture }; + yield return new object[] { StringComparer.CurrentCultureIgnoreCase }; + } + [Theory] - [InlineData(0)] - [InlineData(1)] - [InlineData(2)] - [InlineData(3)] - [InlineData(4)] - [InlineData(5)] - [InlineData(6)] - public void GetAlternateLookup_OperationsMatchUnderlyingDictionary(int mode) + [MemberData(nameof(Dictionary_GetAlternateLookup_OperationsMatchUnderlyingDictionary_MemberData))] + public void GetAlternateLookup_OperationsMatchUnderlyingDictionary(IEqualityComparer comparer) { // Test with a variety of comparers to ensure that the alternate lookup is consistent with the underlying dictionary - ConcurrentDictionary dictionary = new(mode switch - { - 0 => EqualityComparer.Default, - 1 => StringComparer.Ordinal, - 2 => StringComparer.OrdinalIgnoreCase, - 3 => StringComparer.InvariantCulture, - 4 => StringComparer.InvariantCultureIgnoreCase, - 5 => StringComparer.CurrentCulture, - 6 => StringComparer.CurrentCultureIgnoreCase, - _ => throw new ArgumentOutOfRangeException(nameof(mode)) - }); + ConcurrentDictionary dictionary = new(comparer); ConcurrentDictionary.AlternateLookup> lookup = dictionary.GetAlternateLookup>(); Assert.Same(dictionary, lookup.Dictionary); Assert.Same(lookup.Dictionary, lookup.Dictionary); diff --git a/src/libraries/System.Collections/tests/Generic/CollectionExtensionsTests.cs b/src/libraries/System.Collections/tests/Generic/CollectionExtensionsTests.cs index 00333c6203495..b43f5affdaee5 100644 --- a/src/libraries/System.Collections/tests/Generic/CollectionExtensionsTests.cs +++ b/src/libraries/System.Collections/tests/Generic/CollectionExtensionsTests.cs @@ -180,28 +180,23 @@ public void GetAlternateLookup_FailsWhenIncompatible() Assert.False(hashSet.TryGetAlternateLookup(out _)); } + public static IEnumerable Dictionary_GetAlternateLookup_OperationsMatchUnderlyingDictionary_MemberData() + { + yield return new object[] { EqualityComparer.Default }; + yield return new object[] { StringComparer.Ordinal }; + yield return new object[] { StringComparer.OrdinalIgnoreCase }; + yield return new object[] { StringComparer.InvariantCulture }; + yield return new object[] { StringComparer.InvariantCultureIgnoreCase }; + yield return new object[] { StringComparer.CurrentCulture }; + yield return new object[] { StringComparer.CurrentCultureIgnoreCase }; + } + [Theory] - [InlineData(0)] - [InlineData(1)] - [InlineData(2)] - [InlineData(3)] - [InlineData(4)] - [InlineData(5)] - [InlineData(6)] - public void Dictionary_GetAlternateLookup_OperationsMatchUnderlyingDictionary(int mode) + [MemberData(nameof(Dictionary_GetAlternateLookup_OperationsMatchUnderlyingDictionary_MemberData))] + public void Dictionary_GetAlternateLookup_OperationsMatchUnderlyingDictionary(IEqualityComparer comparer) { // Test with a variety of comparers to ensure that the alternate lookup is consistent with the underlying dictionary - Dictionary dictionary = new(mode switch - { - 0 => EqualityComparer.Default, - 1 => StringComparer.Ordinal, - 2 => StringComparer.OrdinalIgnoreCase, - 3 => StringComparer.InvariantCulture, - 4 => StringComparer.InvariantCultureIgnoreCase, - 5 => StringComparer.CurrentCulture, - 6 => StringComparer.CurrentCultureIgnoreCase, - _ => throw new ArgumentOutOfRangeException(nameof(mode)) - }); + Dictionary dictionary = new(comparer); Dictionary.AlternateLookup> lookup = dictionary.GetAlternateLookup>(); Assert.Same(dictionary, lookup.Dictionary); Assert.Same(lookup.Dictionary, lookup.Dictionary);