예제 #1
0
        public void EnsureCapacity_Generic_ExistingCapacityRequested_SameValueReturned(int capacity)
        {
            var set = new LinkedHashSet <T>(capacity);

            Assert.Equal(capacity, set.EnsureCapacity(capacity));

            set = (LinkedHashSet <T>)GenericISetFactory(capacity);
            Assert.Equal(capacity, set.EnsureCapacity(capacity));
        }
예제 #2
0
        public void EnsureCapacity_Generic_HashsetNotEmpty_SetsToAtLeastTheRequested(int setLength)
        {
            LinkedHashSet <T> set = (LinkedHashSet <T>)GenericISetFactory(setLength);

            // get current capacity
            int currentCapacity = set.EnsureCapacity(0);

            // assert we can update to a larger capacity
            int newCapacity = set.EnsureCapacity(currentCapacity * 2);

            Assert.InRange(newCapacity, currentCapacity * 2, int.MaxValue);
        }
예제 #3
0
        public void EnsureCapacity_Generic_GrowCapacityWithFreeList(int setLength)
        {
            LinkedHashSet <T> set = (LinkedHashSet <T>)GenericISetFactory(setLength);

            // Remove the first element to ensure we have a free list.
            Assert.True(set.Remove(set.ElementAt(0)));

            int currentCapacity = set.EnsureCapacity(0);

            Assert.True(currentCapacity > 0);

            int newCapacity = set.EnsureCapacity(currentCapacity + 1);

            Assert.True(newCapacity > currentCapacity);
        }
예제 #4
0
        public void EnsureCapacity_Generic_RequestingLargerCapacity_DoesNotInvalidateEnumeration(int setLength)
        {
            LinkedHashSet <T> set      = (LinkedHashSet <T>)(GenericISetFactory(setLength));
            var         capacity       = set.EnsureCapacity(0);
            IEnumerator valuesEnum     = set.GetEnumerator();
            IEnumerator valuesListEnum = new SCG.List <T>(set).GetEnumerator();

            set.EnsureCapacity(capacity + 1); // Verify EnsureCapacity does not invalidate enumeration

            while (valuesEnum.MoveNext())
            {
                valuesListEnum.MoveNext();
                Assert.Equal(valuesListEnum.Current, valuesEnum.Current);
            }
        }
예제 #5
0
        public void EnsureCapacity_Generic_RequestedCapacitySmallerThanCurrent_CapacityUnchanged(int currentCapacity)
        {
            LinkedHashSet <T> set;

            // assert capacity remains the same when ensuring a capacity smaller or equal than existing
            for (int i = 0; i <= currentCapacity; i++)
            {
                set = new LinkedHashSet <T>(currentCapacity);
                Assert.Equal(currentCapacity, set.EnsureCapacity(i));
            }
        }
예제 #6
0
        public void LinkedHashSet_Generic_Constructor_Capacity_ToNextPrimeNumber()
        {
            // Highest pre-computed number + 1.
            const int Capacity = 7199370;
            var       set      = new LinkedHashSet <T>(Capacity);

            // Assert that the HashTable's capacity is set to the descendant prime number of the given one.
            const int NextPrime = 7199371;

            Assert.Equal(NextPrime, set.EnsureCapacity(0));
        }
예제 #7
0
        public void EnsureCapacity_Generic_CapacityIsSetToPrimeNumberLargerOrEqualToRequested()
        {
            var set = new LinkedHashSet <T>();

            Assert.Equal(17, set.EnsureCapacity(17));

            set = new LinkedHashSet <T>();
            Assert.Equal(17, set.EnsureCapacity(15));

            set = new LinkedHashSet <T>();
            Assert.Equal(17, set.EnsureCapacity(13));
        }
예제 #8
0
        public void EnsureCapacity_Generic_EnsureCapacityCalledTwice_ReturnsSameValue(int setLength)
        {
            LinkedHashSet <T> set = (LinkedHashSet <T>)GenericISetFactory(setLength);
            int capacity          = set.EnsureCapacity(0);

            Assert.Equal(capacity, set.EnsureCapacity(0));

            set      = (LinkedHashSet <T>)GenericISetFactory(setLength);
            capacity = set.EnsureCapacity(setLength);
            Assert.Equal(capacity, set.EnsureCapacity(setLength));

            set      = (LinkedHashSet <T>)GenericISetFactory(setLength);
            capacity = set.EnsureCapacity(setLength + 1);
            Assert.Equal(capacity, set.EnsureCapacity(setLength + 1));
        }
예제 #9
0
        public void EnsureCapacity_Generic_HashsetNotEmpty_RequestedSmallerThanCount_ReturnsAtLeastSizeOfCount(int setLength)
        {
            LinkedHashSet <T> set = (LinkedHashSet <T>)GenericISetFactory(setLength);

            Assert.InRange(set.EnsureCapacity(setLength - 1), setLength, int.MaxValue);
        }
예제 #10
0
        public void EnsureCapacity_Generic_HashsetNotInitialized_RequestedNonZero_CapacityIsSetToAtLeastTheRequested(int requestedCapacity)
        {
            var set = new LinkedHashSet <T>();

            Assert.InRange(set.EnsureCapacity(requestedCapacity), requestedCapacity, int.MaxValue);
        }
예제 #11
0
        public void EnsureCapacity_Generic_HashsetNotInitialized_RequestedZero_ReturnsZero()
        {
            var set = new LinkedHashSet <T>();

            Assert.Equal(0, set.EnsureCapacity(0));
        }
예제 #12
0
        public void EnsureCapacity_Generic_NegativeCapacityRequested_Throws()
        {
            var set = new LinkedHashSet <T>();

            AssertExtensions.Throws <ArgumentOutOfRangeException>("capacity", () => set.EnsureCapacity(-1));
        }