Missing capacity parameter added for better performance.
This commit is contained in:
1 parent
79bd17afad
commit
d99ec044a3
2 files changed
+42
-42
No files matched your search
@@ -210,7 +210,7 @@ namespace Recyclable.CollectionsTests
|
||||
public void ClearShouldRemoveAllItems(string testCase, IEnumerable<long> testData, long itemsCount)
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableList<long>(testData);
|
||||
using var list = new RecyclableList<long>(testData, (int)itemsCount);
|
||||
_ = list.Count.Should().Be((int)itemsCount);
|
||||
|
||||
// Act
|
||||
@@ -227,7 +227,7 @@ namespace Recyclable.CollectionsTests
|
||||
public void ConsecutiveDisposeShouldSucceed(string testCase, IEnumerable<long> testData, long itemsCount)
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableList<long>(testData);
|
||||
using var list = new RecyclableList<long>(testData, (int)itemsCount);
|
||||
list.Dispose();
|
||||
|
||||
// Act
|
||||
@@ -239,7 +239,7 @@ namespace Recyclable.CollectionsTests
|
||||
public void ConstructorShouldAcceptDuplicates(string testCase, IEnumerable<long> testData, long itemsCount)
|
||||
{
|
||||
// Act
|
||||
using var list = new RecyclableList<long>(testData.Concat(testData), initialCapacity: (int)itemsCount * 2);
|
||||
using var list = new RecyclableList<long>(testData.Concat(testData), (int)itemsCount * 2);
|
||||
|
||||
// Validate
|
||||
_ = list.Count.Should().Be((int)itemsCount * 2);
|
||||
@@ -251,7 +251,7 @@ namespace Recyclable.CollectionsTests
|
||||
public void ConstructorShouldAddItemsInCorrectOrderWhenSourceIsIEnumerable(string testCase, IEnumerable<long> testData, long itemsCount)
|
||||
{
|
||||
// Act
|
||||
using var list = new RecyclableList<long>(testData);
|
||||
using var list = new RecyclableList<long>(testData, (int)itemsCount);
|
||||
|
||||
// Validate
|
||||
_ = list.Capacity.Should().BeGreaterThanOrEqualTo((int)itemsCount, "when we succeed in taking count without enumerating, then we allocate as much memory as needed, only");
|
||||
@@ -264,7 +264,7 @@ namespace Recyclable.CollectionsTests
|
||||
public void ConstructorSourceShouldInitializeList(string testCase, IEnumerable<long> testData, long itemsCount)
|
||||
{
|
||||
// Act
|
||||
using var list = new RecyclableList<long>(testData);
|
||||
using var list = new RecyclableList<long>(testData, (int)itemsCount);
|
||||
|
||||
// Validate
|
||||
_ = list.Count.Should().Be((int)itemsCount);
|
||||
@@ -281,7 +281,7 @@ namespace Recyclable.CollectionsTests
|
||||
}
|
||||
|
||||
// Prepare
|
||||
using var list = new RecyclableList<long>(testData);
|
||||
using var list = new RecyclableList<long>(testData, (int)itemsCount);
|
||||
_ = testData.Any().Should().BeTrue("we need items on the list that we can look for");
|
||||
|
||||
// Act
|
||||
@@ -313,7 +313,7 @@ namespace Recyclable.CollectionsTests
|
||||
}
|
||||
|
||||
// Prepare
|
||||
using var list = new RecyclableList<long>(testData);
|
||||
using var list = new RecyclableList<long>(testData, (int)itemsCount);
|
||||
_ = testData.Any().Should().BeTrue("we need items on the list that we can look for");
|
||||
|
||||
// Act
|
||||
@@ -332,7 +332,7 @@ namespace Recyclable.CollectionsTests
|
||||
public void CopyToShouldCopyAllItemsInTheCorrectOrder(string testCase, IEnumerable<long> testData, long itemsCount)
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableList<long>(testData);
|
||||
using var list = new RecyclableList<long>(testData, (int)itemsCount);
|
||||
long[] copiedItems = new long[itemsCount];
|
||||
|
||||
// Act
|
||||
@@ -347,7 +347,7 @@ namespace Recyclable.CollectionsTests
|
||||
public void EnumerateShouldYieldAllItemsInCorrectOrder(string testCase, IEnumerable<long> testData, long itemsCount)
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableList<long>(testData);
|
||||
using var list = new RecyclableList<long>(testData, (int)itemsCount);
|
||||
|
||||
// Act
|
||||
var yieldedItems = new List<long>((int)itemsCount);
|
||||
@@ -385,7 +385,7 @@ namespace Recyclable.CollectionsTests
|
||||
}
|
||||
|
||||
// Prepare
|
||||
using var list = new RecyclableList<long>(testData);
|
||||
using var list = new RecyclableList<long>(testData, (int)itemsCount);
|
||||
_ = testData.Any().Should().BeTrue("we need items on the list that we can look for");
|
||||
|
||||
// Act
|
||||
@@ -404,7 +404,7 @@ namespace Recyclable.CollectionsTests
|
||||
public void IndexOfShouldReturnCorrectIndexes(string testCase, IEnumerable<long> testData, long itemsCount)
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableList<long>(testData);
|
||||
using var list = new RecyclableList<long>(testData, (int)itemsCount);
|
||||
|
||||
// Act & Validate
|
||||
foreach (var index in testData)
|
||||
@@ -424,7 +424,7 @@ namespace Recyclable.CollectionsTests
|
||||
}
|
||||
|
||||
// Act
|
||||
using RecyclableList<long> list = new(testData);
|
||||
using RecyclableList<long> list = new(testData, (int)itemsCount);
|
||||
QuickSortExtensions<long>.QuickSort(list);
|
||||
|
||||
// Validate
|
||||
@@ -457,7 +457,7 @@ namespace Recyclable.CollectionsTests
|
||||
public void InsertAtTheBeginningShouldMoveItems(string testCase, IEnumerable<long> testData, long itemsCount)
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableList<long>();
|
||||
using var list = new RecyclableList<long>((int)itemsCount);
|
||||
|
||||
// Act
|
||||
foreach (var item in testData)
|
||||
@@ -492,7 +492,7 @@ namespace Recyclable.CollectionsTests
|
||||
public void RemoveAtFromTheBeginningShouldSucceed(string testCase, IEnumerable<long> testData, long itemsCount)
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableList<long>(testData);
|
||||
using var list = new RecyclableList<long>(testData, (int)itemsCount);
|
||||
|
||||
// Act & Validate
|
||||
for (var deleted = 1; deleted <= itemsCount; deleted++)
|
||||
@@ -514,7 +514,7 @@ namespace Recyclable.CollectionsTests
|
||||
public void RemoveAtFromTheEndShouldSucceed(string testCase, IEnumerable<long> testData, long itemsCount)
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableList<long>(testData);
|
||||
using var list = new RecyclableList<long>(testData, (int)itemsCount);
|
||||
|
||||
// Act & Validate
|
||||
for (var deleted = 1; deleted <= itemsCount; deleted++)
|
||||
@@ -536,7 +536,7 @@ namespace Recyclable.CollectionsTests
|
||||
public void RemoveFromTheBeginningShouldRemoveTheCorrectItem(string testCase, IEnumerable<long> testData, long itemsCount)
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableList<long>(testData);
|
||||
using var list = new RecyclableList<long>(testData, (int)itemsCount);
|
||||
|
||||
// Act & Validate
|
||||
for (var deleted = 1; deleted <= itemsCount; deleted++)
|
||||
@@ -555,7 +555,7 @@ namespace Recyclable.CollectionsTests
|
||||
public void RemoveFromTheEndShouldRemoveTheCorrectItem(string testCase, IEnumerable<long> testData, long itemsCount)
|
||||
{
|
||||
// Act & Validate
|
||||
using var list = new RecyclableList<long>(testData);
|
||||
using var list = new RecyclableList<long>(testData, (int)itemsCount);
|
||||
long deleted = 0;
|
||||
foreach (var item in testData.Reverse())
|
||||
{
|
||||
@@ -574,7 +574,7 @@ namespace Recyclable.CollectionsTests
|
||||
public void VersionedEnumerateShouldYieldAllItemsInCorrectOrder(string testCase, IEnumerable<long> testData, long itemsCount)
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableList<long>(testData);
|
||||
using var list = new RecyclableList<long>(testData, (int)itemsCount);
|
||||
|
||||
// Act
|
||||
var yieldedItems = new List<long>((int)itemsCount);
|
||||
|
||||
@@ -197,7 +197,7 @@ namespace Recyclable.CollectionsTests
|
||||
public void GetByIndexShouldReturnCorrectItem(string testCase, IEnumerable<long> testData, long itemsCount, int targetBlockSize)
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableLongList<long>(testData, minBlockSize: targetBlockSize);
|
||||
using var list = new RecyclableLongList<long>(testData, minBlockSize: targetBlockSize, itemsCount);
|
||||
|
||||
// Act & Validate
|
||||
foreach (var item in testData)
|
||||
@@ -212,7 +212,7 @@ namespace Recyclable.CollectionsTests
|
||||
public void AddShouldAddItemWhenAfterAddRange(string testCase, IEnumerable<long> testData, long itemsCount, int targetBlockSize)
|
||||
{
|
||||
// Act
|
||||
using var list = new RecyclableLongList<long>(minBlockSize: targetBlockSize);
|
||||
using var list = new RecyclableLongList<long>(minBlockSize: targetBlockSize, itemsCount);
|
||||
list.AddRange(testData);
|
||||
foreach (var index in testData)
|
||||
{
|
||||
@@ -230,7 +230,7 @@ namespace Recyclable.CollectionsTests
|
||||
public void ClearShouldRemoveAllItems(string testCase, IEnumerable<long> testData, long itemsCount, int targetBlockSize)
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableLongList<long>(testData, minBlockSize: targetBlockSize, expectedItemsCount: itemsCount);
|
||||
using var list = new RecyclableLongList<long>(testData, minBlockSize: targetBlockSize, itemsCount);
|
||||
_ = list.LongCount.Should().Be(itemsCount);
|
||||
|
||||
// Act
|
||||
@@ -247,7 +247,7 @@ namespace Recyclable.CollectionsTests
|
||||
public void ConsecutiveDisposeShouldSucceed(string testCase, IEnumerable<long> testData, long itemsCount, int targetBlockSize)
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableLongList<long>(testData, minBlockSize: targetBlockSize);
|
||||
using var list = new RecyclableLongList<long>(testData, minBlockSize: targetBlockSize, itemsCount);
|
||||
list.Dispose();
|
||||
|
||||
// Act
|
||||
@@ -262,7 +262,7 @@ namespace Recyclable.CollectionsTests
|
||||
testData = testData.Concat(testData).ToArray();
|
||||
|
||||
// Act
|
||||
using var list = new RecyclableLongList<long>(testData, minBlockSize: targetBlockSize);
|
||||
using var list = new RecyclableLongList<long>(expectedData, minBlockSize: targetBlockSize, itemsCount);
|
||||
|
||||
// Validate
|
||||
_ = list.LongCount.Should().Be(itemsCount * 2);
|
||||
@@ -305,7 +305,7 @@ namespace Recyclable.CollectionsTests
|
||||
return;
|
||||
}
|
||||
|
||||
using var list = new RecyclableLongList<long>(testData, minBlockSize: targetBlockSize);
|
||||
using var list = new RecyclableLongList<long>(testData, minBlockSize: targetBlockSize, itemsCount);
|
||||
_ = testData.Any().Should().BeTrue("we need items on the list that we can look for");
|
||||
|
||||
// Act
|
||||
@@ -321,7 +321,7 @@ namespace Recyclable.CollectionsTests
|
||||
public void ContainsShouldNotFindAnythingWhenListEmpty(long itemsCount, int targetBlockSize)
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableLongList<int>(minBlockSize: targetBlockSize, expectedItemsCount: itemsCount);
|
||||
using var list = new RecyclableLongList<int>(minBlockSize: targetBlockSize, itemsCount);
|
||||
|
||||
// Validate
|
||||
_ = list.Contains(0).Should().BeFalse();
|
||||
@@ -339,7 +339,7 @@ namespace Recyclable.CollectionsTests
|
||||
return;
|
||||
}
|
||||
|
||||
using var list = new RecyclableLongList<long>(testData, minBlockSize: targetBlockSize);
|
||||
using var list = new RecyclableLongList<long>(testData, minBlockSize: targetBlockSize, itemsCount);
|
||||
_ = testData.Any().Should().BeTrue("we need items on the list that we can look for");
|
||||
|
||||
// Act
|
||||
@@ -359,7 +359,7 @@ namespace Recyclable.CollectionsTests
|
||||
public void CopyToShouldCopyAllItemsInTheCorrectOrder(string testCase, IEnumerable<long> testData, long itemsCount, int targetBlockSize)
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableLongList<long>(testData, minBlockSize: targetBlockSize);
|
||||
using var list = new RecyclableLongList<long>(testData, minBlockSize: targetBlockSize, itemsCount);
|
||||
|
||||
// Act
|
||||
var actual = new long[itemsCount];
|
||||
@@ -372,7 +372,7 @@ namespace Recyclable.CollectionsTests
|
||||
public void DisposeShouldSucceed(string testCase, IEnumerable<long> testData, long itemsCount, int targetBlockSize)
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableLongList<long>(testData, minBlockSize: targetBlockSize);
|
||||
using var list = new RecyclableLongList<long>(testData, minBlockSize: targetBlockSize, itemsCount);
|
||||
|
||||
// Act
|
||||
list.Dispose();
|
||||
@@ -387,10 +387,10 @@ namespace Recyclable.CollectionsTests
|
||||
public void EnumerateShouldYieldAllItemsInCorrectOrder(string testCase, IEnumerable<long> testData, long itemsCount, int targetBlockSize)
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableLongList<long>(testData, minBlockSize: targetBlockSize);
|
||||
using var list = new RecyclableLongList<long>(testData, minBlockSize: targetBlockSize, itemsCount);
|
||||
|
||||
// Act
|
||||
var actual = new List<long>();
|
||||
var actual = new List<long>((int)itemsCount);
|
||||
using var enumerator = list.GetEnumerator();
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
@@ -406,10 +406,10 @@ namespace Recyclable.CollectionsTests
|
||||
public void VersionedEnumerateShouldYieldAllItemsInCorrectOrder(string testCase, IEnumerable<long> testData, long itemsCount, int targetBlockSize)
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableLongList<long>(testData, minBlockSize: targetBlockSize);
|
||||
using var list = new RecyclableLongList<long>(testData, minBlockSize: targetBlockSize, itemsCount);
|
||||
|
||||
// Act
|
||||
var actual = new List<long>();
|
||||
var actual = new List<long>((int)itemsCount);
|
||||
foreach(var item in (IRecyclableVersionedLongList<long>)list)
|
||||
{
|
||||
actual.Add(item);
|
||||
@@ -442,7 +442,7 @@ namespace Recyclable.CollectionsTests
|
||||
}
|
||||
|
||||
// Prepare
|
||||
using var list = new RecyclableLongList<long>(testData, minBlockSize: targetBlockSize);
|
||||
using var list = new RecyclableLongList<long>(testData, minBlockSize: targetBlockSize, itemsCount);
|
||||
_ = testData.Any().Should().BeTrue("we need items on the list that we can look for");
|
||||
|
||||
// Act
|
||||
@@ -461,7 +461,7 @@ namespace Recyclable.CollectionsTests
|
||||
public void IndexOfShouldReturnCorrectIndexes(string testCase, IEnumerable<long> testData, long itemsCount, int targetBlockSize)
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableLongList<long>(testData, minBlockSize: targetBlockSize);
|
||||
using var list = new RecyclableLongList<long>(testData, minBlockSize: targetBlockSize, itemsCount);
|
||||
|
||||
// Act & Validate
|
||||
foreach (var item in testData)
|
||||
@@ -481,7 +481,7 @@ namespace Recyclable.CollectionsTests
|
||||
}
|
||||
|
||||
// Act
|
||||
using RecyclableLongList<long> list = new(testData, minBlockSize: targetBlockSize);
|
||||
using RecyclableLongList<long> list = new(testData, minBlockSize: targetBlockSize, itemsCount);
|
||||
QuickSortExtensions<long>.QuickSort(list);
|
||||
|
||||
// Validate
|
||||
@@ -514,7 +514,7 @@ namespace Recyclable.CollectionsTests
|
||||
public void InsertAtTheBeginningShouldMoveItems(string testCase, IEnumerable<long> testData, long itemsCount, int targetBlockSize)
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableLongList<long>();
|
||||
using var list = new RecyclableLongList<long>(testData, targetBlockSize, itemsCount);
|
||||
|
||||
// Act
|
||||
foreach (var item in testData)
|
||||
@@ -566,7 +566,7 @@ namespace Recyclable.CollectionsTests
|
||||
}
|
||||
|
||||
// Prepare
|
||||
using var list = new RecyclableLongList<long>(testData, minBlockSize: targetBlockSize);
|
||||
using var list = new RecyclableLongList<long>(testData, minBlockSize: targetBlockSize, itemsCount);
|
||||
_ = testData.Any().Should().BeTrue("we need items on the list that we can look for");
|
||||
|
||||
// Act
|
||||
@@ -585,7 +585,7 @@ namespace Recyclable.CollectionsTests
|
||||
public void LongIndexOfShouldReturnCorrectIndexes(string testCase, IEnumerable<long> testData, long itemsCount, int targetBlockSize)
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableLongList<long>(testData, minBlockSize: targetBlockSize);
|
||||
using var list = new RecyclableLongList<long>(testData, minBlockSize: targetBlockSize, itemsCount);
|
||||
|
||||
// Act & Validate
|
||||
foreach (var item in testData)
|
||||
@@ -603,7 +603,7 @@ namespace Recyclable.CollectionsTests
|
||||
public void RemoveAtFromTheBeginningShouldSucceed(string testCase, IEnumerable<long> testData, long itemsCount, int targetBlockSize)
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableLongList<long>(testData, minBlockSize: targetBlockSize);
|
||||
using var list = new RecyclableLongList<long>(testData, minBlockSize: targetBlockSize, itemsCount);
|
||||
var listAsArray = list.ToArray();
|
||||
|
||||
// Act & Validate
|
||||
@@ -628,7 +628,7 @@ namespace Recyclable.CollectionsTests
|
||||
public void RemoveAtFromTheEndShouldSucceed(string testCase, IEnumerable<long> testData, long itemsCount, int targetBlockSize)
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableLongList<long>(testData, minBlockSize: targetBlockSize);
|
||||
using var list = new RecyclableLongList<long>(testData, minBlockSize: targetBlockSize, itemsCount);
|
||||
var listAsArray = list.ToArray();
|
||||
|
||||
// Act & Validate
|
||||
@@ -653,7 +653,7 @@ namespace Recyclable.CollectionsTests
|
||||
public void RemoveFromTheBeginningShouldRemoveTheCorrectItem(string testCase, IEnumerable<long> testData, long itemsCount, int targetBlockSize)
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableLongList<long>(testData, minBlockSize: targetBlockSize);
|
||||
using var list = new RecyclableLongList<long>(testData, targetBlockSize, itemsCount)
|
||||
var listAsArray = list.ToArray();
|
||||
|
||||
// Act & Validate
|
||||
@@ -678,7 +678,7 @@ namespace Recyclable.CollectionsTests
|
||||
public void RemoveFromTheEndShouldRemoveTheCorrectItem(string testCase, IEnumerable<long> testData, long itemsCount, int targetBlockSize)
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableLongList<long>(testData, minBlockSize: targetBlockSize);
|
||||
using var list = new RecyclableLongList<long>(testData, minBlockSize: targetBlockSize, itemsCount);
|
||||
var listAsArray = testData.ToArray();
|
||||
int removedCount = 0;
|
||||
foreach (var item in testData.Reverse())
|
||||
|
||||
Reference in new issue
Block a user