Unit tests extended. Missing .ToRecyclableList() & .ToRecyclableLongList() variants added. Support for all major interfaces finished. README.md updated.

This commit is contained in:
mlemanczyk committed 2023-09-10 17:42:08 +02:00
1 parent 9cd2096783
commit a315ff80d5
8 files changed
+791 -183

No files matched your search

@@ -1,6 +1,7 @@
using FluentAssertions;
using Recyclable.Collections;
using Recyclable.Collections.Linq;
using System.Collections;
#pragma warning disable xUnit1026, RCS1163, IDE0060, RCS1235
@@ -29,10 +30,34 @@ namespace Recyclable.CollectionsTests
using var list = new RecyclableList<long>();
// Act
if (testCase.Contains("ReadOnlySpan[", StringComparison.OrdinalIgnoreCase))
if (testCase.Contains("Array[", StringComparison.OrdinalIgnoreCase))
{
list.AddRange((Array)testData);
}
else if (testCase.Contains("ICollection[", StringComparison.OrdinalIgnoreCase))
{
list.AddRange((ICollection)testData);
}
else if (testCase.Contains("ICollection<T>[", StringComparison.OrdinalIgnoreCase))
{
list.AddRange((ICollection<long>)testData);
}
else if (testCase.Contains("IEnumerable[", StringComparison.OrdinalIgnoreCase))
{
list.AddRange((IEnumerable)testData);
}
else if (testCase.Contains("IReadOnlyList<T>[", StringComparison.OrdinalIgnoreCase))
{
list.AddRange((IReadOnlyList<long>)testData);
}
else if (testCase.Contains("ReadOnlySpan<T>[", StringComparison.OrdinalIgnoreCase))
{
list.AddRange(new ReadOnlySpan<long>((long[])testData));
}
else if (testCase.Contains("Span<T>[", StringComparison.OrdinalIgnoreCase))
{
list.AddRange(new Span<long>((long[])testData));
}
else if (testData is long[] testDataArray)
{
list.AddRange(testDataArray);
@@ -76,10 +101,34 @@ namespace Recyclable.CollectionsTests
using var list = new RecyclableList<long>();
// Act
if (testCase.Contains("ReadOnlySpan[", StringComparison.OrdinalIgnoreCase))
if (testCase.Contains("Array[", StringComparison.OrdinalIgnoreCase))
{
list.AddRange((Array)testData);
}
else if (testCase.Contains("ICollection[", StringComparison.OrdinalIgnoreCase))
{
list.AddRange((ICollection)testData);
}
else if (testCase.Contains("ICollection<T>[", StringComparison.OrdinalIgnoreCase))
{
list.AddRange((ICollection<long>)testData);
}
else if (testCase.Contains("IEnumerable[", StringComparison.OrdinalIgnoreCase))
{
list.AddRange((IEnumerable)testData);
}
else if (testCase.Contains("IReadOnlyList<T>[", StringComparison.OrdinalIgnoreCase))
{
list.AddRange((IReadOnlyList<long>)testData);
}
else if (testCase.Contains("ReadOnlySpan<T>[", StringComparison.OrdinalIgnoreCase))
{
list.AddRange(new ReadOnlySpan<long>((long[])testData));
}
else if (testCase.Contains("Span<T>[", StringComparison.OrdinalIgnoreCase))
{
list.AddRange(new Span<long>((long[])testData));
}
else if (testData is long[] testDataArray)
{
list.AddRange(testDataArray);
@@ -123,12 +172,43 @@ namespace Recyclable.CollectionsTests
using var list = new RecyclableList<long>();
// Act
if (testCase.Contains("ReadOnlySpan[", StringComparison.OrdinalIgnoreCase))
if (testCase.Contains("Array[", StringComparison.OrdinalIgnoreCase))
{
list.AddRange((Array)testData);
list.AddRange((Array)testData);
}
else if (testCase.Contains("ICollection[", StringComparison.OrdinalIgnoreCase))
{
list.AddRange((ICollection)testData);
list.AddRange((ICollection)testData);
}
else if (testCase.Contains("ICollection<T>[", StringComparison.OrdinalIgnoreCase))
{
list.AddRange((ICollection<long>)testData);
list.AddRange((ICollection<long>)testData);
}
else if (testCase.Contains("IEnumerable[", StringComparison.OrdinalIgnoreCase))
{
list.AddRange((IEnumerable)testData);
list.AddRange((IEnumerable)testData);
}
else if (testCase.Contains("IReadOnlyList<T>[", StringComparison.OrdinalIgnoreCase))
{
list.AddRange((IReadOnlyList<long>)testData);
list.AddRange((IReadOnlyList<long>)testData);
}
else if (testCase.Contains("ReadOnlySpan<T>[", StringComparison.OrdinalIgnoreCase))
{
var readOnlySpan = new ReadOnlySpan<long>((long[])testData);
list.AddRange(readOnlySpan);
list.AddRange(readOnlySpan);
}
else if (testCase.Contains("Span<T>[", StringComparison.OrdinalIgnoreCase))
{
var readOnlySpan = new Span<long>((long[])testData);
list.AddRange(readOnlySpan);
list.AddRange(readOnlySpan);
}
else if (testData is long[] testDataArray)
{
list.AddRange(testDataArray);
@@ -1,6 +1,7 @@
using MoreLinq;
using Open.Numeric.Primes;
using Recyclable.Collections;
using System.Collections;
using System.Numerics;
namespace Recyclable.CollectionsTests
@@ -78,23 +79,21 @@ namespace Recyclable.CollectionsTests
{
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, true);
IDisposable disposable;
switch (refType)
{
case false:
long[] testData = CreateTestData(itemsCount).ToArray();
yield return new object[] { $"int[{itemsCount}]", testData, itemsCount };
yield return new object[] { $"ReadOnlySpan[{itemsCount}]", testData, itemsCount };
//GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, true);
yield return new object[] { $"List<int>(itemsCount: {itemsCount}", testData.ToList(), itemsCount };
//GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, true);
yield return new object[] { $"RecyclableList<int>(itemsCount: {itemsCount})", disposable = testData.ToRecyclableList(), itemsCount };
//disposable.Dispose();
//GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, true);
yield return new object[] { $"Array[{itemsCount}]", testData, itemsCount };
yield return new object[] { $"ICollection[{itemsCount}]", testData, itemsCount };
yield return new object[] { $"ICollection<T>[{itemsCount}]", testData, itemsCount };
yield return new object[] { $"IEnumerable[{itemsCount}]", testData, itemsCount };
yield return new object[] { $"IEnumerable<T>[{itemsCount}] without non-enumerated count", new EnumerableWithoutCount<long>(testData), itemsCount };
yield return new object[] { $"IList<T>[{itemsCount}]", new CustomIList<long>(testData), itemsCount };
yield return new object[] { $"IReadOnlyList<T>[{itemsCount}])", testData, itemsCount };
yield return new object[] { $"List<T>[{itemsCount}]", testData.ToList(), itemsCount };
yield return new object[] { $"ReadOnlySpan<T>[{itemsCount}]", testData, itemsCount };
yield return new object[] { $"RecyclableList<T>[{itemsCount}]", testData.ToRecyclableList(), itemsCount };
foreach (var sourceBlockSize in BlockSizeVariants)
{
@@ -105,39 +104,29 @@ namespace Recyclable.CollectionsTests
yield return new object[]
{
$"RecyclableLongList<int>(itemsCount: {itemsCount}, minBlockSize: {sourceBlockSize})",
disposable = testData.ToRecyclableLongList(sourceBlockSize),
$"RecyclableLongList<T>[itemsCount: {itemsCount}, minBlockSize: {sourceBlockSize}]",
testData.ToRecyclableLongList(sourceBlockSize),
itemsCount
};
//disposable.Dispose();
//GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, true);
}
yield return new object[] { $"IList<int>(itemsCount: {itemsCount})", new CustomIList<long>(testData), itemsCount };
//GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, true);
yield return new object[] { $"IEnumerable<int>(itemsCount: {itemsCount}) with non-enumerated count", testData, itemsCount };
//GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, true);
yield return new object[] { $"IEnumerable<int>(itemsCount: {itemsCount}) without non-enumerated count", new EnumerableWithoutCount<long>(testData), itemsCount };
//GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, true);
yield return new object[] { $"Span<T>[{itemsCount}]", testData, itemsCount };
yield return new object[] { $"T[{itemsCount}]", testData, itemsCount };
break;
case true:
IEnumerable<object> testRefData = CreateRefTestData(itemsCount).ToArray();
yield return new object[] { $"int[{itemsCount}]", testRefData, itemsCount };
//GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, true);
yield return new object[] { $"List<int>(itemsCount: {itemsCount}", testRefData.ToList(), itemsCount };
//GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, true);
yield return new object[] { $"RecyclableList<int>(itemsCount: {itemsCount})", disposable = testRefData.ToRecyclableList(), itemsCount };
//disposable.Dispose();
//GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, true);
yield return new object[] { $"Array[{itemsCount}]", testRefData, itemsCount };
yield return new object[] { $"ICollection(itemsCount: {itemsCount}", testRefData, itemsCount };
yield return new object[] { $"ICollection<T>(itemsCount: {itemsCount}", testRefData, itemsCount };
yield return new object[] { $"IEnumerable(itemsCount: {itemsCount})", testRefData, itemsCount };
yield return new object[] { $"IEnumerable<T>(itemsCount: {itemsCount}) without non-enumerated count", new EnumerableWithoutCount<object>(testRefData), itemsCount };
yield return new object[] { $"IList<T>(itemsCount: {itemsCount})", new CustomIList<object>(testRefData), itemsCount };
yield return new object[] { $"IReadOnlyList<T>(itemsCount: {itemsCount})", testRefData, itemsCount };
yield return new object[] { $"List<T>(itemsCount: {itemsCount}", testRefData.ToList(), itemsCount };
yield return new object[] { $"ReadOnlySpan<T>[{itemsCount}]", testRefData, itemsCount };
yield return new object[] { $"RecyclableList<T>(itemsCount: {itemsCount})", testRefData.ToRecyclableList(), itemsCount };
foreach (var sourceBlockSize in BlockSizeVariants)
{
@@ -148,24 +137,14 @@ namespace Recyclable.CollectionsTests
yield return new object[]
{
$"RecyclableLongList<int>(itemsCount: {itemsCount}, minBlockSize: {sourceBlockSize})",
disposable = testRefData.ToRecyclableLongList(sourceBlockSize),
$"RecyclableLongList<T>(itemsCount: {itemsCount}, minBlockSize: {sourceBlockSize})",
testRefData.ToRecyclableLongList(sourceBlockSize),
itemsCount
};
//disposable.Dispose();
//GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, true);
}
yield return new object[] { $"IList<int>(itemsCount: {itemsCount})", new CustomIList<object>(testRefData), itemsCount };
//GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, true);
yield return new object[] { $"IEnumerable<int>(itemsCount: {itemsCount}) with non-enumerated count", testRefData, itemsCount };
//GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, true);
yield return new object[] { $"IEnumerable<int>(itemsCount: {itemsCount}) without non-enumerated count", new EnumerableWithoutCount<object>(testRefData), itemsCount };
//GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, true);
yield return new object[] { $"Span<T>[{itemsCount}]", testRefData, itemsCount };
yield return new object[] { $"T[{itemsCount}]", testRefData, itemsCount };
break;
}
}
@@ -1,6 +1,7 @@
using FluentAssertions;
using Recyclable.Collections;
using Recyclable.Collections.Linq;
using System.Collections;
using System.Numerics;
#pragma warning disable xUnit1026, RCS1163, IDE0060, RCS1235
@@ -41,10 +42,34 @@ namespace Recyclable.CollectionsTests
using var list = new RecyclableLongList<long>(minBlockSize: targetBlockSize);
// Act
if (testCase.Contains("ReadOnlySpan[", StringComparison.OrdinalIgnoreCase))
if (testCase.Contains("Array[", StringComparison.OrdinalIgnoreCase))
{
list.AddRange((Array)testData);
}
else if (testCase.Contains("ICollection[", StringComparison.OrdinalIgnoreCase))
{
list.AddRange((ICollection)testData);
}
else if (testCase.Contains("ICollection<T>[", StringComparison.OrdinalIgnoreCase))
{
list.AddRange((ICollection<long>)testData);
}
else if (testCase.Contains("IEnumerable[", StringComparison.OrdinalIgnoreCase))
{
list.AddRange((IEnumerable)testData);
}
else if (testCase.Contains("IReadOnlyList<T>[", StringComparison.OrdinalIgnoreCase))
{
list.AddRange((IReadOnlyList<long>)testData);
}
else if (testCase.Contains("ReadOnlySpan<T>[", StringComparison.OrdinalIgnoreCase))
{
list.AddRange(new ReadOnlySpan<long>((long[])testData));
}
else if (testCase.Contains("Span<T>[", StringComparison.OrdinalIgnoreCase))
{
list.AddRange(new Span<long>((long[])testData));
}
else if (testData is long[] testDataArray)
{
list.AddRange(testDataArray);
@@ -90,10 +115,34 @@ namespace Recyclable.CollectionsTests
using var list = new RecyclableLongList<long>();
// Act
if (testCase.Contains("ReadOnlySpan[", StringComparison.OrdinalIgnoreCase))
if (testCase.Contains("Array[", StringComparison.OrdinalIgnoreCase))
{
list.AddRange((Array)testData);
}
else if (testCase.Contains("ICollection[", StringComparison.OrdinalIgnoreCase))
{
list.AddRange((ICollection)testData);
}
else if (testCase.Contains("ICollection<T>[", StringComparison.OrdinalIgnoreCase))
{
list.AddRange((ICollection<long>)testData);
}
else if (testCase.Contains("IEnumerable[", StringComparison.OrdinalIgnoreCase))
{
list.AddRange((IEnumerable)testData);
}
else if (testCase.Contains("IReadOnlyList<T>[", StringComparison.OrdinalIgnoreCase))
{
list.AddRange((IReadOnlyList<long>)testData);
}
else if (testCase.Contains("ReadOnlySpan<T>[", StringComparison.OrdinalIgnoreCase))
{
list.AddRange(new ReadOnlySpan<long>((long[])testData));
}
else if (testCase.Contains("Span<T>[", StringComparison.OrdinalIgnoreCase))
{
list.AddRange(new Span<long>((long[])testData));
}
else if (testData is long[] testDataArray)
{
list.AddRange(testDataArray);
@@ -138,12 +187,43 @@ namespace Recyclable.CollectionsTests
using var list = new RecyclableLongList<long>(minBlockSize: targetBlockSize);
// Act
if (testCase.Contains("ReadOnlySpan[", StringComparison.OrdinalIgnoreCase))
if (testCase.Contains("Array[", StringComparison.OrdinalIgnoreCase))
{
list.AddRange((Array)testData);
list.AddRange((Array)testData);
}
else if (testCase.Contains("ICollection[", StringComparison.OrdinalIgnoreCase))
{
list.AddRange((ICollection)testData);
list.AddRange((ICollection)testData);
}
else if (testCase.Contains("ICollection<T>[", StringComparison.OrdinalIgnoreCase))
{
list.AddRange((ICollection<long>)testData);
list.AddRange((ICollection<long>)testData);
}
else if (testCase.Contains("IEnumerable[", StringComparison.OrdinalIgnoreCase))
{
list.AddRange((IEnumerable)testData);
list.AddRange((IEnumerable)testData);
}
else if (testCase.Contains("IReadOnlyList<T>[", StringComparison.OrdinalIgnoreCase))
{
list.AddRange((IReadOnlyList<long>)testData);
list.AddRange((IReadOnlyList<long>)testData);
}
else if (testCase.Contains("ReadOnlySpan<T>[", StringComparison.OrdinalIgnoreCase))
{
var readOnlySpan = new ReadOnlySpan<long>((long[])testData);
list.AddRange(readOnlySpan);
list.AddRange(readOnlySpan);
}
else if (testCase.Contains("Span<T>[", StringComparison.OrdinalIgnoreCase))
{
var readOnlySpan = new Span<long>((long[])testData);
list.AddRange(readOnlySpan);
list.AddRange(readOnlySpan);
}
else if (testData is long[] testDataArray)
{
list.AddRange(testDataArray);