125 lines
4.2 KiB
C#
125 lines
4.2 KiB
C#
using Recyclable.Collections;
|
|
|
|
namespace Recyclable.CollectionsTests
|
|
{
|
|
public class RecyclableListTestData : IDisposable
|
|
{
|
|
private static void DisposeTestData(IEnumerable<object[]>? testCases)
|
|
{
|
|
if (testCases != null)
|
|
{
|
|
foreach (var testData in testCases)
|
|
{
|
|
foreach (var item in testData)
|
|
{
|
|
if (item is IDisposable disposable)
|
|
{
|
|
disposable.Dispose();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void DisposeTestData(IEnumerable<IEnumerable<long>>? testCases)
|
|
{
|
|
if (testCases != null)
|
|
{
|
|
foreach (var testData in testCases)
|
|
{
|
|
if (testData is IDisposable disposable)
|
|
{
|
|
disposable.Dispose();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private static IEnumerable<long> DoCreateTestData(long itemsCount)
|
|
{
|
|
for (long index = 1; index <= itemsCount; index++)
|
|
{
|
|
yield return index;
|
|
}
|
|
}
|
|
|
|
public static IEnumerable<long> CreateTestData(long itemsCount) => DoCreateTestData(itemsCount).ToArray();
|
|
|
|
public static readonly IEnumerable<long> ItemsCountVariants = new long[]
|
|
{
|
|
0, 1, 2, 3, 10, 16, 32, 64, 128, 256, 512, 1_024, 2_048, 4_096, 8_192, 16_384,
|
|
32_768, 65_536, 131_072, 262_144, 524_288
|
|
};
|
|
|
|
public static readonly IEnumerable<int> BlockSizeVariants = new int[]
|
|
{
|
|
1, 2, 3, 10, 16, 32, 64, 128, 256, 512, 1_024, 2_048, 4_096,
|
|
8_192, 16_384, 32_768, 65_536, 131_072, 262_144, 524_288
|
|
};
|
|
|
|
private static IEnumerable<object[]> GetTargetDataVariants()
|
|
{
|
|
foreach (var itemsCount in ItemsCountVariants)
|
|
{
|
|
foreach (var targetBlockSize in BlockSizeVariants)
|
|
{
|
|
yield return new object[] { itemsCount, targetBlockSize };
|
|
}
|
|
}
|
|
}
|
|
|
|
public static IEnumerable<object[]> TargetDataVariants => GetTargetDataVariants().ToArray();
|
|
|
|
private static IEnumerable<object[]> CreateSourceDataVariants()
|
|
{
|
|
foreach (var itemsCount in ItemsCountVariants)
|
|
{
|
|
yield return new object[] { $"int[{itemsCount}]", CreateTestData(itemsCount).ToArray(), itemsCount };
|
|
yield return new object[] { $"List<int>(itemsCount: {itemsCount}", CreateTestData(itemsCount).ToList(), itemsCount };
|
|
yield return new object[] { $"RecyclableArrayList<int>(itemsCount: {itemsCount})", CreateTestData(itemsCount).ToRecyclableArrayList(), itemsCount };
|
|
foreach (var sourceBlockSize in BlockSizeVariants)
|
|
{
|
|
yield return new object[]
|
|
{
|
|
$"RecyclableList<int>(itemsCount: {itemsCount}, minBlockSize: {sourceBlockSize})",
|
|
CreateTestData(itemsCount).ToRecyclableList(sourceBlockSize),
|
|
itemsCount
|
|
};
|
|
|
|
}
|
|
|
|
yield return new object[] { $"IList<int>(itemsCount: {itemsCount})", new CustomIList<long>(CreateTestData(itemsCount)), itemsCount };
|
|
yield return new object[] { $"IEnumerable<int>(itemsCount: {itemsCount}) with non-enumerated count", CreateTestData(itemsCount), itemsCount };
|
|
yield return new object[] { $"IEnumerable<int>(itemsCount: {itemsCount}) without non-enumerated count", new EnumerableWithoutCount<long>(CreateTestData(itemsCount)), itemsCount };
|
|
}
|
|
}
|
|
|
|
public static IEnumerable<object[]> SourceDataVariants => CreateSourceDataVariants().ToArray();
|
|
|
|
private static IEnumerable<object[]> CreateSourceEmptyDataVariants() => new[]
|
|
{
|
|
new object[] { "int[]", Array.Empty<long>() },
|
|
new object[] { "List<int>", Array.Empty<long>().ToList() },
|
|
new object[] { "RecyclableArrayList<int>", Array.Empty<long>().ToRecyclableArrayList() },
|
|
new object[] { "RecyclableList<int>", Array.Empty<long>().ToRecyclableList() },
|
|
new object[] { "IList<int>", new CustomIList<long>(Array.Empty<long>()) },
|
|
new object[] { "IEnumerable<int> with non-enumerated count", Array.Empty<long>().AsEnumerable() },
|
|
new object[] { "IEnumerable<int> without non-enumerated count", new EnumerableWithoutCount<long>(Array.Empty<long>()) }
|
|
};
|
|
|
|
public static IEnumerable<object[]> EmptySourceDataVariants => CreateSourceEmptyDataVariants().ToArray();
|
|
|
|
private static IEnumerable<object[]> CreateSourceTargetDataVariants()
|
|
{
|
|
foreach (var testData in SourceDataVariants)
|
|
{
|
|
foreach (var targetBlockSize in BlockSizeVariants)
|
|
{
|
|
yield return new object[] { testData[0], testData[1], testData[2], targetBlockSize };
|
|
}
|
|
}
|
|
}
|
|
|
|
public static IEnumerable<object[]> SourceTargetDataVariants => CreateSourceTargetDataVariants().ToArray();
|
|
}
|
|
} |