public void HashSet_Generic_TrimExcess_Repeatedly(int setLength) { PooledSet <T> set = (PooledSet <T>)GenericISetFactory(setLength); List <T> expected = set.ToList(); set.TrimExcess(); set.TrimExcess(); set.TrimExcess(); Assert.True(set.SetEquals(expected)); }
public void HashSet_Generic_Constructor_HashSet_SparselyFilled(int count) { PooledSet <T> source = (PooledSet <T>)CreateEnumerable(EnumerableType.HashSet, null, count, 0, 0); List <T> sourceElements = source.ToList(); foreach (int i in NonSquares(count)) { source.Remove(sourceElements[i]);// Unevenly spaced survivors increases chance of catching any spacing-related bugs. } PooledSet <T> set = new PooledSet <T>(source, GetIEqualityComparer()); RegisterForDispose(set); Assert.True(set.SetEquals(source)); }
public void HashSet_Generic_TrimExcess_AfterRemovingOneElement(int setLength) { if (setLength > 0) { PooledSet <T> set = (PooledSet <T>)GenericISetFactory(setLength); List <T> expected = set.ToList(); T elementToRemove = set.ElementAt(0); set.TrimExcess(); Assert.True(set.Remove(elementToRemove)); expected.Remove(elementToRemove); set.TrimExcess(); Assert.True(set.SetEquals(expected)); } }