예제 #1
0
        public void PooledAddRange_String_CapacityIncrease_Array()
        {
            var pooled = new PooledList <string>();

            for (int j = 0; j < addLoops; j++)
            {
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
            }

            pooled.Dispose();
        }
        public void LastIndexOf_int_int_OutOfRangeExceptions(int count)
        {
            PooledList <T> list = GenericListFactory(count);
            T element           = CreateT(234);

            if (count > 0)
            {
                Assert.Throws <ArgumentOutOfRangeException>(() => list.LastIndexOf(element, 0, count + 1));             //"Expected ArgumentOutOfRangeException."
                Assert.Throws <ArgumentOutOfRangeException>(() => list.LastIndexOf(element, count / 2, count / 2 + 2)); //"Expected ArgumentOutOfRangeException."
                Assert.Throws <ArgumentOutOfRangeException>(() => list.LastIndexOf(element, 0, count + 1));             //"Expected ArgumentOutOfRangeException."
                Assert.Throws <ArgumentOutOfRangeException>(() => list.LastIndexOf(element, 0, -1));                    //"Expected ArgumentOutOfRangeException."
                Assert.Throws <ArgumentOutOfRangeException>(() => list.LastIndexOf(element, -1, count));                //"Expected ArgumentOutOfRangeException."
                Assert.Throws <ArgumentOutOfRangeException>(() => list.LastIndexOf(element, -1, 1));                    //"Expected ArgumentOutOfRangeException."                Assert.Throws<ArgumentOutOfRangeException>(() => list.LastIndexOf(element, count, 0)); //"Expected ArgumentOutOfRangeException."
                Assert.Throws <ArgumentOutOfRangeException>(() => list.LastIndexOf(element, count, 1));                 //"Expected ArgumentOutOfRangeException."
            }
            else // IndexOf with a 0 count List is special cased to return -1.
            {
                Assert.Equal(-1, list.LastIndexOf(element, 0, count + 1));
                Assert.Equal(-1, list.LastIndexOf(element, count / 2, count / 2 + 2));
                Assert.Equal(-1, list.LastIndexOf(element, 0, count + 1));
                Assert.Equal(-1, list.LastIndexOf(element, 0, -1));
                Assert.Equal(-1, list.LastIndexOf(element, -1, count));
                Assert.Equal(-1, list.LastIndexOf(element, -1, 1));
                Assert.Equal(-1, list.LastIndexOf(element, count, 0));
                Assert.Equal(-1, list.LastIndexOf(element, count, 1));
            }

            list.Dispose();
        }
예제 #3
0
        public void ForEach_NullAction_ThrowsArgumentNullException()
        {
            PooledList <T> list = GenericListFactory();

            Assert.Throws <ArgumentNullException>(() => list.ForEach(null));
            list.Dispose();
        }
예제 #4
0
        public void Reverse_RepeatedValues(int listLength, int index, int count)
        {
            PooledList <T> list = GenericListFactory(1);

            for (int i = 1; i < listLength; i++)
            {
                list.Add(list[0]);
            }
            PooledList <T> listBefore = list.ToPooledList();

            list.Reverse(index, count);

            for (int i = 0; i < index; i++)
            {
                Assert.Equal(list[i], listBefore[i]); //"Expect them to be the same."
            }

            int j = 0;

            for (int i = index; i < index + count; i++)
            {
                Assert.Equal(list[i], listBefore[index + count - (j + 1)]); //"Expect them to be the same."
                j++;
            }

            for (int i = index + count; i < listBefore.Count; i++)
            {
                Assert.Equal(list[i], listBefore[i]); //"Expect them to be the same."
            }

            list.Dispose();
            listBefore.Dispose();
        }
예제 #5
0
 public void Dispose()
 {
     if (!_buffer.WasDisposed)
     {
         _buffer.Dispose();
     }
 }
예제 #6
0
        public void PooledAddRange_Int_CapacityIncrease_Enumerable()
        {
            var pooled = new PooledList <string>();

            var enumerable = (IEnumerable <string>)sampleSet;

            for (int j = 0; j < addLoops; j++)
            {
                pooled.AddRange(enumerable);
                pooled.AddRange(enumerable);
                pooled.AddRange(enumerable);
                pooled.AddRange(enumerable);
                pooled.AddRange(enumerable);
                pooled.AddRange(enumerable);
                pooled.AddRange(enumerable);
                pooled.AddRange(enumerable);
                pooled.AddRange(enumerable);
                pooled.AddRange(enumerable);
                pooled.AddRange(enumerable);
                pooled.AddRange(enumerable);
                pooled.AddRange(enumerable);
                pooled.AddRange(enumerable);
                pooled.AddRange(enumerable);
                pooled.AddRange(enumerable);
                pooled.AddRange(enumerable);
            }

            pooled.Dispose();
        }
예제 #7
0
        public void Dispose()
        {
            _drawOperationsRefCounter?.Dispose();

            _children?.Dispose();

            Disposed = true;
        }
예제 #8
0
        public void NoSizeToCapacityItemsSet()
        {
            var list  = new PooledList <T>(13, false);
            var value = CreateT(42);

            Assert.Throws <ArgumentOutOfRangeException>(() => list[12] = value);
            list.Dispose();
        }
예제 #9
0
        public void SizeToCapacityCapacityCount()
        {
            var list = new PooledList <T>(13, true);

            Assert.InRange(list.Capacity, 13, list.Capacity);
            Assert.Equal(13, list.Count);
            list.Dispose();
        }
            public void InsertRangeIEnumerable(T[] itemsX, T[] itemsY, int index, int repeat, Func <T[], IEnumerable <T> > constructIEnumerable)
            {
                PooledList <T> list = new PooledList <T>(constructIEnumerable(itemsX));

                for (int i = 0; i < repeat; i++)
                {
                    list.InsertRange(index, constructIEnumerable(itemsY));
                }

                foreach (T item in itemsY)
                {
                    Assert.True(list.Contains(item));                               //"Should contain the item."
                }
                Assert.Equal(list.Count, itemsX.Length + (itemsY.Length * repeat)); //"Should have the same result."

                for (int i = 0; i < index; i++)
                {
                    Assert.Equal(list[i], itemsX[i]); //"Should have the same result."
                }

                for (int i = index; i < index + (itemsY.Length * repeat); i++)
                {
                    Assert.Equal(list[i], itemsY[(i - index) % itemsY.Length]); //"Should have the same result."
                }

                for (int i = index + (itemsY.Length * repeat); i < list.Count; i++)
                {
                    Assert.Equal(list[i], itemsX[i - (itemsY.Length * repeat)]); //"Should have the same result."
                }

                //InsertRange into itself
                list.Dispose();
                list = new PooledList <T>(constructIEnumerable(itemsX));
                list.InsertRange(index, list);

                foreach (T item in itemsX)
                {
                    Assert.True(list.Contains(item));                    //"Should contain the item."
                }
                Assert.Equal(list.Count, itemsX.Length + itemsX.Length); //"Should have the same result."

                for (int i = 0; i < index; i++)
                {
                    Assert.Equal(list[i], itemsX[i]); //"Should have the same result."
                }

                for (int i = index; i < index + itemsX.Length; i++)
                {
                    Assert.Equal(list[i], itemsX[(i - index) % itemsX.Length]); //"Should have the same result."
                }

                for (int i = index + (itemsX.Length); i < list.Count; i++)
                {
                    Assert.Equal(list[i], itemsX[i - (itemsX.Length)]); //"Should have the same result."
                }

                list.Dispose();
            }
예제 #11
0
        public void Constructor_Capacity(int capacity)
        {
            PooledList <T> list = new PooledList <T>(capacity);

            Assert.True(capacity <= list.Capacity);     //"Expected capacity of list to be at least the same as given."
            Assert.Empty(list);                         //"Do not expect anything to be in the list."
            Assert.False(((IList <T>)list).IsReadOnly); //"List should not be readonly"
            list.Dispose();
        }
예제 #12
0
        public void SizeToCapacityItemsSet()
        {
            var list  = new PooledList <T>(13, true);
            var value = CreateT(42);

            list[12] = value;
            Assert.Equal(value, list[12]);
            list.Dispose();
        }
 public void PooledAddRangeIEnumerable()
 {
     for (int i = 0; i < 5000; i++)
     {
         var emptyList = new PooledList <int>();
         emptyList.AddRange(IntEnumerable());
         emptyList.Dispose();
     }
 }
 public void PooledAddRangeICollection()
 {
     for (int i = 0; i < 5000; i++)
     {
         var emptyList = new PooledList <int>();
         emptyList.AddRange(list);
         emptyList.Dispose();
     }
 }
 public void CopyTo_ArgumentValidity(int count)
 {
     if (count > 0)
     {
         PooledList <T> list = GenericListFactory(count);
         AssertExtensions.Throws <ArgumentException>(null, () => list.CopyTo(new T[0]));
         list.Dispose();
     }
 }
예제 #16
0
        public void Dispose()
        {
            GC.SuppressFinalize(this);

            if (_lines is not null)
            {
                _lines.ForEach(x => x?.Dispose());
                _lines.Dispose();
            }
        }
        public void AddRange_NullEnumerable_ThrowsArgumentNullException(int count)
        {
            PooledList <T> list          = GenericListFactory(count);
            var            listBeforeAdd = list.ToPooledList();

            Assert.Throws <ArgumentNullException>(() => list.AddRange((IEnumerable <T>)null));
            Assert.Equal(listBeforeAdd, list);
            list.Dispose();
            listBeforeAdd.Dispose();
        }
        public void IndexOf_int_OutOfRangeExceptions(int count)
        {
            PooledList <T> list = GenericListFactory(count);
            T element           = CreateT(234);

            Assert.Throws <ArgumentOutOfRangeException>(() => list.IndexOf(element, count + 1));    //"Expect ArgumentOutOfRangeException for index greater than length of list.."
            Assert.Throws <ArgumentOutOfRangeException>(() => list.IndexOf(element, count + 10));   //"Expect ArgumentOutOfRangeException for index greater than length of list.."
            Assert.Throws <ArgumentOutOfRangeException>(() => list.IndexOf(element, -1));           //"Expect ArgumentOutOfRangeException for negative index."
            Assert.Throws <ArgumentOutOfRangeException>(() => list.IndexOf(element, int.MinValue)); //"Expect ArgumentOutOfRangeException for negative index."
            list.Dispose();
        }
예제 #19
0
        public void PooledAdd()
        {
            var copyList = new PooledList <int>(list);

            for (int i = 0; i < N; i++)
            {
                copyList.Add(123555); copyList.Add(123555); copyList.Add(123555); copyList.Add(123555);
                copyList.Add(123555); copyList.Add(123555); copyList.Add(123555); copyList.Add(123555);
            }
            copyList.Dispose();
        }
예제 #20
0
 public void Dispose()
 {
     if (threadMethods != null)
     {
         foreach (var tuple in threadMethods)
         {
             tuple.Item2?.Dispose();
         }
         threadMethods.Dispose();
     }
     markers?.Dispose();
 }
        public void PooledInsert_Int()
        {
            var list = new PooledList <int>();

            for (int j = 0; j < N; ++j)
            {
                list.Insert(0, j);          // Insert at the begining of the list
                list.Insert(j / 2, j);      // Insert in the middle of the list
                list.Insert(list.Count, j); // Insert at the end of the list
            }
            list.Dispose();
        }
        public void PooledInsert_String()
        {
            var list = new PooledList <string>();

            for (int j = 0; j < N; ++j)
            {
                list.Insert(0, stringToAdd);          // Insert at the begining of the list
                list.Insert(j / 2, stringToAdd);      // Insert in the middle of the list
                list.Insert(list.Count, stringToAdd); // Insert at the end of the list
            }
            list.Dispose();
        }
예제 #23
0
        public void RemoveAll_AllElements(int count)
        {
            PooledList <T> list         = GenericListFactory(count);
            PooledList <T> beforeList   = list.ToPooledList();
            int            removedCount = list.RemoveAll((value) => { return(true); });

            Assert.Equal(count, removedCount);
            Assert.Equal(0, list.Count);

            list.Dispose();
            beforeList.Dispose();
        }
        public void IndexOf_NonExistingValues(IndexOfMethod indexOfMethod, int count, bool frontToBackOrder)
        {
            PooledList <T>  list = GenericListFactory(count);
            IEnumerable <T> nonexistentValues = CreateEnumerable(EnumerableType.List, list, count: count, numberOfMatchingElements: 0, numberOfDuplicateElements: 0);
            IndexOfDelegate IndexOf           = IndexOfDelegateFromType(indexOfMethod);

            Assert.All(nonexistentValues, nonexistentValue =>
            {
                Assert.Equal(-1, IndexOf(list, nonexistentValue));
            });

            list.Dispose();
        }
예제 #25
0
        public void ConstructWithArray(int length)
        {
            var arr  = GenericArrayFactory(length);
            var list = new PooledList <T>(arr);

            Assert.Equal(arr.Length, list.Count);
            if (length > 0)
            {
                Assert.Equal(arr[0], list[0]);
                Assert.Equal(arr[arr.Length - 1], list[list.Count - 1]);
            }
            list.Dispose();
        }
        public void BinarySearch_Validations(int count)
        {
            PooledList <T> list = GenericListFactory(count);

            list.Sort();
            T element = CreateT(3215);

            AssertExtensions.Throws <ArgumentException>(null, () => list.BinarySearch(0, count + 1, element, GetIComparer()));     //"Finding items longer than array should throw ArgumentException"
            Assert.Throws <ArgumentOutOfRangeException>(() => list.BinarySearch(-1, count, element, GetIComparer()));              //"ArgumentOutOfRangeException should be thrown on negative index."
            Assert.Throws <ArgumentOutOfRangeException>(() => list.BinarySearch(0, -1, element, GetIComparer()));                  //"ArgumentOutOfRangeException should be thrown on negative count."
            AssertExtensions.Throws <ArgumentException>(null, () => list.BinarySearch(count + 1, count, element, GetIComparer())); //"ArgumentException should be thrown on index greater than length of array."
            list.Dispose();
        }
        public void IndexOf_NoDuplicates(IndexOfMethod indexOfMethod, int count, bool frontToBackOrder)
        {
            PooledList <T>  list         = GenericListFactory(count);
            PooledList <T>  expectedList = list.ToPooledList();
            IndexOfDelegate IndexOf      = IndexOfDelegateFromType(indexOfMethod);

            Assert.All(Enumerable.Range(0, count), i =>
            {
                Assert.Equal(i, IndexOf(list, expectedList[i]));
            });

            list.Dispose();
            expectedList.Dispose();
        }
예제 #28
0
        public void SizeToCapacityClearModeNever()
        {
            var items = GenericArrayFactory(13);
            var value = CreateT(42);

            items[7] = value;
            var pool = new SingleArrayPool(items);

            var list = new PooledList <T>(13, ClearMode.Never, pool, true);

            Assert.Equal(value, list[7]);

            list.Dispose();
        }
        public void IndexOf_int_int_OutOfRangeExceptions(int count)
        {
            PooledList <T> list = GenericListFactory(count);
            T element           = CreateT(234);

            Assert.Throws <ArgumentOutOfRangeException>(() => list.IndexOf(element, count, 1));                 //"ArgumentOutOfRangeException expected on index larger than array."
            Assert.Throws <ArgumentOutOfRangeException>(() => list.IndexOf(element, count + 1, 1));             //"ArgumentOutOfRangeException expected  on index larger than array."
            Assert.Throws <ArgumentOutOfRangeException>(() => list.IndexOf(element, 0, count + 1));             //"ArgumentOutOfRangeException expected  on count larger than array."
            Assert.Throws <ArgumentOutOfRangeException>(() => list.IndexOf(element, count / 2, count / 2 + 2)); //"ArgumentOutOfRangeException expected.."
            Assert.Throws <ArgumentOutOfRangeException>(() => list.IndexOf(element, 0, count + 1));             //"ArgumentOutOfRangeException expected  on count larger than array."
            Assert.Throws <ArgumentOutOfRangeException>(() => list.IndexOf(element, 0, -1));                    //"ArgumentOutOfRangeException expected on negative count."
            Assert.Throws <ArgumentOutOfRangeException>(() => list.IndexOf(element, -1, 1));                    //"ArgumentOutOfRangeException expected on negative index."
            list.Dispose();
        }
예제 #30
0
        /// <summary>
        /// Dispose and clear component data
        /// </summary>
        public void Dispose()
        {
            Array.Clear(ComponentTypes, 0, ComponentTypes.Length);
            entities.Clear();
            foreach (var component in Components.Values)
            {
                component.Dispose();
            }

            Components.Clear();

            entityToIndex.Dispose();
            entities.Dispose();
            Components.Dispose();
        }