RecyclableList.Insert fixed to allow inserting at the end.

This commit is contained in:
mlemanczyk committed 2023-08-05 22:29:57 +02:00
1 parent a6adeff9e5
commit 4d680ee453
2 files changed
+16 -1

No files matched your search

+1 -1
View File
@@ -385,7 +385,7 @@ namespace Recyclable.Collections
_capacity = RecyclableListHelpers<T>.ResizeAndCopy(this, checked((int)BitOperations.RoundUpToPowerOf2((uint)oldCount + 1)));
}
if (oldCount > 0)
if (index < oldCount)
{
new Span<T>(_memoryBlock, index, oldCount)
.CopyTo(new Span<T>(_memoryBlock, index + 1, oldCount));
@@ -471,6 +471,21 @@ namespace Recyclable.CollectionsTests
_ = list.Should().ContainInConsecutiveOrder(testData.Reverse());
}
[Theory]
[MemberData(nameof(RecyclableLongListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableLongListTestData))]
public void InsertAtTheEndShouldAppend(string testCase, IEnumerable<long> testData, long itemsCount, int targetBlockSize)
{
// Prepare
using var list = new RecyclableList<long>(testData);
// Act
list.Insert((int)itemsCount, -1);
// Assert
_ = list.Count.Should().Be((int)itemsCount + 1);
_ = list[^1].Should().Be(-1);
}
[Theory]
[MemberData(nameof(RecyclableLongListTestData.SourceDataVariants), MemberType = typeof(RecyclableLongListTestData))]
public void RemoveAtFromTheBeginningShouldSucceed(string testCase, IEnumerable<long> testData, long itemsCount)