Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        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));
            }
        }
Exemplo n.º 3
0
        public void HashSet_Generic_RemoveWhere_NewObject(int setLength) // Regression Dev10_624201
        {
            object[]           array = new object[2];
            object             obj   = new object();
            PooledSet <object> set   = new PooledSet <object>();

            RegisterForDispose(set);

            set.Add(obj);
            set.Remove(obj);
            foreach (object o in set)
            {
            }
            set.CopyTo(array, 0, 2);
            set.RemoveWhere((element) => { return(false); });
        }
 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
     {
         PooledSet <T> expected = new PooledSet <T>(set, GetIEqualityComparer());
         RegisterForDispose(expected);
         foreach (T element in enumerable)
         {
             expected.Remove(element);
         }
         set.ExceptWith(enumerable);
         Assert.Equal(expected.Count, set.Count);
         Assert.True(expected.SetEquals(set));
     }
 }
Exemplo n.º 5
0
 private void Validate_ExceptWith(PooledSet <T> set, Span <T> span)
 {
     if (set.Count == 0)
     {
         set.ExceptWith(span);
         Assert.Equal(0, set.Count);
     }
     else
     {
         PooledSet <T> expected = new PooledSet <T>(set, set.Comparer);
         RegisterForDispose(expected);
         foreach (T element in span)
         {
             expected.Remove(element);
         }
         set.ExceptWith(span);
         Assert.Equal(expected.Count, set.Count);
         Assert.True(expected.SetEquals(set));
     }
 }