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)); }
/// <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); } }
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); }
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); }
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); }
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)); }
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()); }
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" }
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); }
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); }
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)); }
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)); }
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); }
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"); }
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); }
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)); }
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)); }
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); }
public Expression GetEmptyInstanceCreation(Type enumerableType = null) { if ((enumerableType == EnumerableType) || (enumerableType == null)) { return(EnumerableType.GetEmptyInstanceCreation(ElementType, this)); } return(enumerableType.GetEmptyInstanceCreation(ElementType)); }
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)); }
public Type GetEmptyInstanceCreationFallbackType() { return(IsDictionary ? EnumerableType.GetDictionaryConcreteType() : IsCollection ? CollectionType : HasSetInterface ? HashSetType : ListType); }
private bool IsReadOnlyCollectionInterface() { #if NET_STANDARD return(EnumerableType.IsClosedTypeOf(typeof(IReadOnlyCollection <>))); #else return(EnumerableType.IsInterface() && (EnumerableType.Name == "IReadOnlyCollection`1") && EnumerableType.IsFromBcl()); #endif }
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()); } }
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" } }
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; } }
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); }
public Type GetEmptyInstanceCreationFallbackType() { if (IsArray) { return(ListType); } if (!EnumerableType.IsInterface()) { return(EnumerableType); } if (IsDictionary) { return(typeof(Dictionary <,>).MakeGenericType(EnumerableType.GetGenericTypeArguments())); } return(HasSetInterface ? HashSetType : ListType); }
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]); }); }
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)); }
public Expression GetNewInstanceCreation() { return(IsReadOnly || EnumerableType.IsInterface() ? Expression.New(ListType) : GetEmptyInstanceCreation()); }