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..dd58178 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() { diff --git a/tests/ListPool.UnitTests/ListPoolAsIList.cs b/tests/ListPool.UnitTests/ListPoolAsIList.cs new file mode 100644 index 0000000..51f5a73 --- /dev/null +++ b/tests/ListPool.UnitTests/ListPoolAsIList.cs @@ -0,0 +1,527 @@ +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))); + } + + [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 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 SyncRoot_never_is_null() + { + using var listPool = new ListPool(); + IList sut = listPool; + + Assert.NotNull(sut.SyncRoot); + } + + 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 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 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 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 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); + } + } +} 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(); + } +}