public void ISet_Generic_SymmetricExceptWith_AfterRemovingElements(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements) { ISet <T> set = GenericISetFactory(setLength); T value = CreateT(532); if (!set.Contains(value)) { set.Add(value); } set.Remove(value); IEnumerable <T> enumerable = CreateEnumerable(enumerableType, set, enumerableLength, numberOfMatchingElements, numberOfDuplicateElements); Debug.Assert(enumerable != null); IEqualityComparer <T> comparer = GetIEqualityComparer(); System.Collections.Generic.HashSet <T> expected = new System.Collections.Generic.HashSet <T>(comparer); foreach (T element in enumerable) { if (!set.Contains(element, comparer)) { expected.Add(element); } } foreach (T element in set) { if (!enumerable.Contains(element, comparer)) { expected.Add(element); } } set.SymmetricExceptWith(enumerable); Assert.Equal(expected.Count, set.Count); Assert.True(expected.SetEquals(set)); }
private void Validate_IntersectWith(ISet <T> set, IEnumerable <T> enumerable) { if (set.Count == 0 || Enumerable.Count(enumerable) == 0) { set.IntersectWith(enumerable); Assert.Equal(0, set.Count); } else if (set == enumerable) { System.Collections.Generic.HashSet <T> beforeOperation = new System.Collections.Generic.HashSet <T>(set, GetIEqualityComparer()); set.IntersectWith(enumerable); Assert.True(beforeOperation.SetEquals(set)); } else { IEqualityComparer <T> comparer = GetIEqualityComparer(); System.Collections.Generic.HashSet <T> expected = new System.Collections.Generic.HashSet <T>(comparer); foreach (T value in set) { if (enumerable.Contains(value, comparer)) { expected.Add(value); } } set.IntersectWith(enumerable); Assert.Equal(expected.Count, set.Count); Assert.True(expected.SetEquals(set)); } }
private void Validate_UnionWith(ISet <T> set, IEnumerable <T> enumerable) { IEqualityComparer <T> comparer = GetIEqualityComparer(); System.Collections.Generic.HashSet <T> expected = new System.Collections.Generic.HashSet <T>(set, comparer); foreach (T element in enumerable) { if (!set.Contains(element, comparer)) { expected.Add(element); } } set.UnionWith(enumerable); Assert.Equal(expected.Count, set.Count); Assert.True(expected.SetEquals(set)); }
private void Validate_ExceptWith(ISet <T> set, IEnumerable <T> enumerable) { if (set.Count == 0 || enumerable == set) { set.ExceptWith(enumerable); Assert.Equal(0, set.Count); } else { System.Collections.Generic.HashSet <T> expected = new System.Collections.Generic.HashSet <T>(set, GetIEqualityComparer()); foreach (T element in enumerable) { expected.Remove(element); } set.ExceptWith(enumerable); Assert.Equal(expected.Count, set.Count); Assert.True(expected.SetEquals(set)); } }
public override bool Equals(object obj) { return(Object.ReferenceEquals(obj, this) || Positive.SetEquals(((PredicateList)obj).Positive)); }