RecyclableArrayList & RecyclableList tests synced.
This commit is contained in:
1 parent
76598dcc7d
commit
b815767d8f
2 files changed
+245
-49
No files matched your search
@@ -5,26 +5,6 @@ namespace Recyclable.CollectionsTests
|
||||
{
|
||||
public class RecyclableArrayListTests
|
||||
{
|
||||
[Theory]
|
||||
[MemberData(nameof(RecyclableListTestData.SourceDataVariants), MemberType = typeof(RecyclableListTestData))]
|
||||
public void AddCountShouldSucceed(string testCase, IEnumerable<long> testData, long itemsCount)
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableArrayList<long>();
|
||||
|
||||
// Act
|
||||
foreach (var item in testData)
|
||||
{
|
||||
list.Add(item);
|
||||
_ = list.Count.Should().Be((int)item);
|
||||
}
|
||||
|
||||
// Validate
|
||||
_ = list.Capacity.Should().BeGreaterThanOrEqualTo((int)itemsCount);
|
||||
_ = list.Count.Should().Be((int)itemsCount);
|
||||
_ = list.Should().ContainInConsecutiveOrder(testData);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(RecyclableListTestData.SourceDataVariants), MemberType = typeof(RecyclableListTestData))]
|
||||
public void AddRangeShouldAddItemsInCorrectOrder(string testCase, IEnumerable<long> testData, long itemsCount)
|
||||
@@ -68,24 +48,157 @@ namespace Recyclable.CollectionsTests
|
||||
_ = list.Should().ContainInConsecutiveOrder(testData);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(RecyclableListTestData.EmptySourceDataVariants), MemberType = typeof(RecyclableListTestData))]
|
||||
public void AddRangeShouldDoNothingWhenSourceIsEmpty(string testCase, IEnumerable<long> testData)
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableArrayList<long>();
|
||||
|
||||
// Act
|
||||
if (testData is long[] testDataArray)
|
||||
{
|
||||
list.AddRange(testDataArray);
|
||||
}
|
||||
else if (testData is List<long> testDataList)
|
||||
{
|
||||
list.AddRange(testDataList);
|
||||
}
|
||||
else if (testData is RecyclableArrayList<long> testDataRecyclableArrayList)
|
||||
{
|
||||
list.AddRange(testDataRecyclableArrayList);
|
||||
}
|
||||
else if (testData is RecyclableList<long> testDataRecyclableList)
|
||||
{
|
||||
list.AddRange(testDataRecyclableList);
|
||||
}
|
||||
else if (testData is IList<long> testDataIList)
|
||||
{
|
||||
list.AddRange(testDataIList);
|
||||
}
|
||||
else if (testData is IEnumerable<long> testDataIEnumerable)
|
||||
{
|
||||
list.AddRange(testDataIEnumerable);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidCastException("Unknown type of test data");
|
||||
}
|
||||
|
||||
// Validate
|
||||
_ = list.Capacity.Should().Be(0);
|
||||
_ = list.Count.Should().Be(0);
|
||||
_ = list.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(RecyclableListTestData.SourceDataVariants), MemberType = typeof(RecyclableListTestData))]
|
||||
public void AddRangeShouldNotOverrideItems(string testCase, IEnumerable<long> testData, long itemsCount)
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableArrayList<long>();
|
||||
|
||||
// Act
|
||||
if (testData is long[] testDataArray)
|
||||
{
|
||||
list.AddRange(testDataArray);
|
||||
list.AddRange(testDataArray);
|
||||
}
|
||||
else if (testData is List<long> testDataList)
|
||||
{
|
||||
list.AddRange(testDataList);
|
||||
list.AddRange(testDataList);
|
||||
}
|
||||
else if (testData is RecyclableArrayList<long> testDataRecyclableArrayList)
|
||||
{
|
||||
list.AddRange(testDataRecyclableArrayList);
|
||||
list.AddRange(testDataRecyclableArrayList);
|
||||
}
|
||||
else if (testData is RecyclableList<long> testDataRecyclableList)
|
||||
{
|
||||
list.AddRange(testDataRecyclableList);
|
||||
list.AddRange(testDataRecyclableList);
|
||||
}
|
||||
else if (testData is IList<long> testDataIList)
|
||||
{
|
||||
list.AddRange(testDataIList);
|
||||
list.AddRange(testDataIList);
|
||||
}
|
||||
else if (testData is IEnumerable<long> testDataIEnumerable)
|
||||
{
|
||||
list.AddRange(testDataIEnumerable);
|
||||
list.AddRange(testDataIEnumerable);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidCastException("Unknown type of test data");
|
||||
}
|
||||
|
||||
// Validate
|
||||
var expectedData = testData.Concat(testData).ToArray();
|
||||
|
||||
if (itemsCount > 0)
|
||||
{
|
||||
_ = list.Capacity.Should().BeGreaterThanOrEqualTo((int)itemsCount * 2);
|
||||
}
|
||||
|
||||
_ = list.Count.Should().Be(expectedData.Length);
|
||||
_ = list.Should().ContainInConsecutiveOrder(expectedData);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(RecyclableListTestData.SourceDataVariants), MemberType = typeof(RecyclableListTestData))]
|
||||
public void AddShouldAcceptDuplicates(string testCase, IEnumerable<long> testData, long itemsCount)
|
||||
{
|
||||
// Act
|
||||
using var list = new RecyclableArrayList<long>((int)itemsCount * 2);
|
||||
foreach (var index in testData)
|
||||
{
|
||||
list.Add(index);
|
||||
}
|
||||
// Prepare
|
||||
testData = testData.Concat(testData).ToArray();
|
||||
|
||||
// Act
|
||||
using var list = new RecyclableArrayList<long>();
|
||||
foreach (var index in testData)
|
||||
{
|
||||
list.Add(index);
|
||||
}
|
||||
|
||||
// Validate
|
||||
_ = list.Count.Should().Be((int)itemsCount * 2);
|
||||
_ = list.Count.Should().Be((int)(itemsCount * 2));
|
||||
_ = list.Should().ContainInConsecutiveOrder(testData);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(RecyclableListTestData.SourceDataVariants), MemberType = typeof(RecyclableListTestData))]
|
||||
public void AddShouldAddItems(string testCase, IEnumerable<long> testData, long itemsCount)
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableArrayList<long>();
|
||||
|
||||
// Act
|
||||
foreach (var item in testData)
|
||||
{
|
||||
list.Add(item);
|
||||
_ = list.Count.Should().Be((int)item);
|
||||
}
|
||||
|
||||
// Validate
|
||||
_ = list.Capacity.Should().BeGreaterThanOrEqualTo((int)itemsCount);
|
||||
_ = list.Count.Should().Be((int)itemsCount);
|
||||
_ = list.Should().ContainInConsecutiveOrder(testData);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(RecyclableListTestData.SourceDataVariants), MemberType = typeof(RecyclableListTestData))]
|
||||
public void AddShouldAddItemWhenAfterAddRange(string testCase, IEnumerable<long> testData, long itemsCount)
|
||||
{
|
||||
// Act
|
||||
using var list = new RecyclableArrayList<long>();
|
||||
list.AddRange(testData);
|
||||
foreach (var index in testData)
|
||||
{
|
||||
list.Add(index);
|
||||
}
|
||||
|
||||
// Validate
|
||||
_ = list.Count.Should().Be((int)(itemsCount * 2));
|
||||
_ = list.Should().ContainInConsecutiveOrder(testData.Concat(testData));
|
||||
}
|
||||
|
||||
@@ -99,6 +212,7 @@ namespace Recyclable.CollectionsTests
|
||||
|
||||
// Act
|
||||
list.Clear();
|
||||
list.Clear();
|
||||
|
||||
// Validate
|
||||
_ = list.Count.Should().Be(0);
|
||||
@@ -106,6 +220,18 @@ namespace Recyclable.CollectionsTests
|
||||
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(RecyclableListTestData.SourceDataVariants), MemberType = typeof(RecyclableListTestData))]
|
||||
public void ConsecutiveDisposeShouldSucceed(string testCase, IEnumerable<long> testData, long itemsCount)
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableArrayList<long>(testData);
|
||||
list.Dispose();
|
||||
|
||||
// Act
|
||||
list.Dispose();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(RecyclableListTestData.SourceDataVariants), MemberType = typeof(RecyclableListTestData))]
|
||||
public void ConstructorShouldAcceptDuplicates(string testCase, IEnumerable<long> testData, long itemsCount)
|
||||
@@ -234,9 +360,46 @@ namespace Recyclable.CollectionsTests
|
||||
_ = yieldedItems.Should().ContainInConsecutiveOrder(testData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IndexOfShouldNotFindAnythingWhenListEmpty()
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableArrayList<int>();
|
||||
|
||||
// Validate
|
||||
_ = list.IndexOf(0).Should().Be(-1);
|
||||
_ = list.IndexOf(1).Should().Be(-1);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(RecyclableListTestData.SourceDataVariants), MemberType = typeof(RecyclableListTestData))]
|
||||
public void IndexOfShouldFindTheIndexes(string testCase, IEnumerable<long> testData, long itemsCount)
|
||||
public void IndexOfShouldNotFindNonExistingItems(string testCase, IEnumerable<long> testData, long itemsCount)
|
||||
{
|
||||
// Prepare
|
||||
if (itemsCount == 0)
|
||||
{
|
||||
// There is nothing to search for when our lists are empty
|
||||
return;
|
||||
}
|
||||
|
||||
// Prepare
|
||||
using var list = new RecyclableArrayList<long>(testData);
|
||||
_ = testData.Any().Should().BeTrue("we need items on the list that we can look for");
|
||||
|
||||
// Act
|
||||
foreach (var item in testData)
|
||||
{
|
||||
// Validate
|
||||
_ = list.IndexOf(-item).Should().Be(-1);
|
||||
}
|
||||
|
||||
// Validate
|
||||
_ = list.IndexOf(0).Should().Be(-1);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(RecyclableListTestData.SourceDataVariants), MemberType = typeof(RecyclableListTestData))]
|
||||
public void IndexOfShouldReturnCorrectIndexes(string testCase, IEnumerable<long> testData, long itemsCount)
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableArrayList<long>(testData);
|
||||
@@ -249,6 +412,44 @@ namespace Recyclable.CollectionsTests
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(RecyclableListTestData.SourceDataVariants), MemberType = typeof(RecyclableListTestData))]
|
||||
public void InitializeSortClearAddRangeRemoveShouldSucceed(string testCase, IEnumerable<long> testData, long itemsCount)
|
||||
{
|
||||
if (itemsCount == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Act
|
||||
using RecyclableArrayList<long> list = new(testData);
|
||||
list.QuickSort();
|
||||
|
||||
// Validate
|
||||
_ = list.Count.Should().Be((int)itemsCount);
|
||||
_ = list.Should().Equal(testData);
|
||||
|
||||
// Act
|
||||
list.Clear();
|
||||
|
||||
// Validate
|
||||
_ = list.Count.Should().Be(0);
|
||||
_ = list.Should().BeEmpty();
|
||||
|
||||
// Act
|
||||
list.AddRange(testData);
|
||||
|
||||
// Validate
|
||||
_ = list.Count.Should().Be((int)itemsCount);
|
||||
_ = list.Should().ContainInConsecutiveOrder(testData);
|
||||
|
||||
// Act
|
||||
foreach (var item in testData.Reverse())
|
||||
{
|
||||
_ = list.Remove(item).Should().BeTrue();
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(RecyclableListTestData.SourceDataVariants), MemberType = typeof(RecyclableListTestData))]
|
||||
public void InsertAtTheBeginningShouldMoveItems(string testCase, IEnumerable<long> testData, long itemsCount)
|
||||
@@ -269,24 +470,6 @@ namespace Recyclable.CollectionsTests
|
||||
_ = list.Should().ContainInConsecutiveOrder(testData.Reverse());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(RecyclableListTestData.SourceDataVariants), MemberType = typeof(RecyclableListTestData))]
|
||||
public void LongIndexOfShouldReturnCorrectIndexes(string testCase, IEnumerable<long> testData, long itemsCount)
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableArrayList<long>(testData);
|
||||
|
||||
// Act & Validate
|
||||
foreach (var item in testData)
|
||||
{
|
||||
// Act
|
||||
var index = list.IndexOf(item);
|
||||
|
||||
// Validate
|
||||
_ = index.Should().Be((int)(item - 1));
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(RecyclableListTestData.SourceDataVariants), MemberType = typeof(RecyclableListTestData))]
|
||||
public void RemoveAtFromTheBeginningShouldSucceed(string testCase, IEnumerable<long> testData, long itemsCount)
|
||||
|
||||
Reference in new issue
Block a user