Exemplo n.º 1
0
        protected override IEnumerable NonGenericIEnumerableFactory(int count)
        {
            var set  = new SegmentedHashSet <string>();
            int seed = 12354;

            while (set.Count < count)
            {
                set.Add(CreateT(set, seed++));
            }
            return(set);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Helper function to create an HashSet fulfilling the given specific parameters. The function will
        /// create an HashSet using the Comparer constructor and then add values
        /// to it until it is full. It will begin by adding the desired number of matching,
        /// followed by random (deterministic) elements until the desired count is reached.
        /// </summary>
        protected IEnumerable <T> CreateSegmentedHashSet(IEnumerable <T>?enumerableToMatchTo, int count, int numberOfMatchingElements)
        {
            SegmentedHashSet <T> set = new SegmentedHashSet <T>(GetIEqualityComparer());
            int seed = 528;
            SegmentedList <T>?match = null;

            // Add Matching elements
            if (enumerableToMatchTo != null)
            {
                match = enumerableToMatchTo.ToSegmentedList();
                for (int i = 0; i < numberOfMatchingElements; i++)
                {
                    set.Add(match[i]);
                }
            }

            // Add elements to reach the desired count
            while (set.Count < count)
            {
                T toAdd = CreateT(seed++);
                while (set.Contains(toAdd) || (match != null && match.Contains(toAdd, GetIEqualityComparer()))) // Don't want any unexpectedly duplicate values
                {
                    toAdd = CreateT(seed++);
                }
                set.Add(toAdd);
            }

            // Validate that the Enumerable fits the guidelines as expected
            Debug.Assert(set.Count == count);
            if (match != null)
            {
                int actualMatchingCount = 0;
                foreach (T lookingFor in match)
                {
                    actualMatchingCount += set.Contains(lookingFor) ? 1 : 0;
                }
                Assert.Equal(numberOfMatchingElements, actualMatchingCount);
            }

            return(set);
        }
        public void HashSet_Generic_RemoveWhere_NewObject() // Regression Dev10_624201
        {
            object[] array = new object[2];
            object   obj   = new();
            SegmentedHashSet <object> set = new SegmentedHashSet <object>();

            set.Add(obj);
            set.Remove(obj);
            foreach (object o in set)
            {
            }
            set.CopyTo(array, 0, 2);
            set.RemoveWhere((element) => { return(false); });
        }