Repository: dotnet/runtime
File: src/libraries/System.Collections/tests/Generic/HashSet/HashSet.Generic.Tests.cs (C#)

Code before:
                else
                {
                    Assert.Equal(internalTypeName, set.Comparer.GetType().ToString());
                }

                Assert.True(equalityComparer.Equals(set.Comparer));
            }
        }

        #endregion

        #region UnionWith

        [Theory]
        [InlineData(0, true, true)]
        [InlineData(0, true, false)]
        [InlineData(0, false, true)]
        [InlineData(0, false, false)]
        [InlineData(1, true, true)]
        [InlineData(1, true, false)]
        [InlineData(1, false, true)]
        [InlineData(1, false, false)]
        [InlineData(75, true, true)]
        [InlineData(75, true, false)]
        [InlineData(75, false, true)]
        [InlineData(75, false, false)]
        public void HashSet_Generic_UnionWith_HashSet(int count, bool destinationEmpty, bool sourceSparseFilled)
        {
            HashSet<T> source = (HashSet<T>)CreateEnumerable(EnumerableType.HashSet, null, count, 0, 0);

            if (sourceSparseFilled)
            {
                List<T> sourceElements = source.ToList();
                foreach (int i in NonSquares(count))
                    source.Remove(sourceElements[i]);
            }

            HashSet<T> destination = destinationEmpty
                ? new HashSet<T>(source.Comparer)
                : (HashSet<T>)GenericISetFactory(1);

            HashSet<T> expected = new HashSet<T>(destination, source.Comparer);
            foreach (T item in source)
                expected.Add(item);

            destination.UnionWith(source);

            Assert.True(expected.SetEquals(destination));
        }

        #endregion

Review comment (suggestion):
@copilot, this should be better as a MemberData that yields all of the values from three foreach loops or LINQ from exoressions

Code after:
                else
                {
                    Assert.Equal(internalTypeName, set.Comparer.GetType().ToString());
                }

                Assert.True(equalityComparer.Equals(set.Comparer));
            }
        }

        #endregion

        #region UnionWith

        public static IEnumerable<object[]> UnionWith_HashSet_TestData()
        {
            foreach (int count in new[] { 0, 1, 75 })
            {
                foreach (bool destinationEmpty in new[] { true, false })
                {
                    foreach (bool sourceSparseFilled in new[] { true, false })
                    {
                        yield return new object[] { count, destinationEmpty, sourceSparseFilled };
                    }
                }
            }
        }

        [Theory]
        [MemberData(nameof(UnionWith_HashSet_TestData))]
        public void HashSet_Generic_UnionWith_HashSet(int count, bool destinationEmpty, bool sourceSparseFilled)
        {
            HashSet<T> source = (HashSet<T>)CreateEnumerable(EnumerableType.HashSet, null, count, 0, 0);

            if (sourceSparseFilled)
            {
                List<T> sourceElements = source.ToList();
                foreach (int i in NonSquares(count))
                    source.Remove(sourceElements[i]);
            }

            HashSet<T> destination = destinationEmpty
                ? new HashSet<T>(source.Comparer)
                : (HashSet<T>)GenericISetFactory(1);

            HashSet<T> expected = new HashSet<T>(destination, source.Comparer);
            foreach (T item in source)
                expected.Add(item);

            destination.UnionWith(source);

            Assert.True(expected.SetEquals(destination));