コード例 #1
0
        public void HashSet_Generic_Constructor_IEnumerable(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)
        {
            IEnumerable <T> enumerable = CreateEnumerable(enumerableType, null, enumerableLength, 0, numberOfDuplicateElements);
            HashSet <T>     set        = new HashSet <T>(enumerable);

            Assert.True(set.SetEquals(enumerable));
        }
コード例 #2
0
ファイル: TestBase.Generic.cs プロジェクト: rsumner31/corefx2
        /// <summary>
        /// Helper function to create an enumerable fulfilling the given specific parameters. The function will
        /// create an enumerable of the desired type using the Default constructor for that type and then add values
        /// to it until it is full. It will begin by adding the desired number of matching and duplicate elements,
        /// followed by random (deterministic) elements until the desired count is reached.
        /// </summary>
        protected IEnumerable <T> CreateEnumerable(EnumerableType type, IEnumerable <T> enumerableToMatchTo, int count, int numberOfMatchingElements, int numberOfDuplicateElements)
        {
            Debug.Assert(count >= numberOfMatchingElements);
            Debug.Assert(count >= numberOfDuplicateElements);

            switch (type)
            {
            case EnumerableType.HashSet:
                Debug.Assert(numberOfDuplicateElements == 0, "Can not create a HashSet with duplicate elements - numberOfDuplicateElements must be zero");
                return(CreateHashSet(enumerableToMatchTo, count, numberOfMatchingElements));

            case EnumerableType.List:
                return(CreateList(enumerableToMatchTo, count, numberOfMatchingElements, numberOfDuplicateElements));

            case EnumerableType.SortedSet:
                Debug.Assert(numberOfDuplicateElements == 0, "Can not create a SortedSet with duplicate elements - numberOfDuplicateElements must be zero");
                return(CreateSortedSet(enumerableToMatchTo, count, numberOfMatchingElements));

            case EnumerableType.Queue:
                return(CreateQueue(enumerableToMatchTo, count, numberOfMatchingElements, numberOfDuplicateElements));

            default:
                Debug.Assert(false, "Check that the 'EnumerableType' Enum returns only types that are special-cased in the CreateEnumerable function within the Iset_Generic_Tests class");
                return(null);
            }
        }
コード例 #3
0
        public void ISet_Generic_IsProperSupersetOf(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)
        {
            var set        = GenericISetFactory(setLength);
            var enumerable = CreateEnumerable(enumerableType, set, enumerableLength, numberOfMatchingElements, numberOfDuplicateElements);

            Validate_IsProperSupersetOf(set, enumerable);
        }
コード例 #4
0
        public void Constructor_IEnumerable(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)
        {
            var enumerable = CreateEnumerable(enumerableType, null, enumerableLength, 0, numberOfDuplicateElements);
            var queue      = new LinkedQueue <T>(enumerable);

            Assert.Equal(enumerable, queue);
        }
コード例 #5
0
        public void LinkedList_Generic_Constructor_IEnumerable(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)
        {
            IEnumerable <T> enumerable = CreateEnumerable(enumerableType, null, enumerableLength, 0, numberOfDuplicateElements);
            LinkedList <T>  queue      = new LinkedList <T>(enumerable);

            Assert.Equal(enumerable, queue);
        }
コード例 #6
0
        public Expression GetEnumerableConversion(Expression instance, bool allowEnumerableAssignment)
        {
            if (instance.Type.IsAssignableTo(EnumerableType) &&
                (allowEnumerableAssignment || ValueIsNotEnumerableInterface(instance)))
            {
                return(instance);
            }

            if (IsArray)
            {
                return(instance.WithToArrayCall(ElementType));
            }

            if (IsReadOnlyCollection)
            {
                return(instance.GetReadOnlyCollectionCreation(ElementType));
            }

            if (EnumerableType.IsAssignableTo(CollectionType))
            {
                return(instance.GetCollectionTypeCreation(ElementType));
            }

            if (HasSetInterface)
            {
                return(GetCopyIntoObjectConstruction(instance));
            }

            return(instance.WithToListLinqCall(ElementType));
        }
コード例 #7
0
ファイル: Stack.Generic.Tests.cs プロジェクト: wudilab/corefx
        public void Stack_Generic_Constructor_IEnumerable(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)
        {
            IEnumerable <T> enumerable = CreateEnumerable(enumerableType, null, enumerableLength, 0, numberOfDuplicateElements);
            Stack <T>       stack      = new Stack <T>(enumerable);

            Assert.Equal(enumerable.ToArray().Reverse(), stack.ToArray());
        }
コード例 #8
0
        public void Constructor_IEnumerable(
            EnumerableType enumerableType,
            int listLength,
            int enumerableLength,
            int numberOfMatchingElements,
            int numberOfDuplicateElements
            )
        {
            _ = listLength;
            _ = numberOfMatchingElements;
            IEnumerable <T> enumerable = CreateEnumerable(
                enumerableType,
                null,
                enumerableLength,
                0,
                numberOfDuplicateElements
                );
            SegmentedList <T> list     = new SegmentedList <T>(enumerable);
            SegmentedList <T> expected = enumerable.ToSegmentedList();

            Assert.Equal(enumerableLength, list.Count); //"Number of items in list do not match the number of items given."

            for (int i = 0; i < enumerableLength; i++)
            {
                Assert.Equal(expected[i], list[i]);     //"Expected object in item array to be the same as in the list"
            }
            Assert.False(((IList <T>)list).IsReadOnly); //"List should not be readonly"
        }
コード例 #9
0
        public void PooledSet_Span_UnionWith(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)
        {
            var      set  = (PooledSet <T>)GenericISetFactory(setLength);
            Span <T> span = CreateSpan(enumerableType, set, enumerableLength, numberOfMatchingElements, numberOfDuplicateElements);

            Validate_UnionWith(set, span);
        }
コード例 #10
0
        public void ISet_Generic_UnionWith(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)
        {
            ISet <T>        set        = GenericISetFactory(setLength);
            IEnumerable <T> enumerable = CreateEnumerable(enumerableType, set, enumerableLength, numberOfMatchingElements, numberOfDuplicateElements);

            Validate_UnionWith(set, enumerable);
        }
コード例 #11
0
        public void SortedSet_Generic_Constructor_IEnumerable_IComparer(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)
        {
            IEnumerable <T> enumerable = CreateEnumerable(enumerableType, null, enumerableLength, 0, 0);
            SortedSet <T>   set        = new SortedSet <T>(enumerable, GetIComparer());

            Assert.True(set.SetEquals(enumerable));
        }
コード例 #12
0
        public void ISet_Generic_SymmetricExceptWith_AfterRemovingElements(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)
        {
            ISet <T> set   = GenericISetFactory(setLength);
            T        value = CreateT(532);

            if (!set.Contains(value))
            {
                set.Add(value);
            }
            set.Remove(value);
            IEnumerable <T> enumerable = CreateEnumerable(enumerableType, set, enumerableLength, numberOfMatchingElements, numberOfDuplicateElements);

            Debug.Assert(enumerable != null);

            IEqualityComparer <T> comparer = GetIEqualityComparer();

            System.Collections.Generic.HashSet <T> expected = new System.Collections.Generic.HashSet <T>(comparer);
            foreach (T element in enumerable)
            {
                if (!set.Contains(element, comparer))
                {
                    expected.Add(element);
                }
            }
            foreach (T element in set)
            {
                if (!enumerable.Contains(element, comparer))
                {
                    expected.Add(element);
                }
            }
            set.SymmetricExceptWith(enumerable);
            Assert.Equal(expected.Count, set.Count);
            Assert.True(expected.SetEquals(set));
        }
コード例 #13
0
        public void ISet_Generic_SymmetricExceptWith(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)
        {
            var set        = GenericISetFactory(setLength);
            var enumerable = CreateEnumerable(enumerableType, set, enumerableLength, numberOfMatchingElements, numberOfDuplicateElements);

            Validate_SymmetricExceptWith(set, enumerable);
        }
コード例 #14
0
            public EnumerationData(Type itemType)
            {
                EnumerableType = typeof(IEnumerable <>).MakeGenericType(itemType);
                EnumeratorType = typeof(IEnumerator <>).MakeGenericType(itemType);

                GetEnumerator = EnumerableType.GetMethod("GetEnumerator", new Type[0]);
                Current       = EnumeratorType.GetProperty("Current");
            }
コード例 #15
0
        public void Queue_Generic_Constructor_IEnumerable(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)
        {
            IEnumerable <T> enumerable = CreateEnumerable(enumerableType, null, enumerableLength, 0, numberOfDuplicateElements);
            PooledQueue <T> queue      = new PooledQueue <T>(enumerable);

            RegisterForDispose(queue);
            Assert.Equal(enumerable, queue);
        }
コード例 #16
0
        public void HashSet_Generic_Constructor_Span(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)
        {
            IEnumerable <T> enumerable = CreateEnumerable(enumerableType, null, enumerableLength, 0, numberOfDuplicateElements);
            var             span       = enumerable.ToArray().AsSpan();
            PooledSet <T>   set        = new PooledSet <T>(span);

            Assert.True(set.SetEquals(enumerable));
        }
コード例 #17
0
        public void HashSet_Generic_Constructor_IEnumerable_IEqualityComparer(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)
        {
            IEnumerable <T> enumerable = CreateEnumerable(enumerableType, null, enumerableLength, 0, 0);
            PooledSet <T>   set        = new PooledSet <T>(enumerable, GetIEqualityComparer());

            RegisterForDispose(set);
            Assert.True(set.SetEquals(enumerable));
        }
コード例 #18
0
        public void Queue_Generic_Constructor_IEnumerable(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)
        {
            _ = setLength;
            _ = numberOfMatchingElements;
            IEnumerable <T> enumerable = CreateEnumerable(enumerableType, null, enumerableLength, 0, numberOfDuplicateElements);
            Queue <T>       queue      = new Queue <T>(enumerable);

            Assert.Equal(enumerable, queue);
        }
コード例 #19
0
        public Expression GetEmptyInstanceCreation(Type enumerableType = null)
        {
            if ((enumerableType == EnumerableType) || (enumerableType == null))
            {
                return(EnumerableType.GetEmptyInstanceCreation(ElementType, this));
            }

            return(enumerableType.GetEmptyInstanceCreation(ElementType));
        }
コード例 #20
0
        public void LinkedHashSet_Generic_Constructor_IEnumerable_IEqualityComparer(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)
        {
            _ = setLength;
            _ = numberOfMatchingElements;
            _ = numberOfDuplicateElements;
            SCG.IEnumerable <T> enumerable = CreateEnumerable(enumerableType, null, enumerableLength, 0, 0);
            LinkedHashSet <T>   set        = new LinkedHashSet <T>(enumerable, GetIEqualityComparer());

            Assert.True(set.SetEquals(enumerable));
        }
コード例 #21
0
 public Type GetEmptyInstanceCreationFallbackType()
 {
     return(IsDictionary
         ? EnumerableType.GetDictionaryConcreteType()
         : IsCollection
             ? CollectionType
             : HasSetInterface
                 ? HashSetType
                 : ListType);
 }
コード例 #22
0
        private bool IsReadOnlyCollectionInterface()
        {
#if NET_STANDARD
            return(EnumerableType.IsClosedTypeOf(typeof(IReadOnlyCollection <>)));
#else
            return(EnumerableType.IsInterface() &&
                   (EnumerableType.Name == "IReadOnlyCollection`1") &&
                   EnumerableType.IsFromBcl());
#endif
        }
コード例 #23
0
        public void Generic_Constructor_IEnumerable(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)
        {
            var arr  = CreateEnumerable(enumerableType, null, enumerableLength, 0, numberOfDuplicateElements).ToArray();
            var heap = new MaxHeap <T>(arr, Comparer <T> .Default);

            Assert.Equal(arr.Length, heap.Count);
            Array.Sort(arr, Comparer <T> .Default);
            Array.Reverse(arr);
            foreach (var item in arr)
            {
                Assert.Equal(item, heap.Pop());
            }
        }
コード例 #24
0
        public void Constructor_IEnumerable(EnumerableType enumerableType, int listLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)
        {
            var enumerable = CreateEnumerable(enumerableType, null, enumerableLength, 0, numberOfDuplicateElements);
            var list       = new SeqList <T>(enumerable);
            var expected   = enumerable.ToList();

            Assert.Equal(enumerableLength, list.Count); //"Number of items in list do not match the number of items given."

            for (var i = 0; i < enumerableLength; i++)
            {
                Assert.Equal(expected[i], list[i]); //"Expected object in item array to be the same as in the list"
            }
        }
コード例 #25
0
        internal NCacheOqlEnumerable(EnumerableType type, ICacheReader cacheReader)
        {
            switch (type)
            {
            case EnumerableType.Normal:
                enumeratorWrapper = new NCacheOqlEnumeratorNormal <T>(cacheReader);
                break;

            case EnumerableType.Deferred:
                enumeratorWrapper = new NCacheOqlEnumeratorDeferred <T>(cacheReader);
                break;
            }
        }
コード例 #26
0
        public bool CouldBeReadOnly()
        {
            if (_couldBeReadOnly.HasValue)
            {
                return(_couldBeReadOnly.Value);
            }

            if (EnumerableType.IsInterface())
            {
                // If the declared Type is an interface it could have an 'Add' method
                // while the underlying, implementing Type is actually readonly:
                return((_couldBeReadOnly = true).Value);
            }

            // If the declared Type declares an 'Add' method, assume it's not readonly;
            // Array implements ICollection<>, but its Add method is implemented explicitly:
            return((_couldBeReadOnly = EnumerableType.GetPublicInstanceMethods("Add").None()).Value);
        }
コード例 #27
0
        public Type GetEmptyInstanceCreationFallbackType()
        {
            if (IsArray)
            {
                return(ListType);
            }

            if (!EnumerableType.IsInterface())
            {
                return(EnumerableType);
            }

            if (IsDictionary)
            {
                return(typeof(Dictionary <,>).MakeGenericType(EnumerableType.GetGenericTypeArguments()));
            }

            return(HasSetInterface ? HashSetType : ListType);
        }
コード例 #28
0
        public void AddRange(EnumerableType enumerableType, int listLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)
        {
            SegmentedList <T> list          = GenericListFactory(listLength);
            SegmentedList <T> listBeforeAdd = list.ToSegmentedList();
            IEnumerable <T>   enumerable    = CreateEnumerable(enumerableType, list, enumerableLength, numberOfMatchingElements, numberOfDuplicateElements);

            list.AddRange(enumerable);

            // Check that the first section of the List is unchanged
            Assert.All(Enumerable.Range(0, listLength), index =>
            {
                Assert.Equal(listBeforeAdd[index], list[index]);
            });

            // Check that the added elements are correct
            Assert.All(Enumerable.Range(0, enumerableLength), index =>
            {
                Assert.Equal(enumerable.ElementAt(index), list[index + listLength]);
            });
        }
コード例 #29
0
        public void SortedSet_Generic_Constructor_IEnumerable_IComparer_NullComparer_Netcoreapp(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements)
        {
            _ = setLength;
            _ = numberOfMatchingElements;
            _ = numberOfDuplicateElements;
            SCG.IEnumerable <T> enumerable = CreateEnumerable(enumerableType, null, enumerableLength, 0, 0);
            SortedSet <T>       set        = new SortedSet <T>(enumerable, comparer: null);

            Assert.True(set.SetEquals(enumerable));
        }
コード例 #30
0
 public Expression GetNewInstanceCreation()
 {
     return(IsReadOnly || EnumerableType.IsInterface()
         ? Expression.New(ListType)
         : GetEmptyInstanceCreation());
 }