1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4 
5 using System.Collections.Generic;
6 using System.Diagnostics;
7 using System.Linq;
8 using Xunit;
9 
10 namespace System.Collections.Tests
11 {
12     /// <summary>
13     /// Contains tests that ensure the correctness of any class that implements the generic
14     /// ISet interface.
15     ///
16     /// Tests for an ISet follow a rather different structure because of the consistency in
17     /// function signatures. Instead of having a test for every data scenario within a class for
18     /// every set function, there is instead a test for every configuration of enumerable parameter.
19     /// Each of those tests calls a Validation function that calculates the expected result and then
20     /// compares it to the actual result of the set operation.
21     /// </summary>
22     public abstract class ISet_Generic_Tests<T> : ICollection_Generic_Tests<T>
23     {
24         #region ISet<T> Helper methods
25 
26         /// <summary>
27         /// Creates an instance of an ISet{T} that can be used for testing.
28         /// </summary>
29         /// <returns>An instance of an ISet{T} that can be used for testing.</returns>
GenericISetFactory()30         protected abstract ISet<T> GenericISetFactory();
31 
32         /// <summary>
33         /// Creates an instance of an ISet{T} that can be used for testing.
34         /// </summary>
35         /// <param name="count">The number of unique items that the returned ISet{T} contains.</param>
36         /// <returns>An instance of an ISet{T} that can be used for testing.</returns>
GenericISetFactory(int count)37         protected virtual ISet<T> GenericISetFactory(int count)
38         {
39             ISet<T> collection = GenericISetFactory();
40             AddToCollection(collection, count);
41             return collection;
42         }
43 
AddToCollection(ICollection<T> collection, int numberOfItemsToAdd)44         protected override void AddToCollection(ICollection<T> collection, int numberOfItemsToAdd)
45         {
46             int seed = 9600;
47             ISet<T> set = (ISet<T>)collection;
48             while (set.Count < numberOfItemsToAdd)
49             {
50                 T toAdd = CreateT(seed++);
51                 while (set.Contains(toAdd) || (InvalidValues != Array.Empty<T>() && InvalidValues.Contains(toAdd, GetIEqualityComparer())))
52                     toAdd = CreateT(seed++);
53                 set.Add(toAdd);
54             }
55         }
56 
57         protected virtual int ISet_Large_Capacity => 1000;
58 
59         #endregion
60 
61         #region ICollection<T> Helper Methods
62 
GenericICollectionFactory()63         protected override ICollection<T> GenericICollectionFactory() => GenericISetFactory();
64 
GenericICollectionFactory(int count)65         protected override ICollection<T> GenericICollectionFactory(int count) => GenericISetFactory(count);
66 
67         protected override bool DuplicateValuesAllowed => false;
68         protected override bool DefaultValueWhenNotAllowed_Throws => false;
69 
70         #endregion
71 
72         #region ICollection_Generic
73 
74         [Theory]
75         [MemberData(nameof(ValidCollectionSizes))]
ICollection_Generic_Add_ReturnValue(int count)76         public void ICollection_Generic_Add_ReturnValue(int count)
77         {
78             if (!IsReadOnly)
79             {
80                 ISet<T> set = GenericISetFactory(count);
81                 int seed = 92834;
82                 T newValue = CreateT(seed++);
83                 while (set.Contains(newValue))
84                     newValue = CreateT(seed++);
85                 Assert.True(set.Add(newValue));
86                 if (!DuplicateValuesAllowed)
87                     Assert.False(set.Add(newValue));
88                 Assert.Equal(count + 1, set.Count);
89                 Assert.True(set.Contains(newValue));
90             }
91         }
92 
93         [Theory]
94         [MemberData(nameof(ValidCollectionSizes))]
ICollection_Generic_Add_DuplicateValue_DoesNothing(int count)95         public void ICollection_Generic_Add_DuplicateValue_DoesNothing(int count)
96         {
97             if (!IsReadOnly)
98             {
99                 if (!DuplicateValuesAllowed)
100                 {
101                     ICollection<T> collection = GenericICollectionFactory(count);
102                     int seed = 800;
103                     T duplicateValue = CreateT(seed++);
104                     while (collection.Contains(duplicateValue))
105                         duplicateValue = CreateT(seed++);
106                     collection.Add(duplicateValue);
107                     collection.Add(duplicateValue);
108                     Assert.Equal(count + 1, collection.Count);
109                 }
110             }
111         }
112 
113         #endregion
114 
115         #region Set Function Validation
116 
Validate_ExceptWith(ISet<T> set, IEnumerable<T> enumerable)117         private void Validate_ExceptWith(ISet<T> set, IEnumerable<T> enumerable)
118         {
119             if (set.Count == 0 || enumerable == set)
120             {
121                 set.ExceptWith(enumerable);
122                 Assert.Equal(0, set.Count);
123             }
124             else
125             {
126                 HashSet<T> expected = new HashSet<T>(set, GetIEqualityComparer());
127                 foreach (T element in enumerable)
128                     expected.Remove(element);
129                 set.ExceptWith(enumerable);
130                 Assert.Equal(expected.Count, set.Count);
131                 Assert.True(expected.SetEquals(set));
132             }
133         }
134 
Validate_IntersectWith(ISet<T> set, IEnumerable<T> enumerable)135         private void Validate_IntersectWith(ISet<T> set, IEnumerable<T> enumerable)
136         {
137             if (set.Count == 0 || Enumerable.Count(enumerable) == 0)
138             {
139                 set.IntersectWith(enumerable);
140                 Assert.Equal(0, set.Count);
141             }
142             else if (set == enumerable)
143             {
144                 HashSet<T> beforeOperation = new HashSet<T>(set, GetIEqualityComparer());
145                 set.IntersectWith(enumerable);
146                 Assert.True(beforeOperation.SetEquals(set));
147             }
148             else
149             {
150                 IEqualityComparer<T> comparer = GetIEqualityComparer();
151                 HashSet<T> expected = new HashSet<T>(comparer);
152                 foreach (T value in set)
153                     if (enumerable.Contains(value, comparer))
154                         expected.Add(value);
155                 set.IntersectWith(enumerable);
156                 Assert.Equal(expected.Count, set.Count);
157                 Assert.True(expected.SetEquals(set));
158             }
159         }
160 
Validate_IsProperSubsetOf(ISet<T> set, IEnumerable<T> enumerable)161         private void Validate_IsProperSubsetOf(ISet<T> set, IEnumerable<T> enumerable)
162         {
163             bool setContainsValueNotInEnumerable = false;
164             bool enumerableContainsValueNotInSet = false;
165             IEqualityComparer<T> comparer = GetIEqualityComparer();
166             foreach (T value in set) // Every value in Set must be in Enumerable
167             {
168                 if (!enumerable.Contains(value, comparer))
169                 {
170                     setContainsValueNotInEnumerable = true;
171                     break;
172                 }
173             }
174             foreach (T value in enumerable) // Enumerable must contain at least one value not in Set
175             {
176                 if (!set.Contains(value, comparer))
177                 {
178                     enumerableContainsValueNotInSet = true;
179                     break;
180                 }
181             }
182             Assert.Equal(!setContainsValueNotInEnumerable && enumerableContainsValueNotInSet, set.IsProperSubsetOf(enumerable));
183         }
184 
Validate_IsProperSupersetOf(ISet<T> set, IEnumerable<T> enumerable)185         private void Validate_IsProperSupersetOf(ISet<T> set, IEnumerable<T> enumerable)
186         {
187             bool isProperSuperset = true;
188             bool setContainsElementsNotInEnumerable = false;
189             IEqualityComparer<T> comparer = GetIEqualityComparer();
190             foreach (T value in enumerable)
191             {
192                 if (!set.Contains(value, comparer))
193                 {
194                     isProperSuperset = false;
195                     break;
196                 }
197             }
198             foreach (T value in set)
199             {
200                 if (!enumerable.Contains(value, comparer))
201                 {
202                     setContainsElementsNotInEnumerable = true;
203                     break;
204                 }
205             }
206             isProperSuperset = isProperSuperset && setContainsElementsNotInEnumerable;
207             Assert.Equal(isProperSuperset, set.IsProperSupersetOf(enumerable));
208         }
209 
Validate_IsSubsetOf(ISet<T> set, IEnumerable<T> enumerable)210         private void Validate_IsSubsetOf(ISet<T> set, IEnumerable<T> enumerable)
211         {
212             IEqualityComparer<T> comparer = GetIEqualityComparer();
213             foreach (T value in set)
214                 if (!enumerable.Contains(value, comparer))
215                 {
216                     Assert.False(set.IsSubsetOf(enumerable));
217                     return;
218                 }
219             Assert.True(set.IsSubsetOf(enumerable));
220         }
221 
Validate_IsSupersetOf(ISet<T> set, IEnumerable<T> enumerable)222         private void Validate_IsSupersetOf(ISet<T> set, IEnumerable<T> enumerable)
223         {
224             IEqualityComparer<T> comparer = GetIEqualityComparer();
225             foreach (T value in enumerable)
226                 if (!set.Contains(value, comparer))
227                 {
228                     Assert.False(set.IsSupersetOf(enumerable));
229                     return;
230                 }
231             Assert.True(set.IsSupersetOf(enumerable));
232         }
233 
Validate_Overlaps(ISet<T> set, IEnumerable<T> enumerable)234         private void Validate_Overlaps(ISet<T> set, IEnumerable<T> enumerable)
235         {
236             IEqualityComparer<T> comparer = GetIEqualityComparer();
237             foreach (T value in enumerable)
238             {
239                 if (set.Contains(value, comparer))
240                 {
241                     Assert.True(set.Overlaps(enumerable));
242                     return;
243                 }
244             }
245             Assert.False(set.Overlaps(enumerable));
246         }
247 
Validate_SetEquals(ISet<T> set, IEnumerable<T> enumerable)248         private void Validate_SetEquals(ISet<T> set, IEnumerable<T> enumerable)
249         {
250             IEqualityComparer<T> comparer = GetIEqualityComparer();
251             foreach (T value in set)
252             {
253                 if (!enumerable.Contains(value, comparer))
254                 {
255                     Assert.False(set.SetEquals(enumerable));
256                     return;
257                 }
258             }
259             foreach (T value in enumerable)
260             {
261                 if (!set.Contains(value, comparer))
262                 {
263                     Assert.False(set.SetEquals(enumerable));
264                     return;
265                 }
266             }
267             Assert.True(set.SetEquals(enumerable));
268         }
269 
Validate_SymmetricExceptWith(ISet<T> set, IEnumerable<T> enumerable)270         private void Validate_SymmetricExceptWith(ISet<T> set, IEnumerable<T> enumerable)
271         {
272             IEqualityComparer<T> comparer = GetIEqualityComparer();
273             HashSet<T> expected = new HashSet<T>(comparer);
274             foreach (T element in enumerable)
275                 if (!set.Contains(element, comparer))
276                     expected.Add(element);
277             foreach (T element in set)
278                 if (!enumerable.Contains(element, comparer))
279                     expected.Add(element);
280             set.SymmetricExceptWith(enumerable);
281             Assert.Equal(expected.Count, set.Count);
282             Assert.True(expected.SetEquals(set));
283         }
284 
Validate_UnionWith(ISet<T> set, IEnumerable<T> enumerable)285         private void Validate_UnionWith(ISet<T> set, IEnumerable<T> enumerable)
286         {
287             IEqualityComparer<T> comparer = GetIEqualityComparer();
288             HashSet<T> expected = new HashSet<T>(set, comparer);
289             foreach (T element in enumerable)
290                 if (!set.Contains(element, comparer))
291                     expected.Add(element);
292             set.UnionWith(enumerable);
293             Assert.Equal(expected.Count, set.Count);
294             Assert.True(expected.SetEquals(set));
295         }
296 
297         #endregion
298 
299         #region Set Function tests
300 
301         [Theory]
302         [MemberData(nameof(ValidCollectionSizes))]
ISet_Generic_NullEnumerableArgument(int count)303         public void ISet_Generic_NullEnumerableArgument(int count)
304         {
305             ISet<T> set = GenericISetFactory(count);
306             Assert.Throws<ArgumentNullException>(() => set.ExceptWith(null));
307             Assert.Throws<ArgumentNullException>(() => set.IntersectWith(null));
308             Assert.Throws<ArgumentNullException>(() => set.IsProperSubsetOf(null));
309             Assert.Throws<ArgumentNullException>(() => set.IsProperSupersetOf(null));
310             Assert.Throws<ArgumentNullException>(() => set.IsSubsetOf(null));
311             Assert.Throws<ArgumentNullException>(() => set.IsSupersetOf(null));
312             Assert.Throws<ArgumentNullException>(() => set.Overlaps(null));
313             Assert.Throws<ArgumentNullException>(() => set.SetEquals(null));
314             Assert.Throws<ArgumentNullException>(() => set.SymmetricExceptWith(null));
315             Assert.Throws<ArgumentNullException>(() => set.UnionWith(null));
316         }
317 
318         [Theory]
319         [MemberData(nameof(EnumerableTestData))]
ISet_Generic_ExceptWith(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)320         public void ISet_Generic_ExceptWith(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)
321         {
322             ISet<T> set = GenericISetFactory(setLength);
323             IEnumerable<T> enumerable = CreateEnumerable(enumerableType, set, enumerableLength, numberOfMatchingElements, numberOfDuplicateElements);
324             Validate_ExceptWith(set, enumerable);
325         }
326 
327         [Theory]
328         [MemberData(nameof(EnumerableTestData))]
ISet_Generic_IntersectWith(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)329         public void ISet_Generic_IntersectWith(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)
330         {
331             ISet<T> set = GenericISetFactory(setLength);
332             IEnumerable<T> enumerable = CreateEnumerable(enumerableType, set, enumerableLength, numberOfMatchingElements, numberOfDuplicateElements);
333             Validate_IntersectWith(set, enumerable);
334         }
335 
336         [Theory]
337         [MemberData(nameof(EnumerableTestData))]
ISet_Generic_IsProperSubsetOf(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)338         public void ISet_Generic_IsProperSubsetOf(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)
339         {
340             ISet<T> set = GenericISetFactory(setLength);
341             IEnumerable<T> enumerable = CreateEnumerable(enumerableType, set, enumerableLength, numberOfMatchingElements, numberOfDuplicateElements);
342             Validate_IsProperSubsetOf(set, enumerable);
343         }
344 
345         [Theory]
346         [MemberData(nameof(EnumerableTestData))]
ISet_Generic_IsProperSupersetOf(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)347         public void ISet_Generic_IsProperSupersetOf(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)
348         {
349             ISet<T> set = GenericISetFactory(setLength);
350             IEnumerable<T> enumerable = CreateEnumerable(enumerableType, set, enumerableLength, numberOfMatchingElements, numberOfDuplicateElements);
351             Validate_IsProperSupersetOf(set, enumerable);
352         }
353 
354         [Theory]
355         [MemberData(nameof(EnumerableTestData))]
ISet_Generic_IsSubsetOf(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)356         public void ISet_Generic_IsSubsetOf(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)
357         {
358             ISet<T> set = GenericISetFactory(setLength);
359             IEnumerable<T> enumerable = CreateEnumerable(enumerableType, set, enumerableLength, numberOfMatchingElements, numberOfDuplicateElements);
360             Validate_IsSubsetOf(set, enumerable);
361         }
362 
363         [Theory]
364         [MemberData(nameof(EnumerableTestData))]
ISet_Generic_IsSupersetOf(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)365         public void ISet_Generic_IsSupersetOf(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)
366         {
367             ISet<T> set = GenericISetFactory(setLength);
368             IEnumerable<T> enumerable = CreateEnumerable(enumerableType, set, enumerableLength, numberOfMatchingElements, numberOfDuplicateElements);
369             Validate_IsSupersetOf(set, enumerable);
370         }
371 
372         [Theory]
373         [MemberData(nameof(EnumerableTestData))]
ISet_Generic_Overlaps(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)374         public void ISet_Generic_Overlaps(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)
375         {
376             ISet<T> set = GenericISetFactory(setLength);
377             IEnumerable<T> enumerable = CreateEnumerable(enumerableType, set, enumerableLength, numberOfMatchingElements, numberOfDuplicateElements);
378             Validate_Overlaps(set, enumerable);
379         }
380 
381         [Theory]
382         [MemberData(nameof(EnumerableTestData))]
ISet_Generic_SetEquals(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)383         public void ISet_Generic_SetEquals(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)
384         {
385             ISet<T> set = GenericISetFactory(setLength);
386             IEnumerable<T> enumerable = CreateEnumerable(enumerableType, set, enumerableLength, numberOfMatchingElements, numberOfDuplicateElements);
387             Validate_SetEquals(set, enumerable);
388         }
389 
390         [Theory]
391         [MemberData(nameof(EnumerableTestData))]
ISet_Generic_SymmetricExceptWith(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)392         public void ISet_Generic_SymmetricExceptWith(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)
393         {
394             ISet<T> set = GenericISetFactory(setLength);
395             IEnumerable<T> enumerable = CreateEnumerable(enumerableType, set, enumerableLength, numberOfMatchingElements, numberOfDuplicateElements);
396             Validate_SymmetricExceptWith(set, enumerable);
397         }
398 
399         [Theory]
400         [MemberData(nameof(EnumerableTestData))]
ISet_Generic_UnionWith(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)401         public void ISet_Generic_UnionWith(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)
402         {
403             ISet<T> set = GenericISetFactory(setLength);
404             IEnumerable<T> enumerable = CreateEnumerable(enumerableType, set, enumerableLength, numberOfMatchingElements, numberOfDuplicateElements);
405             Validate_UnionWith(set, enumerable);
406         }
407 
408         #endregion
409 
410         #region Set Function tests on itself
411 
412         [Theory]
413         [MemberData(nameof(ValidCollectionSizes))]
ISet_Generic_ExceptWith_Itself(int setLength)414         public void ISet_Generic_ExceptWith_Itself(int setLength)
415         {
416             ISet<T> set = GenericISetFactory(setLength);
417             Validate_ExceptWith(set, set);
418         }
419 
420         [Theory]
421         [MemberData(nameof(ValidCollectionSizes))]
422         [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Full framework throws InvalidOperationException")]
ISet_Generic_IntersectWith_Itself(int setLength)423         public void ISet_Generic_IntersectWith_Itself(int setLength)
424         {
425             ISet<T> set = GenericISetFactory(setLength);
426             Validate_IntersectWith(set, set);
427         }
428 
429         [Theory]
430         [MemberData(nameof(ValidCollectionSizes))]
ISet_Generic_IsProperSubsetOf_Itself(int setLength)431         public void ISet_Generic_IsProperSubsetOf_Itself(int setLength)
432         {
433             ISet<T> set = GenericISetFactory(setLength);
434             Validate_IsProperSubsetOf(set, set);
435         }
436 
437         [Theory]
438         [MemberData(nameof(ValidCollectionSizes))]
ISet_Generic_IsProperSupersetOf_Itself(int setLength)439         public void ISet_Generic_IsProperSupersetOf_Itself(int setLength)
440         {
441             ISet<T> set = GenericISetFactory(setLength);
442             Validate_IsProperSupersetOf(set, set);
443         }
444 
445         [Theory]
446         [MemberData(nameof(ValidCollectionSizes))]
ISet_Generic_IsSubsetOf_Itself(int setLength)447         public void ISet_Generic_IsSubsetOf_Itself(int setLength)
448         {
449             ISet<T> set = GenericISetFactory(setLength);
450             Validate_IsSubsetOf(set, set);
451         }
452 
453         [Theory]
454         [MemberData(nameof(ValidCollectionSizes))]
ISet_Generic_IsSupersetOf_Itself(int setLength)455         public void ISet_Generic_IsSupersetOf_Itself(int setLength)
456         {
457             ISet<T> set = GenericISetFactory(setLength);
458             Validate_IsSupersetOf(set, set);
459         }
460 
461         [Theory]
462         [MemberData(nameof(ValidCollectionSizes))]
ISet_Generic_Overlaps_Itself(int setLength)463         public void ISet_Generic_Overlaps_Itself(int setLength)
464         {
465             ISet<T> set = GenericISetFactory(setLength);
466             Validate_Overlaps(set, set);
467         }
468 
469         [Theory]
470         [MemberData(nameof(ValidCollectionSizes))]
ISet_Generic_SetEquals_Itself(int setLength)471         public void ISet_Generic_SetEquals_Itself(int setLength)
472         {
473             ISet<T> set = GenericISetFactory(setLength);
474             Assert.True(set.SetEquals(set));
475         }
476 
477         [Theory]
478         [MemberData(nameof(ValidCollectionSizes))]
ISet_Generic_SymmetricExceptWith_Itself(int setLength)479         public void ISet_Generic_SymmetricExceptWith_Itself(int setLength)
480         {
481             ISet<T> set = GenericISetFactory(setLength);
482             Validate_SymmetricExceptWith(set, set);
483         }
484 
485         [Theory]
486         [MemberData(nameof(ValidCollectionSizes))]
ISet_Generic_UnionWith_Itself(int setLength)487         public void ISet_Generic_UnionWith_Itself(int setLength)
488         {
489             ISet<T> set = GenericISetFactory(setLength);
490             Validate_UnionWith(set, set);
491         }
492 
493         #endregion
494 
495         #region Set Function tests on a large Set
496 
497         [Fact]
498         [OuterLoop]
ISet_Generic_ExceptWith_LargeSet()499         public void ISet_Generic_ExceptWith_LargeSet()
500         {
501             ISet<T> set = GenericISetFactory(ISet_Large_Capacity);
502             IEnumerable<T> enumerable = CreateEnumerable(EnumerableType.List, set, 150, 0, 0);
503             Validate_ExceptWith(set, enumerable);
504         }
505 
506         [Fact]
507         [OuterLoop]
ISet_Generic_IntersectWith_LargeSet()508         public void ISet_Generic_IntersectWith_LargeSet()
509         {
510             ISet<T> set = GenericISetFactory(ISet_Large_Capacity);
511             IEnumerable<T> enumerable = CreateEnumerable(EnumerableType.List, set, 150, 0, 0);
512             Validate_IntersectWith(set, enumerable);
513         }
514 
515         [Fact]
516         [OuterLoop]
ISet_Generic_IsProperSubsetOf_LargeSet()517         public void ISet_Generic_IsProperSubsetOf_LargeSet()
518         {
519             ISet<T> set = GenericISetFactory(ISet_Large_Capacity);
520             IEnumerable<T> enumerable = CreateEnumerable(EnumerableType.List, set, 150, 0, 0);
521             Validate_IsProperSubsetOf(set, enumerable);
522         }
523 
524         [Fact]
525         [OuterLoop]
ISet_Generic_IsProperSupersetOf_LargeSet()526         public void ISet_Generic_IsProperSupersetOf_LargeSet()
527         {
528             ISet<T> set = GenericISetFactory(ISet_Large_Capacity);
529             IEnumerable<T> enumerable = CreateEnumerable(EnumerableType.List, set, 150, 0, 0);
530             Validate_IsProperSupersetOf(set, enumerable);
531         }
532 
533         [Fact]
534         [OuterLoop]
ISet_Generic_IsSubsetOf_LargeSet()535         public void ISet_Generic_IsSubsetOf_LargeSet()
536         {
537             ISet<T> set = GenericISetFactory(ISet_Large_Capacity);
538             IEnumerable<T> enumerable = CreateEnumerable(EnumerableType.List, set, 150, 0, 0);
539             Validate_IsSubsetOf(set, enumerable);
540         }
541 
542         [Fact]
543         [OuterLoop]
ISet_Generic_IsSupersetOf_LargeSet()544         public void ISet_Generic_IsSupersetOf_LargeSet()
545         {
546             ISet<T> set = GenericISetFactory(ISet_Large_Capacity);
547             IEnumerable<T> enumerable = CreateEnumerable(EnumerableType.List, set, 150, 0, 0);
548             Validate_IsSupersetOf(set, enumerable);
549         }
550 
551         [Fact]
552         [OuterLoop]
ISet_Generic_Overlaps_LargeSet()553         public void ISet_Generic_Overlaps_LargeSet()
554         {
555             ISet<T> set = GenericISetFactory(ISet_Large_Capacity);
556             IEnumerable<T> enumerable = CreateEnumerable(EnumerableType.List, set, 150, 0, 0);
557             Validate_Overlaps(set, enumerable);
558         }
559 
560         [Fact]
561         [OuterLoop]
ISet_Generic_SetEquals_LargeSet()562         public void ISet_Generic_SetEquals_LargeSet()
563         {
564             ISet<T> set = GenericISetFactory(ISet_Large_Capacity);
565             IEnumerable<T> enumerable = CreateEnumerable(EnumerableType.List, set, 150, 0, 0);
566             Validate_SetEquals(set, enumerable);
567         }
568 
569         [Fact]
570         [OuterLoop]
ISet_Generic_SymmetricExceptWith_LargeSet()571         public void ISet_Generic_SymmetricExceptWith_LargeSet()
572         {
573             ISet<T> set = GenericISetFactory(ISet_Large_Capacity);
574             IEnumerable<T> enumerable = CreateEnumerable(EnumerableType.List, set, 150, 0, 0);
575             Validate_SymmetricExceptWith(set, enumerable);
576         }
577 
578         [Fact]
579         [OuterLoop]
ISet_Generic_UnionWith_LargeSet()580         public void ISet_Generic_UnionWith_LargeSet()
581         {
582             ISet<T> set = GenericISetFactory(ISet_Large_Capacity);
583             IEnumerable<T> enumerable = CreateEnumerable(EnumerableType.List, set, 150, 0, 0);
584             Validate_UnionWith(set, enumerable);
585         }
586 
587         #endregion
588 
589         #region Other misc ISet test Scenarios
590 
591         [Theory]
592         [MemberData(nameof(EnumerableTestData))]
ISet_Generic_SymmetricExceptWith_AfterRemovingElements(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)593         public void ISet_Generic_SymmetricExceptWith_AfterRemovingElements(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)
594         {
595             ISet<T> set = GenericISetFactory(setLength);
596             T value = CreateT(532);
597             if (!set.Contains(value))
598                 set.Add(value);
599             set.Remove(value);
600             IEnumerable<T> enumerable = CreateEnumerable(enumerableType, set, enumerableLength, numberOfMatchingElements, numberOfDuplicateElements);
601             Debug.Assert(enumerable != null);
602 
603             IEqualityComparer<T> comparer = GetIEqualityComparer();
604             HashSet<T> expected = new HashSet<T>(comparer);
605             foreach (T element in enumerable)
606                 if (!set.Contains(element, comparer))
607                     expected.Add(element);
608             foreach (T element in set)
609                 if (!enumerable.Contains(element, comparer))
610                     expected.Add(element);
611             set.SymmetricExceptWith(enumerable);
612             Assert.Equal(expected.Count, set.Count);
613             Assert.True(expected.SetEquals(set));
614         }
615 
616         #endregion
617     }
618 }