Custom list types added to force the desired interfaces.
This commit is contained in:
1 parent
2416eeeab3
commit
a5d59b1f6e
9 files changed
+185
-35
No files matched your search
@@ -2,6 +2,10 @@
|
|||||||
`Recyclable.Collections.TestData` project is a basic open source package for containing test data useful for testing collections like `RecyclableList<T>`, `RecyclableLongList<T>`, `List<T>`, `SortableList<T>`, `PriorityQueue<T>` & similar.
|
`Recyclable.Collections.TestData` project is a basic open source package for containing test data useful for testing collections like `RecyclableList<T>`, `RecyclableLongList<T>`, `List<T>`, `SortableList<T>`, `PriorityQueue<T>` & similar.
|
||||||
|
|
||||||
## Included
|
## Included
|
||||||
* `EnmerableWithoutCount<T>`
|
* `CustomICollection<T>` with `ICollection` interface
|
||||||
|
* `CustomICollectionT<T>` with `ICollection<T>` interface
|
||||||
|
* `CustomIList<T>` with `IList` interface
|
||||||
|
* `CustomIListT<T>` with `IList<T>` interface
|
||||||
|
* `CustomIReadOnlyList<T>` with `IReadOnlyList<T>` interface
|
||||||
|
* `EnmerableWithoutCount<T>` with `IEnumerable` & `IEnumerable<T>` interfaces
|
||||||
* `RecyclableLongListTestData`
|
* `RecyclableLongListTestData`
|
||||||
* `CustomIList`
|
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
namespace Recyclable.Collections.TestData
|
||||||
|
{
|
||||||
|
public class CustomICollection<T> : ICollection, IEnumerable<T>
|
||||||
|
{
|
||||||
|
private readonly T[] _testData;
|
||||||
|
|
||||||
|
public CustomICollection(in T[] testData)
|
||||||
|
{
|
||||||
|
_testData = testData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Count => _testData.Length;
|
||||||
|
public bool IsSynchronized => true;
|
||||||
|
public object SyncRoot => _testData;
|
||||||
|
|
||||||
|
public void CopyTo(Array array, int index) => _testData.CopyTo((T[])array, index);
|
||||||
|
|
||||||
|
public IEnumerator GetEnumerator() => _testData.GetEnumerator();
|
||||||
|
|
||||||
|
IEnumerator<T> IEnumerable<T>.GetEnumerator() => ((IEnumerable<T>)_testData).GetEnumerator();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
namespace Recyclable.Collections.TestData
|
||||||
|
{
|
||||||
|
public class CustomICollectionT<T> : ICollection<T>, IEnumerable<T>
|
||||||
|
{
|
||||||
|
private readonly List<T> _testData;
|
||||||
|
|
||||||
|
public CustomICollectionT(in List<T> testData)
|
||||||
|
{
|
||||||
|
_testData = testData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Count => _testData.Count;
|
||||||
|
public bool IsReadOnly => false;
|
||||||
|
|
||||||
|
public void Add(T item) => _testData.Add(item);
|
||||||
|
|
||||||
|
public void Clear() => _testData.Clear();
|
||||||
|
|
||||||
|
public bool Contains(T item) => _testData.Contains(item);
|
||||||
|
|
||||||
|
public void CopyTo(T[] array, int arrayIndex) => _testData.CopyTo(array, arrayIndex);
|
||||||
|
|
||||||
|
public IEnumerator<T> GetEnumerator() => _testData.GetEnumerator();
|
||||||
|
|
||||||
|
public bool Remove(T item) => _testData.Remove(item);
|
||||||
|
|
||||||
|
IEnumerator IEnumerable.GetEnumerator() => _testData.GetEnumerator();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Recyclable.Collections.TestData
|
namespace Recyclable.Collections.TestData
|
||||||
{
|
{
|
||||||
public class CustomIList<T> : IList<T>
|
public class CustomIList<T> : IList, IEnumerable<T>
|
||||||
{
|
{
|
||||||
protected List<T> _list;
|
protected List<T> _list;
|
||||||
|
|
||||||
@@ -16,18 +16,51 @@ namespace Recyclable.Collections.TestData
|
|||||||
_list = new List<T>(items);
|
_list = new List<T>(items);
|
||||||
}
|
}
|
||||||
|
|
||||||
public T this[int index] { get => _list[index]; set => _list[index] = value; }
|
public object? this[int index] { get => ((IList)_list)[index]; set => ((IList)_list)[index] = value; }
|
||||||
public int Count => _list.Count;
|
|
||||||
public bool IsReadOnly => false;
|
public bool IsFixedSize => ((IList)_list).IsFixedSize;
|
||||||
public void Add(T item) => _list.Add(item);
|
|
||||||
public void Clear() => _list.Clear();
|
public bool IsReadOnly => ((IList)_list).IsReadOnly;
|
||||||
public bool Contains(T item) => _list.Contains(item);
|
|
||||||
public void CopyTo(T[] array, int arrayIndex) => _list.CopyTo(0, array, arrayIndex, _list.Count);
|
public int Count => ((ICollection)_list).Count;
|
||||||
public IEnumerator<T> GetEnumerator() => _list.GetEnumerator();
|
|
||||||
public int IndexOf(T item) => _list.IndexOf(item);
|
public bool IsSynchronized => ((ICollection)_list).IsSynchronized;
|
||||||
public void Insert(int index, T item) => _list.Insert(index, item);
|
|
||||||
public bool Remove(T item) => _list.Remove(item);
|
public object SyncRoot => ((ICollection)_list).SyncRoot;
|
||||||
public void RemoveAt(int index) => _list.RemoveAt(index);
|
|
||||||
IEnumerator IEnumerable.GetEnumerator() => _list.GetEnumerator();
|
public int Add(object? value) => ((IList)_list).Add(value);
|
||||||
|
|
||||||
|
public void Clear()
|
||||||
|
{
|
||||||
|
((IList)_list).Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Contains(object? value) => ((IList)_list).Contains(value);
|
||||||
|
|
||||||
|
public void CopyTo(Array array, int index)
|
||||||
|
{
|
||||||
|
((ICollection)_list).CopyTo(array, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerator GetEnumerator() => ((IEnumerable)_list).GetEnumerator();
|
||||||
|
|
||||||
|
public int IndexOf(object? value) => ((IList)_list).IndexOf(value);
|
||||||
|
|
||||||
|
public void Insert(int index, object? value)
|
||||||
|
{
|
||||||
|
((IList)_list).Insert(index, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Remove(object? value)
|
||||||
|
{
|
||||||
|
((IList)_list).Remove(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveAt(int index)
|
||||||
|
{
|
||||||
|
((IList)_list).RemoveAt(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerator<T> IEnumerable<T>.GetEnumerator() => ((IEnumerable<T>)_list).GetEnumerator();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
namespace Recyclable.Collections.TestData
|
||||||
|
{
|
||||||
|
public class CustomIListT<T> : IList<T>, IEnumerable<T>
|
||||||
|
{
|
||||||
|
protected List<T> _list;
|
||||||
|
|
||||||
|
public CustomIListT()
|
||||||
|
{
|
||||||
|
_list = new List<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public CustomIListT(IEnumerable<T> items)
|
||||||
|
{
|
||||||
|
_list = new List<T>(items);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T this[int index] { get => _list[index]; set => _list[index] = value; }
|
||||||
|
public int Count => _list.Count;
|
||||||
|
public bool IsReadOnly => false;
|
||||||
|
public void Add(T item) => _list.Add(item);
|
||||||
|
public void Clear() => _list.Clear();
|
||||||
|
public bool Contains(T item) => _list.Contains(item);
|
||||||
|
public void CopyTo(T[] array, int arrayIndex) => _list.CopyTo(0, array, arrayIndex, _list.Count);
|
||||||
|
public IEnumerator<T> GetEnumerator() => _list.GetEnumerator();
|
||||||
|
public int IndexOf(T item) => _list.IndexOf(item);
|
||||||
|
public void Insert(int index, T item) => _list.Insert(index, item);
|
||||||
|
public bool Remove(T item) => _list.Remove(item);
|
||||||
|
public void RemoveAt(int index) => _list.RemoveAt(index);
|
||||||
|
IEnumerator IEnumerable.GetEnumerator() => _list.GetEnumerator();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
namespace Recyclable.Collections.TestData
|
||||||
|
{
|
||||||
|
public class CustomIReadOnlyList<T> : IReadOnlyList<T>
|
||||||
|
{
|
||||||
|
private readonly T[] _testData;
|
||||||
|
|
||||||
|
public CustomIReadOnlyList(T[] testData)
|
||||||
|
{
|
||||||
|
_testData = testData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T this[int index] => _testData[index];
|
||||||
|
|
||||||
|
public int Count => _testData.Length;
|
||||||
|
|
||||||
|
public IEnumerator<T> GetEnumerator() => _testData.AsEnumerable().GetEnumerator();
|
||||||
|
|
||||||
|
IEnumerator IEnumerable.GetEnumerator() => _testData.GetEnumerator();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Recyclable.Collections.TestData
|
namespace Recyclable.Collections.TestData
|
||||||
{
|
{
|
||||||
public class EnumerableWithoutCount<T> : IEnumerable<T>
|
public class EnumerableWithoutCount<T> : IEnumerable, IEnumerable<T>
|
||||||
{
|
{
|
||||||
private readonly IEnumerable<T> _testData;
|
private readonly IEnumerable<T> _testData;
|
||||||
|
|
||||||
@@ -11,7 +11,8 @@ namespace Recyclable.Collections.TestData
|
|||||||
_testData = testData;
|
_testData = testData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerator<T> GetEnumerator() => _testData.GetEnumerator();
|
public IEnumerator GetEnumerator() => _testData.GetEnumerator();
|
||||||
IEnumerator IEnumerable.GetEnumerator() => _testData.GetEnumerator();
|
|
||||||
|
IEnumerator<T> IEnumerable<T>.GetEnumerator() => _testData.GetEnumerator();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
<OutputType>Library</OutputType>
|
<OutputType>Library</OutputType>
|
||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
<PackageId>Recyclable.Collections.TestData</PackageId>
|
<PackageId>Recyclable.Collections.TestData</PackageId>
|
||||||
<PackageVersion>0.0.2</PackageVersion>
|
<PackageVersion>0.0.3</PackageVersion>
|
||||||
<Authors>Marek Lemańczyk</Authors>
|
<Authors>Marek Lemańczyk</Authors>
|
||||||
<Company>N/A</Company>
|
<Company>N/A</Company>
|
||||||
<Product>Recyclable.Collections.TestData</Product>
|
<Product>Recyclable.Collections.TestData</Product>
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
|
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
|
||||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||||
<RepositoryType>git</RepositoryType>
|
<RepositoryType>git</RepositoryType>
|
||||||
<PackageReleaseNotes>Initial version extracted from `Recyclable.Collections`</PackageReleaseNotes>
|
<PackageReleaseNotes>Custom collection types added to force desired interfaces.</PackageReleaseNotes>
|
||||||
<Platforms>AnyCPU;x64</Platforms>
|
<Platforms>AnyCPU;x64</Platforms>
|
||||||
<PackageIcon>logo.png</PackageIcon>
|
<PackageIcon>logo.png</PackageIcon>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|||||||
@@ -84,12 +84,13 @@ namespace Recyclable.Collections.TestData
|
|||||||
long[] testData = CreateTestData(itemsCount).ToArray();
|
long[] testData = CreateTestData(itemsCount).ToArray();
|
||||||
|
|
||||||
yield return new object[] { $"Array[{itemsCount}]", testData, itemsCount };
|
yield return new object[] { $"Array[{itemsCount}]", testData, itemsCount };
|
||||||
yield return new object[] { $"ICollection[{itemsCount}]", testData, itemsCount };
|
yield return new object[] { $"ICollection[{itemsCount}]", new CustomICollection<long>(testData), itemsCount };
|
||||||
yield return new object[] { $"ICollection<T>[{itemsCount}]", testData, itemsCount };
|
yield return new object[] { $"ICollection<T>[{itemsCount}]", new CustomICollectionT<long>(testData.ToList()), itemsCount };
|
||||||
yield return new object[] { $"IEnumerable[{itemsCount}]", testData, itemsCount };
|
yield return new object[] { $"IEnumerable[{itemsCount}]", new EnumerableWithoutCount<long>(testData), itemsCount };
|
||||||
yield return new object[] { $"IEnumerable<T>[{itemsCount}] without non-enumerated count", new EnumerableWithoutCount<long>(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[] { $"IList[{itemsCount}]", new CustomIList<long>(testData), itemsCount };
|
||||||
yield return new object[] { $"IReadOnlyList<T>[{itemsCount}])", testData, itemsCount };
|
yield return new object[] { $"IList<T>[{itemsCount}]", new CustomIListT<long>(testData), itemsCount };
|
||||||
|
yield return new object[] { $"IReadOnlyList<T>[{itemsCount}])", new CustomIReadOnlyList<long>(testData), itemsCount };
|
||||||
yield return new object[] { $"List<T>[{itemsCount}]", testData.ToList(), itemsCount };
|
yield return new object[] { $"List<T>[{itemsCount}]", testData.ToList(), itemsCount };
|
||||||
yield return new object[] { $"ReadOnlySpan<T>[{itemsCount}]", testData, itemsCount };
|
yield return new object[] { $"ReadOnlySpan<T>[{itemsCount}]", testData, itemsCount };
|
||||||
yield return new object[] { $"RecyclableList<T>[{itemsCount}]", testData.ToRecyclableList(), itemsCount };
|
yield return new object[] { $"RecyclableList<T>[{itemsCount}]", testData.ToRecyclableList(), itemsCount };
|
||||||
@@ -114,15 +115,16 @@ namespace Recyclable.Collections.TestData
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case true:
|
case true:
|
||||||
IEnumerable<object> testRefData = CreateRefTestData(itemsCount).ToArray();
|
object[] testRefData = CreateRefTestData(itemsCount).ToArray();
|
||||||
|
|
||||||
yield return new object[] { $"Array[{itemsCount}]", testRefData, itemsCount };
|
yield return new object[] { $"Array[{itemsCount}]", testRefData, itemsCount };
|
||||||
yield return new object[] { $"ICollection(itemsCount: {itemsCount}", testRefData, itemsCount };
|
yield return new object[] { $"ICollection(itemsCount: {itemsCount}", new CustomICollection<object>(testRefData), itemsCount };
|
||||||
yield return new object[] { $"ICollection<T>(itemsCount: {itemsCount}", testRefData, itemsCount };
|
yield return new object[] { $"ICollection<T>(itemsCount: {itemsCount}", new CustomICollectionT<object>(testRefData.ToList()), itemsCount };
|
||||||
yield return new object[] { $"IEnumerable(itemsCount: {itemsCount})", testRefData, itemsCount };
|
yield return new object[] { $"IEnumerable(itemsCount: {itemsCount})", new EnumerableWithoutCount<object>(testRefData), itemsCount };
|
||||||
yield return new object[] { $"IEnumerable<T>(itemsCount: {itemsCount}) without non-enumerated count", new EnumerableWithoutCount<object>(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[] { $"IList(itemsCount: {itemsCount})", new CustomIList<object>(testRefData), itemsCount };
|
||||||
yield return new object[] { $"IReadOnlyList<T>(itemsCount: {itemsCount})", testRefData, itemsCount };
|
yield return new object[] { $"IList<T>(itemsCount: {itemsCount})", new CustomIListT<object>(testRefData), itemsCount };
|
||||||
|
yield return new object[] { $"IReadOnlyList<T>(itemsCount: {itemsCount})", new CustomIReadOnlyList<object>(testRefData), itemsCount };
|
||||||
yield return new object[] { $"List<T>(itemsCount: {itemsCount}", testRefData.ToList(), 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[] { $"ReadOnlySpan<T>[{itemsCount}]", testRefData, itemsCount };
|
||||||
yield return new object[] { $"RecyclableList<T>(itemsCount: {itemsCount})", testRefData.ToRecyclableList(), itemsCount };
|
yield return new object[] { $"RecyclableList<T>(itemsCount: {itemsCount})", testRefData.ToRecyclableList(), itemsCount };
|
||||||
@@ -191,11 +193,11 @@ namespace Recyclable.Collections.TestData
|
|||||||
public static IEnumerable<object[]> SourceRefDataVariants => CreateSourceDataVariants(true);
|
public static IEnumerable<object[]> SourceRefDataVariants => CreateSourceDataVariants(true);
|
||||||
public static IEnumerable<object[]> SourceRefDataWithBlockSizeVariants { get; } = CombineSourceDataWithBlockSize(SourceRefDataVariants);
|
public static IEnumerable<object[]> SourceRefDataWithBlockSizeVariants { get; } = CombineSourceDataWithBlockSize(SourceRefDataVariants);
|
||||||
|
|
||||||
private static IEnumerable<long> _initialItemIndexVariants => new long[] { 0, 1, 2, 3, 4, 5 };
|
private static IEnumerable<long> InitialItemIndexVariants => new long[] { 0, 1, 2, 3, 4, 5 };
|
||||||
private static IEnumerable<long> CreateItemIndexVariants(long itemsCount, int blockSize)
|
private static IEnumerable<long> CreateItemIndexVariants(long itemsCount, int blockSize)
|
||||||
{
|
{
|
||||||
IEnumerable<long> primes = _initialItemIndexVariants.Concat(
|
IEnumerable<long> primes = InitialItemIndexVariants.Concat(
|
||||||
_initialItemIndexVariants.SelectMany(index => new long[] { blockSize - index, blockSize + index })
|
InitialItemIndexVariants.SelectMany(index => new long[] { blockSize - index, blockSize + index })
|
||||||
//new long[] { blockSize - 3, blockSize - 2, blockSize - 1, blockSize, blockSize + 1, blockSize + 2, blockSize + 3 }
|
//new long[] { blockSize - 3, blockSize - 2, blockSize - 1, blockSize, blockSize + 1, blockSize + 2, blockSize + 3 }
|
||||||
).ToArray();
|
).ToArray();
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user