예제 #1
0
        public void LinkedHashSet_Generic_TrimExcess_Repeatedly(int setLength)
        {
            LinkedHashSet <T> set      = (LinkedHashSet <T>)GenericISetFactory(setLength);
            List <T>          expected = set.ToList();

            set.TrimExcess();
            set.TrimExcess();
            set.TrimExcess();
            Assert.True(set.SetEquals(expected));
        }
예제 #2
0
        public void LinkedHashSet_Generic_Constructor_LinkedHashSet_SparselyFilled(int count)
        {
            LinkedHashSet <T> source         = (LinkedHashSet <T>)CreateEnumerable(EnumerableType.LinkedHashSet, 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.
            }
            LinkedHashSet <T> set = new LinkedHashSet <T>(source, GetIEqualityComparer());

            Assert.True(set.SetEquals(source));
        }
예제 #3
0
        public void LinkedHashSet_Generic_TrimExcess_AfterRemovingOneElement(int setLength)
        {
            if (setLength > 0)
            {
                LinkedHashSet <T> set      = (LinkedHashSet <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));
            }
        }