diff --git a/perf/ListPool.Benchmarks/ListPoolClearBenchmarks.cs b/perf/ListPool.Benchmarks/ListPoolClearBenchmarks.cs index 699fea1..b3712dc 100644 --- a/perf/ListPool.Benchmarks/ListPoolClearBenchmarks.cs +++ b/perf/ListPool.Benchmarks/ListPoolClearBenchmarks.cs @@ -16,6 +16,7 @@ public class ListPoolClearBenchmarks [Params(1000)] public int N { get; set; } + [Params(0.10, 0.50, 0.80, 1)] public double CapacityFilled { get; set; } diff --git a/perf/ListPool.Benchmarks/ListPoolContainsBenchmark.cs b/perf/ListPool.Benchmarks/ListPoolContainsBenchmark.cs index efb5f2a..7d30bff 100644 --- a/perf/ListPool.Benchmarks/ListPoolContainsBenchmark.cs +++ b/perf/ListPool.Benchmarks/ListPoolContainsBenchmark.cs @@ -11,19 +11,19 @@ namespace ListPool.Benchmarks [GcConcurrent] public class ListPoolContainsBenchmark { - [Params(10, 100, 1000, 10000)] - public int N { get; set; } - private List _list; private ListPool _listPool; + [Params(10, 100, 1000, 10000)] + public int N { get; set; } + [IterationSetup] public void IterationSetup() { _list = new List(N); _listPool = new ListPool(N); - for (int i = 1; i <= N; i++) + for (int i = 1; i <= N; i++) { _list.Add(i); _listPool.Add(i); diff --git a/perf/ListPool.Benchmarks/ListPoolCopyToBenchmarks.cs b/perf/ListPool.Benchmarks/ListPoolCopyToBenchmarks.cs index 4e27be0..402eb35 100644 --- a/perf/ListPool.Benchmarks/ListPoolCopyToBenchmarks.cs +++ b/perf/ListPool.Benchmarks/ListPoolCopyToBenchmarks.cs @@ -11,14 +11,14 @@ namespace ListPool.Benchmarks [GcConcurrent] public class ListPoolCopyToBenchmarks { - [Params(10, 100, 1000, 10000)] - public int N { get; set; } - private List _list; - private ListPool _listPool; private int[] _listCopy; + private ListPool _listPool; private int[] _listPoolCopy; + [Params(10, 100, 1000, 10000)] + public int N { get; set; } + [IterationSetup] public void IterationSetup() { diff --git a/perf/ListPool.Benchmarks/ListPoolIndexOfBenchmarks.cs b/perf/ListPool.Benchmarks/ListPoolIndexOfBenchmarks.cs index cb614d0..435f631 100644 --- a/perf/ListPool.Benchmarks/ListPoolIndexOfBenchmarks.cs +++ b/perf/ListPool.Benchmarks/ListPoolIndexOfBenchmarks.cs @@ -11,12 +11,12 @@ namespace ListPool.Benchmarks [GcConcurrent] public class ListPoolIndexOfBenchmarks { - [Params(10, 100, 1000, 10000)] - public int N { get; set; } - private List _list; private ListPool _listPool; + [Params(10, 100, 1000, 10000)] + public int N { get; set; } + [IterationSetup] public void IterationSetup() { diff --git a/perf/ListPool.Benchmarks/ListPoolRemoveAtBenchmarks.cs b/perf/ListPool.Benchmarks/ListPoolRemoveAtBenchmarks.cs index 6b69e5f..afdc988 100644 --- a/perf/ListPool.Benchmarks/ListPoolRemoveAtBenchmarks.cs +++ b/perf/ListPool.Benchmarks/ListPoolRemoveAtBenchmarks.cs @@ -11,12 +11,12 @@ namespace ListPool.Benchmarks [GcConcurrent] public class ListPoolRemoveAtBenchmarks { - [Params(10, 100, 1000, 10000)] - public int N { get; set; } - private List _list; private ListPool _listPool; + [Params(10, 100, 1000, 10000)] + public int N { get; set; } + [IterationSetup] public void IterationSetup() { diff --git a/perf/ListPool.Benchmarks/ListPoolRemoveBenchmarks.cs b/perf/ListPool.Benchmarks/ListPoolRemoveBenchmarks.cs index 7b3f035..d38edb4 100644 --- a/perf/ListPool.Benchmarks/ListPoolRemoveBenchmarks.cs +++ b/perf/ListPool.Benchmarks/ListPoolRemoveBenchmarks.cs @@ -11,12 +11,12 @@ namespace ListPool.Benchmarks [GcConcurrent] public class ListPoolRemoveBenchmarks { - [Params(10, 100, 1000, 10000)] - public int N { get; set; } - private List _list; private ListPool _listPool; + [Params(10, 100, 1000, 10000)] + public int N { get; set; } + [IterationSetup] public void IterationSetup() { diff --git a/src/ListPool/ListPool.cs b/src/ListPool/ListPool.cs index 240de8f..424cefc 100644 --- a/src/ListPool/ListPool.cs +++ b/src/ListPool/ListPool.cs @@ -4,29 +4,51 @@ using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Contracts; using System.Runtime.CompilerServices; +using System.Threading; namespace ListPool { - public struct ListPool : IList, IReadOnlyList, IDisposable, + public struct ListPool : IList, IList, IReadOnlyList, IDisposable, IValueEnumerable { - public readonly int Capacity => _bufferOwner.IsValid ? _bufferOwner.Buffer.Length : 0; + public readonly int Capacity => _bufferOwner.IsValid ? _bufferOwner.Buffer.Length : 0; public readonly int Count => _itemsCount; public readonly bool IsReadOnly => false; - + int ICollection.Count => _itemsCount; + readonly bool IList.IsFixedSize => false; + bool ICollection.IsSynchronized => false; + readonly bool IList.IsReadOnly => false; private BufferOwner _bufferOwner; private int _itemsCount; private const int MinimumCapacity = 128; + [NonSerialized] + private object _syncRoot; + + object ICollection.SyncRoot + { + get + { + if (_syncRoot == null) + { + _ = Interlocked.CompareExchange(ref _syncRoot, new object(), null); + } + + return _syncRoot; + } + } + public ListPool(int length) { + _syncRoot = null; _bufferOwner = new BufferOwner(length < MinimumCapacity ? MinimumCapacity : length); _itemsCount = 0; } public ListPool(IEnumerable source) { + _syncRoot = null; if (source is ICollection collection) { _bufferOwner = new BufferOwner(collection.Count); @@ -56,14 +78,84 @@ public void Add(TSource item) _bufferOwner.Buffer[_itemsCount++] = item; } + int IList.Add(object item) + { + if (item is TSource itemAsTSource) + { + Add(itemAsTSource); + } + else + { + throw new ArgumentException($"Wrong value type. Expected {typeof(TSource)}, got: '{item}'.", + nameof(item)); + } + + return Count - 1; + } + + public void Clear() => _itemsCount = 0; public readonly bool Contains(TSource item) => IndexOf(item) > -1; - public readonly int IndexOf(TSource item) => _bufferOwner.IsValid ? Array.IndexOf(_bufferOwner.Buffer, item, 0, _itemsCount) : -1; + bool IList.Contains(object item) + { + if (item is TSource itemAsTSource) + { + return Contains(itemAsTSource); + } + + throw new ArgumentException($"Wrong value type. Expected {typeof(TSource)}, got: '{item}'.", nameof(item)); + } + + int IList.IndexOf(object item) + { + if (item is TSource itemAsTSource) + { + return IndexOf(itemAsTSource); + } + + throw new ArgumentException($"Wrong value type. Expected {typeof(TSource)}, got: '{item}'.", nameof(item)); + } + + void IList.Remove(object item) + { + if (item is null) + { + return; + } + + if (!(item is TSource itemAsTSource)) + { + throw new ArgumentException($"Wrong value type. Expected {typeof(TSource)}, got: '{item}'.", + nameof(item)); + } + + Remove(itemAsTSource); + } + + void IList.Insert(int index, object item) + { + if (!(item is TSource itemAsTSource)) + { + throw new ArgumentException($"Wrong value type. Expected {typeof(TSource)}, got: '{item}'.", + nameof(item)); + } + + Insert(index, itemAsTSource); + } + + public readonly int IndexOf(TSource item) => + _bufferOwner.IsValid ? Array.IndexOf(_bufferOwner.Buffer, item, 0, _itemsCount) : -1; public readonly void CopyTo(TSource[] array, int arrayIndex) => Array.Copy(_bufferOwner.Buffer, 0, array, arrayIndex, _itemsCount); + void ICollection.CopyTo(Array array, int arrayIndex) + { + // Array.Copy will check for NULL. + Array.Copy(_bufferOwner.Buffer, 0, array, arrayIndex, _itemsCount); + } + public bool Remove(TSource item) { if (item == null) return false; @@ -105,7 +197,7 @@ public readonly TSource this[int index] [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - if (index < 0 || index >= _bufferOwner.Buffer.Length || index >= _itemsCount) + if (index < 0 || index >= _itemsCount) throw new ArgumentOutOfRangeException(nameof(index)); return _bufferOwner.Buffer[index]; @@ -113,13 +205,43 @@ public readonly TSource this[int index] set { - if (index < 0 || index >= _bufferOwner.Buffer.Length || index >= _itemsCount) + if (index < 0 || index >= _itemsCount) throw new ArgumentOutOfRangeException(nameof(index)); _bufferOwner.Buffer[index] = value; } } + [MaybeNull] + readonly object IList.this[int index] + { + [Pure] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get + { + if (index < 0 || index >= _itemsCount) + throw new ArgumentOutOfRangeException(nameof(index)); + + return _bufferOwner.Buffer[index]; + } + + set + { + if (index < 0 || index >= _itemsCount) + throw new ArgumentOutOfRangeException(nameof(index)); + + if (value is TSource valueAsTSource) + { + _bufferOwner.Buffer[index] = valueAsTSource; + } + else + { + throw new ArgumentException($"Wrong value type. Expected {typeof(TSource)}, got: '{value}'.", + nameof(value)); + } + } + } + [Pure] [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly Enumerator GetEnumerator() => diff --git a/tests/ListPool.UnitTests/EnumeratorTests.cs b/tests/ListPool.UnitTests/EnumeratorTests.cs index 9bb540e..4d048b2 100644 --- a/tests/ListPool.UnitTests/EnumeratorTests.cs +++ b/tests/ListPool.UnitTests/EnumeratorTests.cs @@ -23,6 +23,20 @@ public void Current_is_updated_in_each_iteration() } } + [Fact] + public void Current_is_updated_in_each_iteration_using_IEnumerator() + { + string[] items = s_fixture.CreateMany(10).ToArray(); + IEnumerator expectedEnumerator = items.GetEnumerator(); + IEnumerator sut = new Enumerator(items, items.Length); + + while (expectedEnumerator.MoveNext()) + { + Assert.True(sut.MoveNext()); + Assert.Equal(expectedEnumerator.Current, sut.Current); + } + } + [Fact] public void Reset_allows_enumerator_to_be_enumerate_again() { @@ -35,6 +49,7 @@ public void Reset_allows_enumerator_to_be_enumerate_again() Assert.True(sut.MoveNext()); Assert.Equal(expectedEnumerator.Current, sut.Current); } + Assert.False(sut.MoveNext()); sut.Reset(); expectedEnumerator.Reset(); diff --git a/tests/ListPool.UnitTests/ListPoolAsIList.cs b/tests/ListPool.UnitTests/ListPoolAsIList.cs new file mode 100644 index 0000000..4208084 --- /dev/null +++ b/tests/ListPool.UnitTests/ListPoolAsIList.cs @@ -0,0 +1,528 @@ +using System; +using System.Collections; +using System.Linq; +using AutoFixture; +using Xunit; + +namespace ListPool.UnitTests +{ + public class ListPoolAsIList : ListPoolTestsBase + { + public override void Add_item_without_indicate_capacity_of_list() + { + int expectedItem = s_fixture.Create(); + using var listPool = new ListPool {expectedItem}; + IList sut = listPool; + + Assert.Equal(expectedItem, sut[0]); + } + + + public override void Add_items_when_capacity_is_full_then_buffer_autogrow() + { + using var listPool = new ListPool(128); + IList sut = listPool; + var expectedItems = s_fixture.CreateMany(listPool.Capacity * 2).ToList(); + + foreach (int expectedItem in expectedItems) + { + sut.Add(expectedItem); + } + + Assert.Equal(expectedItems.Count, sut.Count); + Assert.True(expectedItems.All(expectedItem => sut.Contains(expectedItem))); + } + + public override void Contains_empty_ListPool_without_indicating_capacity_returns_false() + { + int randomItem = s_fixture.Create(); + using var listPool = new ListPool(); + IList sut = listPool; + + bool actual = sut.Contains(randomItem); + + Assert.False(actual); + } + + + public override void Contains_return_true_when_item_exists() + { + int expectedAt0 = s_fixture.Create(); + int expectedAt1 = s_fixture.Create(); + int expectedAt2 = s_fixture.Create(); + int unexpected = s_fixture.Create(); + + using var listPool = new ListPool(3) {expectedAt0, expectedAt1, expectedAt2}; + IList sut = listPool; + + Assert.True(sut.Contains(expectedAt0)); + Assert.True(sut.Contains(expectedAt1)); + Assert.True(sut.Contains(expectedAt2)); + Assert.False(sut.Contains(unexpected)); + } + + + public override void CopyTo_copy_all_elements_to_target_array() + { + int expectedAt0 = s_fixture.Create(); + int expectedAt1 = s_fixture.Create(); + int expectedAt2 = s_fixture.Create(); + using var listPool = new ListPool(3) {expectedAt0, expectedAt1, expectedAt2}; + IList sut = listPool; + int[] array = new int[3]; + + sut.CopyTo(array, 0); + + Assert.Equal(sut.Count, array.Length); + Assert.Contains(expectedAt0, array); + Assert.Contains(expectedAt1, array); + Assert.Contains(expectedAt2, array); + } + + + public override void Count_property_is_for_items_Added_count_not_capacity_of_buffer() + { + const int listCapacity = 10; + const int expectedItemsCount = 3; + + using var listPool = new ListPool(listCapacity) {1, 2, 3}; + IList sut = listPool; + + Assert.Equal(expectedItemsCount, sut.Count); + } + + + public override void Create_list_and_add_values() + { + int expectedAt0 = s_fixture.Create(); + int expectedAt1 = s_fixture.Create(); + int expectedAt2 = s_fixture.Create(); + + using var listPool = new ListPool(3) {expectedAt0, expectedAt1, expectedAt2}; + IList sut = listPool; + + Assert.Equal(expectedAt0, sut[0]); + Assert.Equal(expectedAt1, sut[1]); + Assert.Equal(expectedAt2, sut[2]); + } + + + public override void Create_list_and_add_values_after_clear() + { + using var listPool = + new ListPool(3) {s_fixture.Create(), s_fixture.Create(), s_fixture.Create()}; + IList sut = listPool; + + sut.Clear(); + + Assert.Empty(sut); + } + + + public override void Create_without_parameters_should_add_and_get_items() + { + const int expectedItemsCount = 3; + int expectedAt0 = s_fixture.Create(); + int expectedAt1 = s_fixture.Create(); + int expectedAt2 = s_fixture.Create(); + + using var listPool = new ListPool {expectedAt0, expectedAt1, expectedAt2}; + IList sut = listPool; + + Assert.Equal(expectedAt0, sut[0]); + Assert.Equal(expectedAt1, sut[1]); + Assert.Equal(expectedAt2, sut[2]); + Assert.Equal(expectedItemsCount, sut.Count); + } + + + public override void Enumerate_when_capacity_is_not_set_dont_throw_exception() + { + using var listPool = new ListPool(); + IList sut = listPool; + + foreach (int _ in sut) + { + } + } + + + public override void Get_item_with_index_above_itemsCount_throws_ArgumentOutOfRangeException() + { + const int index = 2; + using var listPool = new ListPool {s_fixture.Create()}; + IList sut = listPool; + + ArgumentOutOfRangeException exception = Assert.Throws(() => sut[index]); + + Assert.Equal(nameof(index), exception.ParamName); + } + + + public override void Get_item_with_index_bellow_zero_throws_ArgumentOutOfRangeException() + { + int index = -1; + var listPool = new ListPool(); + IList sut = listPool; + + ArgumentOutOfRangeException exception = Assert.Throws(() => sut[index]); + + Assert.Equal(nameof(index), exception.ParamName); + } + + + public override void IndexOf_empty_ListPool_without_indicating_capacity_returns_negative_one() + { + int randomItem = s_fixture.Create(); + const int expected = -1; + using var listPool = new ListPool(); + IList sut = listPool; + + int actual = sut.IndexOf(randomItem); + + Assert.Equal(expected, actual); + } + + + public override void IndexOf_returns_index_of_item() + { + int expectedAt0 = s_fixture.Create(); + int expectedAt1 = s_fixture.Create(); + int expectedAt2 = s_fixture.Create(); + using var listPool = new ListPool(3) {expectedAt0, expectedAt1, expectedAt2}; + IList sut = listPool; + + Assert.Equal(0, sut.IndexOf(expectedAt0)); + Assert.Equal(1, sut.IndexOf(expectedAt1)); + Assert.Equal(2, sut.IndexOf(expectedAt2)); + } + + + public override void Insert_at_existing_index_move_items_up() + { + int[] expectedItems = s_fixture.CreateMany(3).ToArray(); + int expectedItemAt1 = s_fixture.Create(); + int expectedItemsCount = expectedItems.Length + 1; + using var listPool = expectedItems.ToListPool(); + IList sut = listPool; + + sut.Insert(1, expectedItemAt1); + + Assert.Equal(expectedItemsCount, sut.Count); + Assert.Equal(expectedItems[0], (int)sut[0]); + Assert.Equal(expectedItemAt1, (int)sut[1]); + Assert.Equal(expectedItems[1], (int)sut[2]); + Assert.Equal(expectedItems[2], (int)sut[3]); + } + + + public override void Insert_at_the_end_add_new_item() + { + int expectedAt3 = s_fixture.Create(); + using var listPool = + new ListPool(4) {s_fixture.Create(), s_fixture.Create(), s_fixture.Create()}; + IList sut = listPool; + + sut.Insert(3, expectedAt3); + + Assert.Equal(4, sut.Count); + Assert.Equal(expectedAt3, sut[3]); + } + + + public override void Insert_item_with_index_above_itemsCount_throws_ArgumentOutOfRangeException() + { + const int index = 2; + using var listPool = new ListPool {s_fixture.Create()}; + IList sut = listPool; + int item = s_fixture.Create(); + + ArgumentOutOfRangeException exception = + Assert.Throws(() => sut.Insert(index, item)); + + Assert.Equal(nameof(index), exception.ParamName); + } + + + public override void Insert_item_with_index_bellow_zero_throws_ArgumentOutOfRangeException() + { + const int index = -1; + int item = s_fixture.Create(); + using var listPool = new ListPool(); + IList sut = listPool; + + ArgumentOutOfRangeException exception = + Assert.Throws(() => sut.Insert(index, item)); + + Assert.Equal(nameof(index), exception.ParamName); + } + + + public override void Insert_items_when_capacity_is_full_then_buffer_autogrow() + { + using var listPool = new ListPool(128); + IList sut = listPool; + var expectedItems = s_fixture.CreateMany(listPool.Capacity * 2).ToList(); + int index = 0; + + foreach (int expectedItem in expectedItems) + { + sut.Insert(index++, expectedItem); + } + + Assert.Equal(expectedItems.Count, sut.Count); + Assert.True(expectedItems.All(expectedItem => sut.Contains(expectedItem))); + } + + + public override void Insert_without_indicating_capacity_of_list() + { + const int index = 0; + int expectedItem = s_fixture.Create(); + using var listPool = new ListPool(); + IList sut = listPool; + + sut.Insert(index, expectedItem); + + Assert.Equal(expectedItem, sut[0]); + } + + + public override void Readonly_property_is_always_false() + { + using var listPool = new ListPool(); + IList sut = listPool; + + Assert.False(sut.IsReadOnly); + } + + + public override void Remove_item_that_doesnt_exists_return_false() + { + string item = s_fixture.Create(); + using var listPool = new ListPool {s_fixture.Create()}; + IList sut = listPool; + + sut.Remove(item); + + Assert.Single(sut); + } + + + public override void Remove_when_item_exists_remove_item_and_decrease_itemsCount() + { + const int expectedCountAfterRemove = 2; + int expectedAt0 = s_fixture.Create(); + using var listPool = new ListPool(3) {expectedAt0, s_fixture.Create(), s_fixture.Create()}; + IList sut = listPool; + + sut.Remove(expectedAt0); + + Assert.False(sut.Contains(expectedAt0)); + Assert.Equal(expectedCountAfterRemove, sut.Count); + } + + + public override void Remove_when_item_is_null_return_false() + { + string item = null; + using var listPool = new ListPool(); + IList sut = listPool; + + sut.Remove(item); + } + + + public override void RemoveAt_when_item_exists_remove_item_and_decrease_itemsCount() + { + const int expectedCountAfterRemove = 2; + int expectedAt1 = s_fixture.Create(); + using var listPool = new ListPool(3) {s_fixture.Create(), expectedAt1, s_fixture.Create()}; + IList sut = listPool; + + sut.RemoveAt(1); + + Assert.False(sut.Contains(expectedAt1)); + Assert.Equal(expectedCountAfterRemove, sut.Count); + } + + + public override void RemoveAt_with_index_above_itemsCount_throws_ArgumentOutOfRangeException() + { + const int index = 2; + using var listPool = new ListPool {s_fixture.Create()}; + IList sut = listPool; + + ArgumentOutOfRangeException exception = + Assert.Throws(() => sut.RemoveAt(index)); + + Assert.Equal(nameof(index), exception.ParamName); + } + + + public override void RemoveAt_with_index_bellow_zero_throws_ArgumentOutOfRangeException() + { + const int index = -1; + using var listPool = new ListPool(); + IList sut = listPool; + + ArgumentOutOfRangeException exception = + Assert.Throws(() => sut.RemoveAt(index)); + + Assert.Equal(nameof(index), exception.ParamName); + } + + + public override void RemoveAt_with_index_zero_when_not_item_added_throws_ArgumentOutOfRangeException() + { + const int index = 0; + using var listPool = new ListPool(); + IList sut = listPool; + + ArgumentOutOfRangeException exception = + Assert.Throws(() => sut.RemoveAt(index)); + + Assert.Equal(nameof(index), exception.ParamName); + } + + + public override void Set_at_existing_index_update_item() + { + const int expectedItemsCount = 3; + int expectedItem = s_fixture.Create(); + using var listPool = + new ListPool(3) {s_fixture.Create(), s_fixture.Create(), s_fixture.Create()}; + IList sut = listPool; + + sut[2] = expectedItem; + + Assert.Equal(expectedItemsCount, sut.Count); + Assert.Equal(expectedItem, sut[2]); + } + + + public override void Set_item_with_index_above_itemsCount_throws_ArgumentOutOfRangeException() + { + const int index = 2; + using var listPool = new ListPool {s_fixture.Create()}; + IList sut = listPool; + int item = s_fixture.Create(); + + ArgumentOutOfRangeException exception = Assert.Throws(() => sut[index] = item); + + Assert.Equal(nameof(index), exception.ParamName); + } + + + public override void Set_item_with_index_bellow_zero_throws_ArgumentOutOfRangeException() + { + const int index = -1; + int item = s_fixture.Create(); + var listPool = new ListPool(); + IList sut = listPool; + + ArgumentOutOfRangeException exception = Assert.Throws(() => sut[index] = item); + + Assert.Equal(nameof(index), exception.ParamName); + } + + [Fact] + public void Add_item_when_is_not_same_type_throw_ArgumentException() + { + using var listPool = new ListPool(); + IList sut = listPool; + string itemWithWrongType = s_fixture.Create(); + + ArgumentException actualException = Assert.Throws(() => sut.Add(itemWithWrongType)); + Assert.Equal("item", actualException.ParamName); + } + + [Fact] + public void Contains_item_with_another_type_throws_ArgumentException() + { + string itemWithWrongType = s_fixture.Create(); + var listPool = new ListPool {s_fixture.Create()}; + IList sut = listPool; + + ArgumentException exception = Assert.Throws(() => sut.Contains(itemWithWrongType)); + + Assert.Equal("item", exception.ParamName); + } + + [Fact] + public void IndexOf_item_with_another_type_throws_ArgumentException() + { + string itemWithWrongType = s_fixture.Create(); + var listPool = new ListPool {s_fixture.Create()}; + IList sut = listPool; + + ArgumentException exception = Assert.Throws(() => sut.IndexOf(itemWithWrongType)); + + Assert.Equal("item", exception.ParamName); + } + + [Fact] + public void Insert_item_when_is_not_same_type_throw_ArgumentException() + { + using var listPool = new ListPool(); + IList sut = listPool; + string itemWithWrongType = s_fixture.Create(); + + ArgumentException actualException = + Assert.Throws(() => sut.Insert(0, itemWithWrongType)); + Assert.Equal("item", actualException.ParamName); + } + + [Fact] + public void IsFixedSize_always_return_false() + { + using var listPool = new ListPool(); + IList sut = listPool; + + Assert.False(sut.IsFixedSize); + } + + [Fact] + public void IsSynchronized_always_return_false() + { + using var listPool = new ListPool(); + IList sut = listPool; + + Assert.False(sut.IsSynchronized); + } + + [Fact] + public void Remove_item_with_another_type_throws_ArgumentException() + { + string itemWithWrongType = s_fixture.Create(); + var listPool = new ListPool {s_fixture.Create()}; + IList sut = listPool; + + ArgumentException exception = Assert.Throws(() => sut.Remove(itemWithWrongType)); + + Assert.Equal("item", exception.ParamName); + } + + [Fact] + public void Set_item_with_another_type_throws_ArgumentException() + { + const int index = 0; + string itemWithWrongType = s_fixture.Create(); + var listPool = new ListPool {s_fixture.Create()}; + IList sut = listPool; + + ArgumentException exception = Assert.Throws(() => sut[index] = itemWithWrongType); + + Assert.Equal("value", exception.ParamName); + } + + [Fact] + public void SyncRoot_never_is_null() + { + using var listPool = new ListPool(); + IList sut = listPool; + + Assert.NotNull(sut.SyncRoot); + } + } +} diff --git a/tests/ListPool.UnitTests/ListPoolAsIListOfTSource.cs b/tests/ListPool.UnitTests/ListPoolAsIListOfTSource.cs new file mode 100644 index 0000000..fe6f442 --- /dev/null +++ b/tests/ListPool.UnitTests/ListPoolAsIListOfTSource.cs @@ -0,0 +1,430 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using AutoFixture; +using Xunit; + +namespace ListPool.UnitTests +{ + public class ListPoolAsIListOfTSource : ListPoolTestsBase + { + public override void Add_item_without_indicate_capacity_of_list() + { + int expectedItem = s_fixture.Create(); + using var listPool = new ListPool {expectedItem}; + IList sut = listPool; + + Assert.Equal(expectedItem, sut[0]); + } + + + public override void Add_items_when_capacity_is_full_then_buffer_autogrow() + { + using var listPool = new ListPool(128); + IList sut = listPool; + var expectedItems = s_fixture.CreateMany(listPool.Capacity * 2).ToList(); + + foreach (int expectedItem in expectedItems) + { + sut.Add(expectedItem); + } + + Assert.Equal(expectedItems.Count, sut.Count); + Assert.True(expectedItems.All(expectedItem => sut.Contains(expectedItem))); + } + + + public override void Contains_empty_ListPool_without_indicating_capacity_returns_false() + { + int randomItem = s_fixture.Create(); + using var listPool = new ListPool(); + IList sut = listPool; + + bool actual = sut.Contains(randomItem); + + Assert.False(actual); + } + + + public override void Contains_return_true_when_item_exists() + { + int expectedAt0 = s_fixture.Create(); + int expectedAt1 = s_fixture.Create(); + int expectedAt2 = s_fixture.Create(); + int unexpected = s_fixture.Create(); + + using var listPool = new ListPool(3) {expectedAt0, expectedAt1, expectedAt2}; + IList sut = listPool; + + Assert.Contains(expectedAt0, sut); + Assert.Contains(expectedAt1, sut); + Assert.Contains(expectedAt2, sut); + Assert.DoesNotContain(unexpected, sut); + } + + + public override void CopyTo_copy_all_elements_to_target_array() + { + int expectedAt0 = s_fixture.Create(); + int expectedAt1 = s_fixture.Create(); + int expectedAt2 = s_fixture.Create(); + using var listPool = new ListPool(3) {expectedAt0, expectedAt1, expectedAt2}; + IList sut = listPool; + int[] array = new int[3]; + + sut.CopyTo(array, 0); + + Assert.Equal(sut.Count, array.Length); + Assert.Contains(expectedAt0, array); + Assert.Contains(expectedAt1, array); + Assert.Contains(expectedAt2, array); + } + + + public override void Count_property_is_for_items_Added_count_not_capacity_of_buffer() + { + const int listCapacity = 10; + const int expectedItemsCount = 3; + + using var listPool = new ListPool(listCapacity) {1, 2, 3}; + IList sut = listPool; + + Assert.Equal(expectedItemsCount, sut.Count); + } + + + public override void Create_list_and_add_values() + { + int expectedAt0 = s_fixture.Create(); + int expectedAt1 = s_fixture.Create(); + int expectedAt2 = s_fixture.Create(); + + using var listPool = new ListPool(3) {expectedAt0, expectedAt1, expectedAt2}; + IList sut = listPool; + + Assert.Equal(expectedAt0, sut[0]); + Assert.Equal(expectedAt1, sut[1]); + Assert.Equal(expectedAt2, sut[2]); + } + + + public override void Create_list_and_add_values_after_clear() + { + using var listPool = + new ListPool(3) {s_fixture.Create(), s_fixture.Create(), s_fixture.Create()}; + IList sut = listPool; + + sut.Clear(); + + Assert.Empty(sut); + } + + + public override void Create_without_parameters_should_add_and_get_items() + { + const int expectedItemsCount = 3; + int expectedAt0 = s_fixture.Create(); + int expectedAt1 = s_fixture.Create(); + int expectedAt2 = s_fixture.Create(); + + using var listPool = new ListPool {expectedAt0, expectedAt1, expectedAt2}; + IList sut = listPool; + + Assert.Equal(expectedAt0, sut[0]); + Assert.Equal(expectedAt1, sut[1]); + Assert.Equal(expectedAt2, sut[2]); + Assert.Equal(expectedItemsCount, sut.Count); + } + + + public override void Enumerate_when_capacity_is_not_set_dont_throw_exception() + { + using var listPool = new ListPool(); + IList sut = listPool; + + foreach (int _ in sut) + { + } + } + + + public override void Get_item_with_index_above_itemsCount_throws_ArgumentOutOfRangeException() + { + const int index = 2; + using var listPool = new ListPool {s_fixture.Create()}; + IList sut = listPool; + + ArgumentOutOfRangeException exception = Assert.Throws(() => sut[index]); + + Assert.Equal(nameof(index), exception.ParamName); + } + + + public override void Get_item_with_index_bellow_zero_throws_ArgumentOutOfRangeException() + { + int index = -1; + var listPool = new ListPool(); + IList sut = listPool; + + ArgumentOutOfRangeException exception = Assert.Throws(() => sut[index]); + + Assert.Equal(nameof(index), exception.ParamName); + } + + + public override void IndexOf_empty_ListPool_without_indicating_capacity_returns_negative_one() + { + int randomItem = s_fixture.Create(); + const int expected = -1; + using var listPool = new ListPool(); + IList sut = listPool; + + int actual = sut.IndexOf(randomItem); + + Assert.Equal(expected, actual); + } + + + public override void IndexOf_returns_index_of_item() + { + int expectedAt0 = s_fixture.Create(); + int expectedAt1 = s_fixture.Create(); + int expectedAt2 = s_fixture.Create(); + using var listPool = new ListPool(3) {expectedAt0, expectedAt1, expectedAt2}; + IList sut = listPool; + + Assert.Equal(0, sut.IndexOf(expectedAt0)); + Assert.Equal(1, sut.IndexOf(expectedAt1)); + Assert.Equal(2, sut.IndexOf(expectedAt2)); + } + + + public override void Insert_at_existing_index_move_items_up() + { + int[] expectedItems = s_fixture.CreateMany(3).ToArray(); + int expectedItemAt1 = s_fixture.Create(); + int expectedItemsCount = expectedItems.Length + 1; + using var listPool = expectedItems.ToListPool(); + IList sut = listPool; + + sut.Insert(1, expectedItemAt1); + + Assert.Equal(expectedItemsCount, sut.Count); + Assert.Equal(expectedItems[0], sut[0]); + Assert.Equal(expectedItemAt1, sut[1]); + Assert.Equal(expectedItems[1], sut[2]); + Assert.Equal(expectedItems[2], sut[3]); + } + + + public override void Insert_at_the_end_add_new_item() + { + int expectedAt3 = s_fixture.Create(); + using var listPool = + new ListPool(4) {s_fixture.Create(), s_fixture.Create(), s_fixture.Create()}; + IList sut = listPool; + + sut.Insert(3, expectedAt3); + + Assert.Equal(4, sut.Count); + Assert.Equal(expectedAt3, sut[3]); + } + + + public override void Insert_item_with_index_above_itemsCount_throws_ArgumentOutOfRangeException() + { + const int index = 2; + using var listPool = new ListPool {s_fixture.Create()}; + IList sut = listPool; + int item = s_fixture.Create(); + + ArgumentOutOfRangeException exception = + Assert.Throws(() => sut.Insert(index, item)); + + Assert.Equal(nameof(index), exception.ParamName); + } + + + public override void Insert_item_with_index_bellow_zero_throws_ArgumentOutOfRangeException() + { + const int index = -1; + int item = s_fixture.Create(); + using var listPool = new ListPool(); + IList sut = listPool; + + ArgumentOutOfRangeException exception = + Assert.Throws(() => sut.Insert(index, item)); + + Assert.Equal(nameof(index), exception.ParamName); + } + + + public override void Insert_items_when_capacity_is_full_then_buffer_autogrow() + { + using var listPool = new ListPool(128); + IList sut = listPool; + var expectedItems = s_fixture.CreateMany(listPool.Capacity * 2).ToList(); + int index = 0; + + foreach (int expectedItem in expectedItems) + { + sut.Insert(index++, expectedItem); + } + + Assert.Equal(expectedItems.Count, sut.Count); + Assert.True(expectedItems.All(expectedItem => sut.Contains(expectedItem))); + } + + + public override void Insert_without_indicating_capacity_of_list() + { + const int index = 0; + int expectedItem = s_fixture.Create(); + using var listPool = new ListPool(); + IList sut = listPool; + + sut.Insert(index, expectedItem); + + Assert.Equal(expectedItem, sut[0]); + } + + + public override void Readonly_property_is_always_false() + { + using var listPool = new ListPool(); + IList sut = listPool; + + Assert.False(sut.IsReadOnly); + } + + + public override void Remove_item_that_doesnt_exists_return_false() + { + string item = s_fixture.Create(); + using var listPool = new ListPool {s_fixture.Create()}; + IList sut = listPool; + + Assert.False(sut.Remove(item)); + Assert.Single(sut); + } + + + public override void Remove_when_item_exists_remove_item_and_decrease_itemsCount() + { + const int expectedCountAfterRemove = 2; + int expectedAt0 = s_fixture.Create(); + using var listPool = new ListPool(3) {expectedAt0, s_fixture.Create(), s_fixture.Create()}; + IList sut = listPool; + + bool wasRemoved = sut.Remove(expectedAt0); + + Assert.True(wasRemoved); + Assert.DoesNotContain(expectedAt0, sut); + Assert.Equal(expectedCountAfterRemove, sut.Count); + } + + + public override void Remove_when_item_is_null_return_false() + { + string item = null; + using var listPool = new ListPool(); + IList sut = listPool; + + Assert.False(sut.Remove(item)); + } + + + public override void RemoveAt_when_item_exists_remove_item_and_decrease_itemsCount() + { + const int expectedCountAfterRemove = 2; + int expectedAt1 = s_fixture.Create(); + using var listPool = new ListPool(3) {s_fixture.Create(), expectedAt1, s_fixture.Create()}; + IList sut = listPool; + + sut.RemoveAt(1); + + Assert.DoesNotContain(expectedAt1, sut); + Assert.Equal(expectedCountAfterRemove, sut.Count); + } + + + public override void RemoveAt_with_index_above_itemsCount_throws_ArgumentOutOfRangeException() + { + const int index = 2; + using var listPool = new ListPool {s_fixture.Create()}; + IList sut = listPool; + + ArgumentOutOfRangeException exception = + Assert.Throws(() => sut.RemoveAt(index)); + + Assert.Equal(nameof(index), exception.ParamName); + } + + + public override void RemoveAt_with_index_bellow_zero_throws_ArgumentOutOfRangeException() + { + const int index = -1; + using var listPool = new ListPool(); + IList sut = listPool; + + ArgumentOutOfRangeException exception = + Assert.Throws(() => sut.RemoveAt(index)); + + Assert.Equal(nameof(index), exception.ParamName); + } + + + public override void RemoveAt_with_index_zero_when_not_item_added_throws_ArgumentOutOfRangeException() + { + const int index = 0; + using var listPool = new ListPool(); + IList sut = listPool; + + ArgumentOutOfRangeException exception = + Assert.Throws(() => sut.RemoveAt(index)); + + Assert.Equal(nameof(index), exception.ParamName); + } + + + public override void Set_at_existing_index_update_item() + { + const int expectedItemsCount = 3; + int expectedItem = s_fixture.Create(); + using var listPool = + new ListPool(3) {s_fixture.Create(), s_fixture.Create(), s_fixture.Create()}; + IList sut = listPool; + + sut[2] = expectedItem; + + Assert.Equal(expectedItemsCount, sut.Count); + Assert.Equal(expectedItem, sut[2]); + } + + + public override void Set_item_with_index_above_itemsCount_throws_ArgumentOutOfRangeException() + { + const int index = 2; + using var listPool = new ListPool {s_fixture.Create()}; + IList sut = listPool; + int item = s_fixture.Create(); + + ArgumentOutOfRangeException exception = Assert.Throws(() => sut[index] = item); + + Assert.Equal(nameof(index), exception.ParamName); + } + + + public override void Set_item_with_index_bellow_zero_throws_ArgumentOutOfRangeException() + { + const int index = -1; + int item = s_fixture.Create(); + var listPool = new ListPool(); + IList sut = listPool; + + ArgumentOutOfRangeException exception = Assert.Throws(() => sut[index] = item); + + Assert.Equal(nameof(index), exception.ParamName); + } + } +} diff --git a/tests/ListPool.UnitTests/ListPoolTests.cs b/tests/ListPool.UnitTests/ListPoolTests.cs index 480a364..7de6e80 100644 --- a/tests/ListPool.UnitTests/ListPoolTests.cs +++ b/tests/ListPool.UnitTests/ListPoolTests.cs @@ -1,29 +1,22 @@ using System; -using System.Collections.Generic; using System.Linq; using AutoFixture; using Xunit; namespace ListPool.UnitTests { - public class ListPoolTests + public class ListPoolTests : ListPoolTestsBase { - private static readonly Fixture s_fixture = new Fixture(); - - [Fact] - public void Add_item_without_indicate_capacity_of_list() + public override void Add_item_without_indicate_capacity_of_list() { int expectedItem = s_fixture.Create(); - using var sut = new ListPool - { - expectedItem - }; + using var sut = new ListPool {expectedItem}; Assert.Equal(expectedItem, sut[0]); } - [Fact] - public void Add_items_when_capacity_is_full_then_buffer_autogrow() + + public override void Add_items_when_capacity_is_full_then_buffer_autogrow() { using var sut = new ListPool(128); var expectedItems = s_fixture.CreateMany(sut.Capacity * 2).ToList(); @@ -37,15 +30,26 @@ public void Add_items_when_capacity_is_full_then_buffer_autogrow() Assert.True(expectedItems.All(expectedItem => sut.Contains(expectedItem))); } - [Fact] - public void Contains_return_true_when_item_exists() + + public override void Contains_empty_ListPool_without_indicating_capacity_returns_false() + { + int randomItem = s_fixture.Create(); + using var sut = new ListPool(); + + bool actual = sut.Contains(randomItem); + + Assert.False(actual); + } + + + public override void Contains_return_true_when_item_exists() { int expectedAt0 = s_fixture.Create(); int expectedAt1 = s_fixture.Create(); int expectedAt2 = s_fixture.Create(); int unexpected = s_fixture.Create(); - using var sut = new ListPool(3) { expectedAt0, expectedAt1, expectedAt2 }; + using var sut = new ListPool(3) {expectedAt0, expectedAt1, expectedAt2}; Assert.Contains(expectedAt0, sut); Assert.Contains(expectedAt1, sut); @@ -53,8 +57,8 @@ public void Contains_return_true_when_item_exists() Assert.DoesNotContain(unexpected, sut); } - [Fact] - public void CopyTo_copy_all_elements_to_target_array() + + public override void CopyTo_copy_all_elements_to_target_array() { int expectedAt0 = s_fixture.Create(); int expectedAt1 = s_fixture.Create(); @@ -70,33 +74,33 @@ public void CopyTo_copy_all_elements_to_target_array() Assert.Contains(expectedAt2, array); } - [Fact] - public void Count_property_is_for_items_Added_count_not_capacity_of_buffer() + + public override void Count_property_is_for_items_Added_count_not_capacity_of_buffer() { const int listCapacity = 10; const int expectedItemsCount = 3; - using var sut = new ListPool(listCapacity) { 1, 2, 3 }; + using var sut = new ListPool(listCapacity) {1, 2, 3}; Assert.Equal(expectedItemsCount, sut.Count); } - [Fact] - public void Create_list_and_add_values() + + public override void Create_list_and_add_values() { int expectedAt0 = s_fixture.Create(); int expectedAt1 = s_fixture.Create(); int expectedAt2 = s_fixture.Create(); - using var sut = new ListPool(3) { expectedAt0, expectedAt1, expectedAt2 }; + using var sut = new ListPool(3) {expectedAt0, expectedAt1, expectedAt2}; Assert.Equal(expectedAt0, sut[0]); Assert.Equal(expectedAt1, sut[1]); Assert.Equal(expectedAt2, sut[2]); } - [Fact] - public void Create_list_and_add_values_after_clear() + + public override void Create_list_and_add_values_after_clear() { using var sut = new ListPool(3) {s_fixture.Create(), s_fixture.Create(), s_fixture.Create()}; @@ -106,15 +110,15 @@ public void Create_list_and_add_values_after_clear() Assert.Empty(sut); } - [Fact] - public void Create_without_parameters_should_add_and_get_items() + + public override void Create_without_parameters_should_add_and_get_items() { const int expectedItemsCount = 3; int expectedAt0 = s_fixture.Create(); int expectedAt1 = s_fixture.Create(); int expectedAt2 = s_fixture.Create(); - using var sut = new ListPool { expectedAt0, expectedAt1, expectedAt2 }; + using var sut = new ListPool {expectedAt0, expectedAt1, expectedAt2}; Assert.Equal(expectedAt0, sut[0]); Assert.Equal(expectedAt1, sut[1]); @@ -122,8 +126,18 @@ public void Create_without_parameters_should_add_and_get_items() Assert.Equal(expectedItemsCount, sut.Count); } - [Fact] - public void Get_item_with_index_above_itemsCount_throws_ArgumentOutOfRangeException() + + public override void Enumerate_when_capacity_is_not_set_dont_throw_exception() + { + using var sut = new ListPool(); + + foreach (int _ in sut) + { + } + } + + + public override void Get_item_with_index_above_itemsCount_throws_ArgumentOutOfRangeException() { const int index = 2; using var sut = new ListPool {s_fixture.Create()}; @@ -133,8 +147,8 @@ public void Get_item_with_index_above_itemsCount_throws_ArgumentOutOfRangeExcept Assert.Equal(nameof(index), exception.ParamName); } - [Fact] - public void Get_item_with_index_bellow_zero_throws_ArgumentOutOfRangeException() + + public override void Get_item_with_index_bellow_zero_throws_ArgumentOutOfRangeException() { int index = -1; var sut = new ListPool(); @@ -144,8 +158,20 @@ public void Get_item_with_index_bellow_zero_throws_ArgumentOutOfRangeException() Assert.Equal(nameof(index), exception.ParamName); } - [Fact] - public void IndexOf_returns_index_of_item() + + public override void IndexOf_empty_ListPool_without_indicating_capacity_returns_negative_one() + { + int randomItem = s_fixture.Create(); + const int expected = -1; + using var sut = new ListPool(); + + int actual = sut.IndexOf(randomItem); + + Assert.Equal(expected, actual); + } + + + public override void IndexOf_returns_index_of_item() { int expectedAt0 = s_fixture.Create(); int expectedAt1 = s_fixture.Create(); @@ -157,8 +183,8 @@ public void IndexOf_returns_index_of_item() Assert.Equal(2, sut.IndexOf(expectedAt2)); } - [Fact] - public void Insert_at_existing_index_move_items_up() + + public override void Insert_at_existing_index_move_items_up() { int[] expectedItems = s_fixture.CreateMany(3).ToArray(); int expectedItemAt1 = s_fixture.Create(); @@ -174,8 +200,8 @@ public void Insert_at_existing_index_move_items_up() Assert.Equal(expectedItems[2], sut[3]); } - [Fact] - public void Insert_at_the_end_add_new_item() + + public override void Insert_at_the_end_add_new_item() { int expectedAt3 = s_fixture.Create(); using var sut = @@ -187,32 +213,34 @@ public void Insert_at_the_end_add_new_item() Assert.Equal(expectedAt3, sut[3]); } - [Fact] - public void Insert_item_with_index_above_itemsCount_throws_ArgumentOutOfRangeException() + + public override void Insert_item_with_index_above_itemsCount_throws_ArgumentOutOfRangeException() { const int index = 2; using var sut = new ListPool {s_fixture.Create()}; int item = s_fixture.Create(); - ArgumentOutOfRangeException exception = Assert.Throws(() => sut.Insert(index, item)); + ArgumentOutOfRangeException exception = + Assert.Throws(() => sut.Insert(index, item)); Assert.Equal(nameof(index), exception.ParamName); } - [Fact] - public void Insert_item_with_index_bellow_zero_throws_ArgumentOutOfRangeException() + + public override void Insert_item_with_index_bellow_zero_throws_ArgumentOutOfRangeException() { const int index = -1; int item = s_fixture.Create(); using var sut = new ListPool(); - ArgumentOutOfRangeException exception = Assert.Throws(() => sut.Insert(index, item)); + ArgumentOutOfRangeException exception = + Assert.Throws(() => sut.Insert(index, item)); Assert.Equal(nameof(index), exception.ParamName); } - [Fact] - public void Insert_items_when_capacity_is_full_then_buffer_autogrow() + + public override void Insert_items_when_capacity_is_full_then_buffer_autogrow() { using var sut = new ListPool(128); var expectedItems = s_fixture.CreateMany(sut.Capacity * 2).ToList(); @@ -227,8 +255,8 @@ public void Insert_items_when_capacity_is_full_then_buffer_autogrow() Assert.True(expectedItems.All(expectedItem => sut.Contains(expectedItem))); } - [Fact] - public void Insert_without_indicating_capacity_of_list() + + public override void Insert_without_indicating_capacity_of_list() { const int index = 0; int expectedItem = s_fixture.Create(); @@ -239,16 +267,16 @@ public void Insert_without_indicating_capacity_of_list() Assert.Equal(expectedItem, sut[0]); } - [Fact] - public void Readonly_property_is_always_false() + + public override void Readonly_property_is_always_false() { using var sut = new ListPool(); Assert.False(sut.IsReadOnly); } - [Fact] - public void Remove_item_that_doesnt_exists_return_false() + + public override void Remove_item_that_doesnt_exists_return_false() { string item = s_fixture.Create(); using var sut = new ListPool {s_fixture.Create()}; @@ -257,12 +285,12 @@ public void Remove_item_that_doesnt_exists_return_false() Assert.Single(sut); } - [Fact] - public void Remove_when_item_exists_remove_item_and_decrease_itemsCount() + + public override void Remove_when_item_exists_remove_item_and_decrease_itemsCount() { const int expectedCountAfterRemove = 2; int expectedAt0 = s_fixture.Create(); - using var sut = new ListPool(3) { expectedAt0, s_fixture.Create(), s_fixture.Create() }; + using var sut = new ListPool(3) {expectedAt0, s_fixture.Create(), s_fixture.Create()}; bool wasRemoved = sut.Remove(expectedAt0); @@ -271,8 +299,8 @@ public void Remove_when_item_exists_remove_item_and_decrease_itemsCount() Assert.Equal(expectedCountAfterRemove, sut.Count); } - [Fact] - public void Remove_when_item_is_null_return_false() + + public override void Remove_when_item_is_null_return_false() { string item = null; using var sut = new ListPool(); @@ -280,12 +308,12 @@ public void Remove_when_item_is_null_return_false() Assert.False(sut.Remove(item)); } - [Fact] - public void RemoveAt_when_item_exists_remove_item_and_decrease_itemsCount() + + public override void RemoveAt_when_item_exists_remove_item_and_decrease_itemsCount() { const int expectedCountAfterRemove = 2; int expectedAt1 = s_fixture.Create(); - using var sut = new ListPool(3) { s_fixture.Create(), expectedAt1, s_fixture.Create() }; + using var sut = new ListPool(3) {s_fixture.Create(), expectedAt1, s_fixture.Create()}; sut.RemoveAt(1); @@ -293,41 +321,44 @@ public void RemoveAt_when_item_exists_remove_item_and_decrease_itemsCount() Assert.Equal(expectedCountAfterRemove, sut.Count); } - [Fact] - public void RemoveAt_with_index_above_itemsCount_throws_ArgumentOutOfRangeException() + + public override void RemoveAt_with_index_above_itemsCount_throws_ArgumentOutOfRangeException() { const int index = 2; - using var sut = new ListPool { s_fixture.Create() }; + using var sut = new ListPool {s_fixture.Create()}; - ArgumentOutOfRangeException exception = Assert.Throws(() => sut.RemoveAt(index)); + ArgumentOutOfRangeException exception = + Assert.Throws(() => sut.RemoveAt(index)); Assert.Equal(nameof(index), exception.ParamName); } - [Fact] - public void RemoveAt_with_index_bellow_zero_throws_ArgumentOutOfRangeException() + + public override void RemoveAt_with_index_bellow_zero_throws_ArgumentOutOfRangeException() { const int index = -1; using var sut = new ListPool(); - ArgumentOutOfRangeException exception = Assert.Throws(() => sut.RemoveAt(index)); + ArgumentOutOfRangeException exception = + Assert.Throws(() => sut.RemoveAt(index)); Assert.Equal(nameof(index), exception.ParamName); } - [Fact] - public void RemoveAt_with_index_zero_when_not_item_added_throws_ArgumentOutOfRangeException() + + public override void RemoveAt_with_index_zero_when_not_item_added_throws_ArgumentOutOfRangeException() { const int index = 0; using var sut = new ListPool(); - ArgumentOutOfRangeException exception = Assert.Throws(() => sut.RemoveAt(index)); + ArgumentOutOfRangeException exception = + Assert.Throws(() => sut.RemoveAt(index)); Assert.Equal(nameof(index), exception.ParamName); } - [Fact] - public void Set_at_existing_index_update_item() + + public override void Set_at_existing_index_update_item() { const int expectedItemsCount = 3; int expectedItem = s_fixture.Create(); @@ -340,8 +371,8 @@ public void Set_at_existing_index_update_item() Assert.Equal(expectedItem, sut[2]); } - [Fact] - public void Set_item_with_index_above_itemsCount_throws_ArgumentOutOfRangeException() + + public override void Set_item_with_index_above_itemsCount_throws_ArgumentOutOfRangeException() { const int index = 2; using var sut = new ListPool {s_fixture.Create()}; @@ -352,8 +383,8 @@ public void Set_item_with_index_above_itemsCount_throws_ArgumentOutOfRangeExcept Assert.Equal(nameof(index), exception.ParamName); } - [Fact] - public void Set_item_with_index_bellow_zero_throws_ArgumentOutOfRangeException() + + public override void Set_item_with_index_bellow_zero_throws_ArgumentOutOfRangeException() { const int index = -1; int item = s_fixture.Create(); @@ -363,39 +394,5 @@ public void Set_item_with_index_bellow_zero_throws_ArgumentOutOfRangeException() Assert.Equal(nameof(index), exception.ParamName); } - - [Fact] - public void Enumerate_when_capacity_is_not_set_dont_throw_exception() - { - using var sut = new ListPool(); - - foreach (int _ in sut) - { - - } - } - - [Fact] - public void IndexOf_empty_ListPool_without_indicating_capacity_returns_negative_one() - { - int randomItem = s_fixture.Create(); - const int expected = -1; - using var sut = new ListPool(); - - int actual = sut.IndexOf(randomItem); - - Assert.Equal(expected, actual); - } - - [Fact] - public void Contains_empty_ListPool_without_indicating_capacity_returns_false() - { - int randomItem = s_fixture.Create(); - using var sut = new ListPool(); - - bool actual = sut.Contains(randomItem); - - Assert.False(actual); - } } } diff --git a/tests/ListPool.UnitTests/ListPoolTestsBase.cs b/tests/ListPool.UnitTests/ListPoolTestsBase.cs new file mode 100644 index 0000000..e3fc672 --- /dev/null +++ b/tests/ListPool.UnitTests/ListPoolTestsBase.cs @@ -0,0 +1,103 @@ +using AutoFixture; +using Xunit; + +namespace ListPool.UnitTests +{ + public abstract class ListPoolTestsBase + { + protected static readonly Fixture s_fixture = new Fixture(); + + [Fact] + public abstract void Add_item_without_indicate_capacity_of_list(); + + [Fact] + public abstract void Add_items_when_capacity_is_full_then_buffer_autogrow(); + + [Fact] + public abstract void Contains_empty_ListPool_without_indicating_capacity_returns_false(); + + [Fact] + public abstract void Contains_return_true_when_item_exists(); + + [Fact] + public abstract void CopyTo_copy_all_elements_to_target_array(); + + [Fact] + public abstract void Count_property_is_for_items_Added_count_not_capacity_of_buffer(); + + [Fact] + public abstract void Create_list_and_add_values(); + + [Fact] + public abstract void Create_list_and_add_values_after_clear(); + + [Fact] + public abstract void Create_without_parameters_should_add_and_get_items(); + + [Fact] + public abstract void Enumerate_when_capacity_is_not_set_dont_throw_exception(); + + [Fact] + public abstract void Get_item_with_index_above_itemsCount_throws_ArgumentOutOfRangeException(); + + [Fact] + public abstract void Get_item_with_index_bellow_zero_throws_ArgumentOutOfRangeException(); + + [Fact] + public abstract void IndexOf_empty_ListPool_without_indicating_capacity_returns_negative_one(); + + [Fact] + public abstract void IndexOf_returns_index_of_item(); + + [Fact] + public abstract void Insert_at_existing_index_move_items_up(); + + [Fact] + public abstract void Insert_at_the_end_add_new_item(); + + [Fact] + public abstract void Insert_item_with_index_above_itemsCount_throws_ArgumentOutOfRangeException(); + + [Fact] + public abstract void Insert_item_with_index_bellow_zero_throws_ArgumentOutOfRangeException(); + + [Fact] + public abstract void Insert_items_when_capacity_is_full_then_buffer_autogrow(); + + [Fact] + public abstract void Insert_without_indicating_capacity_of_list(); + + [Fact] + public abstract void Readonly_property_is_always_false(); + + [Fact] + public abstract void Remove_item_that_doesnt_exists_return_false(); + + [Fact] + public abstract void Remove_when_item_exists_remove_item_and_decrease_itemsCount(); + + [Fact] + public abstract void Remove_when_item_is_null_return_false(); + + [Fact] + public abstract void RemoveAt_when_item_exists_remove_item_and_decrease_itemsCount(); + + [Fact] + public abstract void RemoveAt_with_index_above_itemsCount_throws_ArgumentOutOfRangeException(); + + [Fact] + public abstract void RemoveAt_with_index_bellow_zero_throws_ArgumentOutOfRangeException(); + + [Fact] + public abstract void RemoveAt_with_index_zero_when_not_item_added_throws_ArgumentOutOfRangeException(); + + [Fact] + public abstract void Set_at_existing_index_update_item(); + + [Fact] + public abstract void Set_item_with_index_above_itemsCount_throws_ArgumentOutOfRangeException(); + + [Fact] + public abstract void Set_item_with_index_bellow_zero_throws_ArgumentOutOfRangeException(); + } +} diff --git a/tests/ListPool.UnitTests/coverage.json b/tests/ListPool.UnitTests/coverage.json index 729fe27..d06646e 100644 --- a/tests/ListPool.UnitTests/coverage.json +++ b/tests/ListPool.UnitTests/coverage.json @@ -1,675 +1,677 @@ { - "ListPool.dll": { - "C:\\Users\\fsuarez\\source\\repos\\ListPool\\src\\ListPool\\BufferOwner.cs": { - "ListPool.BufferOwner`1": { - "System.Void ListPool.BufferOwner`1::GrowDoubleSize()": { - "Lines": { - "22": 2, - "23": 2, - "24": 2, - "25": 2, - "27": 2, - "29": 2, - "30": 2, - "31": 2 - }, - "Branches": [] - }, - "System.Void ListPool.BufferOwner`1::Dispose()": { - "Lines": { - "34": 23, - "35": 23, - "36": 23, - "37": 23 - }, - "Branches": [] - }, - "System.Void ListPool.BufferOwner`1::.ctor(System.Int32)": { - "Lines": { - "14": 23, - "15": 23, - "16": 23, - "17": 23, - "18": 23 - }, - "Branches": [] - } - } - }, - "C:\\Users\\fsuarez\\source\\repos\\ListPool\\src\\ListPool\\Enumerator.cs": { - "ListPool.Enumerator`1": { - "TSource& modreq(System.Runtime.InteropServices.InAttribute) ListPool.Enumerator`1::get_Current()": { - "Lines": { - "25": 30 - }, - "Branches": [] - }, - "TSource ListPool.Enumerator`1::System.Collections.Generic.IEnumerator.get_Current()": { - "Lines": { - "29": 8 - }, - "Branches": [] - }, - "System.Object ListPool.Enumerator`1::System.Collections.IEnumerator.get_Current()": { - "Lines": { - "31": 0 - }, - "Branches": [] - }, - "System.Boolean ListPool.Enumerator`1::MoveNext()": { - "Lines": { - "35": 45, - "36": 45, - "37": 45 - }, - "Branches": [] - }, - "System.Void ListPool.Enumerator`1::Reset()": { - "Lines": { - "40": 1, - "41": 1, - "42": 1 - }, - "Branches": [] - }, - "System.Void ListPool.Enumerator`1::Dispose()": { - "Lines": { - "45": 6, - "46": 6 - }, - "Branches": [] - }, - "System.Void ListPool.Enumerator`1::.ctor(TSource[]&,System.Int32&)": { - "Lines": { - "15": 8, - "16": 8, - "17": 8, - "18": 8, - "19": 8 - }, - "Branches": [] - } - } - }, - "C:\\Users\\fsuarez\\source\\repos\\ListPool\\src\\ListPool\\ListPool.cs": { - "ListPool.ListPool`1": { - "System.Int32 ListPool.ListPool`1::get_Capacity()": { - "Lines": { - "14": 2 - }, - "Branches": [ - { - "Line": 14, - "Offset": 11, - "EndOffset": 13, - "Path": 0, - "Ordinal": 0, - "Hits": 0 - }, - { - "Line": 14, - "Offset": 11, - "EndOffset": 16, - "Path": 1, - "Ordinal": 1, - "Hits": 2 - } - ] - }, - "System.Int32 ListPool.ListPool`1::get_Count()": { - "Lines": { - "15": 14 - }, - "Branches": [] - }, - "System.Boolean ListPool.ListPool`1::get_IsReadOnly()": { - "Lines": { - "16": 1 - }, - "Branches": [] - }, - "System.Void ListPool.ListPool`1::Add(TSource)": { - "Lines": { - "52": 305, - "53": 312, - "54": 306, - "56": 305, - "57": 305 - }, - "Branches": [ - { - "Line": 53, - "Offset": 17, - "EndOffset": 19, - "Path": 0, - "Ordinal": 0, - "Hits": 7 - }, - { - "Line": 53, - "Offset": 17, - "EndOffset": 35, - "Path": 1, - "Ordinal": 1, - "Hits": 305 - }, - { - "Line": 54, - "Offset": 61, - "EndOffset": 63, - "Path": 0, - "Ordinal": 2, - "Hits": 1 - }, - { - "Line": 54, - "Offset": 61, - "EndOffset": 75, - "Path": 1, - "Ordinal": 3, - "Hits": 305 - } - ] - }, - "System.Void ListPool.ListPool`1::Clear()": { - "Lines": { - "59": 1 - }, - "Branches": [] - }, - "System.Boolean ListPool.ListPool`1::Contains(TSource)": { - "Lines": { - "60": 539 - }, - "Branches": [] - }, - "System.Int32 ListPool.ListPool`1::IndexOf(TSource)": { - "Lines": { - "62": 545 - }, - "Branches": [ - { - "Line": 62, - "Offset": 11, - "EndOffset": 13, - "Path": 0, - "Ordinal": 0, - "Hits": 2 - }, - { - "Line": 62, - "Offset": 11, - "EndOffset": 16, - "Path": 1, - "Ordinal": 1, - "Hits": 543 + "ListPool.dll": { + "C:\\Users\\fsuarez\\source\\repos\\ListPool\\src\\ListPool\\BufferOwner.cs": { + "ListPool.BufferOwner`1": { + "System.Void ListPool.BufferOwner`1::GrowDoubleSize()": { + "Lines": { + "22": 2, + "23": 2, + "24": 2, + "25": 2, + "27": 2, + "29": 2, + "30": 2, + "31": 2 + }, + "Branches": [] + }, + "System.Void ListPool.BufferOwner`1::Dispose()": { + "Lines": { + "34": 23, + "35": 23, + "36": 23, + "37": 23 + }, + "Branches": [] + }, + "System.Void ListPool.BufferOwner`1::.ctor(System.Int32)": { + "Lines": { + "14": 23, + "15": 23, + "16": 23, + "17": 23, + "18": 23 + }, + "Branches": [] + } } - ] - }, - "System.Void ListPool.ListPool`1::CopyTo(TSource[],System.Int32)": { - "Lines": { - "65": 1 - }, - "Branches": [] }, - "System.Boolean ListPool.ListPool`1::Remove(TSource)": { - "Lines": { - "68": 3, - "69": 4, - "71": 2, - "73": 3, - "75": 1, - "77": 1, - "78": 3 - }, - "Branches": [ - { - "Line": 69, - "Offset": 12, - "EndOffset": 14, - "Path": 0, - "Ordinal": 0, - "Hits": 1 - }, - { - "Line": 69, - "Offset": 12, - "EndOffset": 18, - "Path": 1, - "Ordinal": 1, - "Hits": 2 - }, - { - "Line": 73, - "Offset": 32, - "EndOffset": 34, - "Path": 0, - "Ordinal": 2, - "Hits": 1 - }, - { - "Line": 73, - "Offset": 32, - "EndOffset": 38, - "Path": 1, - "Ordinal": 3, - "Hits": 1 + "C:\\Users\\fsuarez\\source\\repos\\ListPool\\src\\ListPool\\Enumerator.cs": { + "ListPool.Enumerator`1": { + "TSource& modreq(System.Runtime.InteropServices.InAttribute) ListPool.Enumerator`1::get_Current()": { + "Lines": { + "25": 30 + }, + "Branches": [] + }, + "TSource ListPool.Enumerator`1::System.Collections.Generic.IEnumerator.get_Current()": { + "Lines": { + "29": 8 + }, + "Branches": [] + }, + "System.Object ListPool.Enumerator`1::System.Collections.IEnumerator.get_Current()": { + "Lines": { + "31": 0 + }, + "Branches": [] + }, + "System.Boolean ListPool.Enumerator`1::MoveNext()": { + "Lines": { + "35": 45, + "36": 45, + "37": 45 + }, + "Branches": [] + }, + "System.Void ListPool.Enumerator`1::Reset()": { + "Lines": { + "40": 1, + "41": 1, + "42": 1 + }, + "Branches": [] + }, + "System.Void ListPool.Enumerator`1::Dispose()": { + "Lines": { + "45": 6, + "46": 6 + }, + "Branches": [] + }, + "System.Void ListPool.Enumerator`1::.ctor(TSource[]&,System.Int32&)": { + "Lines": { + "15": 8, + "16": 8, + "17": 8, + "18": 8, + "19": 8 + }, + "Branches": [] + } } - ] }, - "System.Void ListPool.ListPool`1::Insert(System.Int32,TSource)": { - "Lines": { - "82": 261, - "83": 263, - "84": 260, - "85": 260, - "86": 259, - "87": 1, - "89": 259, - "90": 259, - "91": 259 - }, - "Branches": [ - { - "Line": 83, - "Offset": 3, - "EndOffset": 5, - "Path": 0, - "Ordinal": 0, - "Hits": 260 - }, - { - "Line": 83, - "Offset": 3, - "EndOffset": 16, - "Path": 1, - "Ordinal": 1, - "Hits": 1 - }, - { - "Line": 83, - "Offset": 19, - "EndOffset": 21, - "Path": 0, - "Ordinal": 2, - "Hits": 2 - }, - { - "Line": 83, - "Offset": 19, - "EndOffset": 32, - "Path": 1, - "Ordinal": 3, - "Hits": 259 - }, - { - "Line": 84, - "Offset": 48, - "EndOffset": 50, - "Path": 0, - "Ordinal": 4, - "Hits": 1 - }, - { - "Line": 84, - "Offset": 48, - "EndOffset": 66, - "Path": 1, - "Ordinal": 5, - "Hits": 259 - }, - { - "Line": 85, - "Offset": 87, - "EndOffset": 89, - "Path": 0, - "Ordinal": 6, - "Hits": 1 - }, - { - "Line": 85, - "Offset": 87, - "EndOffset": 101, - "Path": 1, - "Ordinal": 7, - "Hits": 259 - }, - { - "Line": 86, - "Offset": 112, - "EndOffset": 114, - "Path": 0, - "Ordinal": 8, - "Hits": 1 - }, - { - "Line": 86, - "Offset": 112, - "EndOffset": 154, - "Path": 1, - "Ordinal": 9, - "Hits": 259 + "C:\\Users\\fsuarez\\source\\repos\\ListPool\\src\\ListPool\\ListPool.cs": { + "ListPool.ListPool`1": { + "System.Int32 ListPool.ListPool`1::get_Capacity()": { + "Lines": { + "14": 2 + }, + "Branches": [ + { + "Line": 14, + "Offset": 11, + "EndOffset": 13, + "Path": 0, + "Ordinal": 0, + "Hits": 0 + }, + { + "Line": 14, + "Offset": 11, + "EndOffset": 16, + "Path": 1, + "Ordinal": 1, + "Hits": 2 + } + ] + }, + "System.Int32 ListPool.ListPool`1::get_Count()": { + "Lines": { + "15": 14 + }, + "Branches": [] + }, + "System.Boolean ListPool.ListPool`1::get_IsReadOnly()": { + "Lines": { + "16": 1 + }, + "Branches": [] + }, + "System.Void ListPool.ListPool`1::Add(TSource)": { + "Lines": { + "52": 305, + "53": 312, + "54": 306, + "56": 305, + "57": 305 + }, + "Branches": [ + { + "Line": 53, + "Offset": 17, + "EndOffset": 19, + "Path": 0, + "Ordinal": 0, + "Hits": 7 + }, + { + "Line": 53, + "Offset": 17, + "EndOffset": 35, + "Path": 1, + "Ordinal": 1, + "Hits": 305 + }, + { + "Line": 54, + "Offset": 61, + "EndOffset": 63, + "Path": 0, + "Ordinal": 2, + "Hits": 1 + }, + { + "Line": 54, + "Offset": 61, + "EndOffset": 75, + "Path": 1, + "Ordinal": 3, + "Hits": 305 + } + ] + }, + "System.Void ListPool.ListPool`1::Clear()": { + "Lines": { + "59": 1 + }, + "Branches": [] + }, + "System.Boolean ListPool.ListPool`1::Contains(TSource)": { + "Lines": { + "60": 539 + }, + "Branches": [] + }, + "System.Int32 ListPool.ListPool`1::IndexOf(TSource)": { + "Lines": { + "62": 545 + }, + "Branches": [ + { + "Line": 62, + "Offset": 11, + "EndOffset": 13, + "Path": 0, + "Ordinal": 0, + "Hits": 2 + }, + { + "Line": 62, + "Offset": 11, + "EndOffset": 16, + "Path": 1, + "Ordinal": 1, + "Hits": 543 + } + ] + }, + "System.Void ListPool.ListPool`1::CopyTo(TSource[],System.Int32)": { + "Lines": { + "65": 1 + }, + "Branches": [] + }, + "System.Boolean ListPool.ListPool`1::Remove(TSource)": { + "Lines": { + "68": 3, + "69": 4, + "71": 2, + "73": 3, + "75": 1, + "77": 1, + "78": 3 + }, + "Branches": [ + { + "Line": 69, + "Offset": 12, + "EndOffset": 14, + "Path": 0, + "Ordinal": 0, + "Hits": 1 + }, + { + "Line": 69, + "Offset": 12, + "EndOffset": 18, + "Path": 1, + "Ordinal": 1, + "Hits": 2 + }, + { + "Line": 73, + "Offset": 32, + "EndOffset": 34, + "Path": 0, + "Ordinal": 2, + "Hits": 1 + }, + { + "Line": 73, + "Offset": 32, + "EndOffset": 38, + "Path": 1, + "Ordinal": 3, + "Hits": 1 + } + ] + }, + "System.Void ListPool.ListPool`1::Insert(System.Int32,TSource)": { + "Lines": { + "82": 261, + "83": 263, + "84": 260, + "85": 260, + "86": 259, + "87": 1, + "89": 259, + "90": 259, + "91": 259 + }, + "Branches": [ + { + "Line": 83, + "Offset": 3, + "EndOffset": 5, + "Path": 0, + "Ordinal": 0, + "Hits": 260 + }, + { + "Line": 83, + "Offset": 3, + "EndOffset": 16, + "Path": 1, + "Ordinal": 1, + "Hits": 1 + }, + { + "Line": 83, + "Offset": 19, + "EndOffset": 21, + "Path": 0, + "Ordinal": 2, + "Hits": 2 + }, + { + "Line": 83, + "Offset": 19, + "EndOffset": 32, + "Path": 1, + "Ordinal": 3, + "Hits": 259 + }, + { + "Line": 84, + "Offset": 48, + "EndOffset": 50, + "Path": 0, + "Ordinal": 4, + "Hits": 1 + }, + { + "Line": 84, + "Offset": 48, + "EndOffset": 66, + "Path": 1, + "Ordinal": 5, + "Hits": 259 + }, + { + "Line": 85, + "Offset": 87, + "EndOffset": 89, + "Path": 0, + "Ordinal": 6, + "Hits": 1 + }, + { + "Line": 85, + "Offset": 87, + "EndOffset": 101, + "Path": 1, + "Ordinal": 7, + "Hits": 259 + }, + { + "Line": 86, + "Offset": 112, + "EndOffset": 114, + "Path": 0, + "Ordinal": 8, + "Hits": 1 + }, + { + "Line": 86, + "Offset": 112, + "EndOffset": 154, + "Path": 1, + "Ordinal": 9, + "Hits": 259 + } + ] + }, + "System.Void ListPool.ListPool`1::RemoveAt(System.Int32)": { + "Lines": { + "94": 5, + "95": 8, + "97": 2, + "98": 2, + "99": 2 + }, + "Branches": [ + { + "Line": 95, + "Offset": 3, + "EndOffset": 5, + "Path": 0, + "Ordinal": 0, + "Hits": 4 + }, + { + "Line": 95, + "Offset": 3, + "EndOffset": 19, + "Path": 1, + "Ordinal": 1, + "Hits": 1 + }, + { + "Line": 95, + "Offset": 22, + "EndOffset": 24, + "Path": 0, + "Ordinal": 2, + "Hits": 3 + }, + { + "Line": 95, + "Offset": 22, + "EndOffset": 35, + "Path": 1, + "Ordinal": 3, + "Hits": 2 + } + ] + }, + "TSource ListPool.ListPool`1::get_Item(System.Int32)": { + "Lines": { + "107": 16, + "108": 16, + "109": 2, + "111": 14, + "112": 14 + }, + "Branches": [ + { + "Line": 108, + "Offset": 3, + "EndOffset": 5, + "Path": 0, + "Ordinal": 0, + "Hits": 15 + }, + { + "Line": 108, + "Offset": 19, + "EndOffset": 21, + "Path": 0, + "Ordinal": 2, + "Hits": 15 + }, + { + "Line": 108, + "Offset": 3, + "EndOffset": 35, + "Path": 1, + "Ordinal": 1, + "Hits": 1 + }, + { + "Line": 108, + "Offset": 19, + "EndOffset": 35, + "Path": 1, + "Ordinal": 3, + "Hits": 1 + }, + { + "Line": 108, + "Offset": 38, + "EndOffset": 40, + "Path": 0, + "Ordinal": 4, + "Hits": 2 + }, + { + "Line": 108, + "Offset": 38, + "EndOffset": 51, + "Path": 1, + "Ordinal": 5, + "Hits": 14 + } + ] + }, + "System.Void ListPool.ListPool`1::set_Item(System.Int32,TSource)": { + "Lines": { + "115": 3, + "116": 3, + "117": 2, + "119": 1, + "120": 1 + }, + "Branches": [ + { + "Line": 116, + "Offset": 3, + "EndOffset": 5, + "Path": 0, + "Ordinal": 0, + "Hits": 2 + }, + { + "Line": 116, + "Offset": 19, + "EndOffset": 21, + "Path": 0, + "Ordinal": 2, + "Hits": 2 + }, + { + "Line": 116, + "Offset": 3, + "EndOffset": 35, + "Path": 1, + "Ordinal": 1, + "Hits": 1 + }, + { + "Line": 116, + "Offset": 19, + "EndOffset": 35, + "Path": 1, + "Ordinal": 3, + "Hits": 1 + }, + { + "Line": 116, + "Offset": 38, + "EndOffset": 40, + "Path": 0, + "Ordinal": 4, + "Hits": 2 + }, + { + "Line": 116, + "Offset": 38, + "EndOffset": 51, + "Path": 1, + "Ordinal": 5, + "Hits": 1 + } + ] + }, + "ListPool.Enumerator`1 ListPool.ListPool`1::GetEnumerator()": { + "Lines": { + "126": 6 + }, + "Branches": [] + }, + "System.Collections.Generic.IEnumerator`1 ListPool.ListPool`1::System.Collections.Generic.IEnumerable.GetEnumerator()": + { + "Lines": { + "128": 4 + }, + "Branches": [] + }, + "System.Collections.IEnumerator ListPool.ListPool`1::System.Collections.IEnumerable.GetEnumerator()": { + "Lines": { + "130": 1 + }, + "Branches": [] + }, + "System.Void ListPool.ListPool`1::Dispose()": { + "Lines": { + "133": 31, + "134": 31, + "135": 31, + "136": 23, + "137": 31 + }, + "Branches": [ + { + "Line": 135, + "Offset": 21, + "EndOffset": 23, + "Path": 0, + "Ordinal": 0, + "Hits": 23 + }, + { + "Line": 135, + "Offset": 21, + "EndOffset": 35, + "Path": 1, + "Ordinal": 1, + "Hits": 31 + } + ] + }, + "System.Void ListPool.ListPool`1::.ctor(System.Int32)": { + "Lines": { + "23": 12, + "24": 12, + "25": 12, + "26": 12 + }, + "Branches": [ + { + "Line": 24, + "Offset": 8, + "EndOffset": 10, + "Path": 0, + "Ordinal": 0, + "Hits": 2 + }, + { + "Line": 24, + "Offset": 8, + "EndOffset": 13, + "Path": 1, + "Ordinal": 1, + "Hits": 10 + } + ] + }, + "System.Void ListPool.ListPool`1::.ctor(System.Collections.Generic.IEnumerable`1)": { + "Lines": { + "29": 3, + "30": 3, + "31": 2, + "32": 2, + "33": 2, + "35": 2, + "36": 2, + "38": 1, + "39": 1, + "40": 1, + "42": 1, + "43": 11, + "44": 10, + "45": 10, + "46": 10, + "47": 1, + "48": 3 + }, + "Branches": [ + { + "Line": 30, + "Offset": 14, + "EndOffset": 16, + "Path": 0, + "Ordinal": 0, + "Hits": 2 + }, + { + "Line": 30, + "Offset": 14, + "EndOffset": 68, + "Path": 1, + "Ordinal": 1, + "Hits": 1 + }, + { + "Line": 43, + "Offset": 124, + "EndOffset": 101, + "Path": 1, + "Ordinal": 3, + "Hits": 10 + }, + { + "Line": 43, + "Offset": 124, + "EndOffset": 126, + "Path": 0, + "Ordinal": 2, + "Hits": 1 + } + ] + } } - ] - }, - "System.Void ListPool.ListPool`1::RemoveAt(System.Int32)": { - "Lines": { - "94": 5, - "95": 8, - "97": 2, - "98": 2, - "99": 2 - }, - "Branches": [ - { - "Line": 95, - "Offset": 3, - "EndOffset": 5, - "Path": 0, - "Ordinal": 0, - "Hits": 4 - }, - { - "Line": 95, - "Offset": 3, - "EndOffset": 19, - "Path": 1, - "Ordinal": 1, - "Hits": 1 - }, - { - "Line": 95, - "Offset": 22, - "EndOffset": 24, - "Path": 0, - "Ordinal": 2, - "Hits": 3 - }, - { - "Line": 95, - "Offset": 22, - "EndOffset": 35, - "Path": 1, - "Ordinal": 3, - "Hits": 2 - } - ] - }, - "TSource ListPool.ListPool`1::get_Item(System.Int32)": { - "Lines": { - "107": 16, - "108": 16, - "109": 2, - "111": 14, - "112": 14 - }, - "Branches": [ - { - "Line": 108, - "Offset": 3, - "EndOffset": 5, - "Path": 0, - "Ordinal": 0, - "Hits": 15 - }, - { - "Line": 108, - "Offset": 19, - "EndOffset": 21, - "Path": 0, - "Ordinal": 2, - "Hits": 15 - }, - { - "Line": 108, - "Offset": 3, - "EndOffset": 35, - "Path": 1, - "Ordinal": 1, - "Hits": 1 - }, - { - "Line": 108, - "Offset": 19, - "EndOffset": 35, - "Path": 1, - "Ordinal": 3, - "Hits": 1 - }, - { - "Line": 108, - "Offset": 38, - "EndOffset": 40, - "Path": 0, - "Ordinal": 4, - "Hits": 2 - }, - { - "Line": 108, - "Offset": 38, - "EndOffset": 51, - "Path": 1, - "Ordinal": 5, - "Hits": 14 - } - ] - }, - "System.Void ListPool.ListPool`1::set_Item(System.Int32,TSource)": { - "Lines": { - "115": 3, - "116": 3, - "117": 2, - "119": 1, - "120": 1 - }, - "Branches": [ - { - "Line": 116, - "Offset": 3, - "EndOffset": 5, - "Path": 0, - "Ordinal": 0, - "Hits": 2 - }, - { - "Line": 116, - "Offset": 19, - "EndOffset": 21, - "Path": 0, - "Ordinal": 2, - "Hits": 2 - }, - { - "Line": 116, - "Offset": 3, - "EndOffset": 35, - "Path": 1, - "Ordinal": 1, - "Hits": 1 - }, - { - "Line": 116, - "Offset": 19, - "EndOffset": 35, - "Path": 1, - "Ordinal": 3, - "Hits": 1 - }, - { - "Line": 116, - "Offset": 38, - "EndOffset": 40, - "Path": 0, - "Ordinal": 4, - "Hits": 2 - }, - { - "Line": 116, - "Offset": 38, - "EndOffset": 51, - "Path": 1, - "Ordinal": 5, - "Hits": 1 - } - ] - }, - "ListPool.Enumerator`1 ListPool.ListPool`1::GetEnumerator()": { - "Lines": { - "126": 6 - }, - "Branches": [] }, - "System.Collections.Generic.IEnumerator`1 ListPool.ListPool`1::System.Collections.Generic.IEnumerable.GetEnumerator()": { - "Lines": { - "128": 4 - }, - "Branches": [] - }, - "System.Collections.IEnumerator ListPool.ListPool`1::System.Collections.IEnumerable.GetEnumerator()": { - "Lines": { - "130": 1 - }, - "Branches": [] - }, - "System.Void ListPool.ListPool`1::Dispose()": { - "Lines": { - "133": 31, - "134": 31, - "135": 31, - "136": 23, - "137": 31 - }, - "Branches": [ - { - "Line": 135, - "Offset": 21, - "EndOffset": 23, - "Path": 0, - "Ordinal": 0, - "Hits": 23 - }, - { - "Line": 135, - "Offset": 21, - "EndOffset": 35, - "Path": 1, - "Ordinal": 1, - "Hits": 31 - } - ] - }, - "System.Void ListPool.ListPool`1::.ctor(System.Int32)": { - "Lines": { - "23": 12, - "24": 12, - "25": 12, - "26": 12 - }, - "Branches": [ - { - "Line": 24, - "Offset": 8, - "EndOffset": 10, - "Path": 0, - "Ordinal": 0, - "Hits": 2 - }, - { - "Line": 24, - "Offset": 8, - "EndOffset": 13, - "Path": 1, - "Ordinal": 1, - "Hits": 10 - } - ] - }, - "System.Void ListPool.ListPool`1::.ctor(System.Collections.Generic.IEnumerable`1)": { - "Lines": { - "29": 3, - "30": 3, - "31": 2, - "32": 2, - "33": 2, - "35": 2, - "36": 2, - "38": 1, - "39": 1, - "40": 1, - "42": 1, - "43": 11, - "44": 10, - "45": 10, - "46": 10, - "47": 1, - "48": 3 - }, - "Branches": [ - { - "Line": 30, - "Offset": 14, - "EndOffset": 16, - "Path": 0, - "Ordinal": 0, - "Hits": 2 - }, - { - "Line": 30, - "Offset": 14, - "EndOffset": 68, - "Path": 1, - "Ordinal": 1, - "Hits": 1 - }, - { - "Line": 43, - "Offset": 124, - "EndOffset": 101, - "Path": 1, - "Ordinal": 3, - "Hits": 10 - }, - { - "Line": 43, - "Offset": 124, - "EndOffset": 126, - "Path": 0, - "Ordinal": 2, - "Hits": 1 - } - ] - } - } - }, - "C:\\Users\\fsuarez\\source\\repos\\ListPool\\src\\ListPool\\ListPoolExtensions.cs": { - "ListPool.ListPoolExtensions": { - "ListPool.ListPool`1 ListPool.ListPoolExtensions::ToListPool(System.Collections.Generic.IEnumerable`1)": { - "Lines": { - "9": 4, - "10": 5, - "11": 3, - "12": 3 - }, - "Branches": [ - { - "Line": 10, - "Offset": 7, - "EndOffset": 9, - "Path": 0, - "Ordinal": 0, - "Hits": 1 - }, - { - "Line": 10, - "Offset": 7, - "EndOffset": 20, - "Path": 1, - "Ordinal": 1, - "Hits": 3 + "C:\\Users\\fsuarez\\source\\repos\\ListPool\\src\\ListPool\\ListPoolExtensions.cs": { + "ListPool.ListPoolExtensions": { + "ListPool.ListPool`1 ListPool.ListPoolExtensions::ToListPool(System.Collections.Generic.IEnumerable`1)": + { + "Lines": { + "9": 4, + "10": 5, + "11": 3, + "12": 3 + }, + "Branches": [ + { + "Line": 10, + "Offset": 7, + "EndOffset": 9, + "Path": 0, + "Ordinal": 0, + "Hits": 1 + }, + { + "Line": 10, + "Offset": 7, + "EndOffset": 20, + "Path": 1, + "Ordinal": 1, + "Hits": 3 + } + ] + } } - ] } - } } - } -} \ No newline at end of file +}