Initial version of RecyclableBlockList implemented.
Tests switched to xUnit in hope to avoid stability issues.
This commit is contained in:
1 parent
aba28028b1
commit
93b8dc5317
17 files changed
+969
-228
No files matched your search
@@ -11,12 +11,16 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentAssertions" Version="6.8.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="3.0.2" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="3.0.2" />
|
||||
<PackageReference Include="morelinq" Version="3.3.2" />
|
||||
<PackageReference Include="coverlet.collector" Version="3.2.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="xunit" Version="2.4.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -0,0 +1,191 @@
|
||||
using FluentAssertions;
|
||||
using Recyclable.Collections;
|
||||
|
||||
namespace Recyclable.CollectionsTests
|
||||
{
|
||||
public class RecyclableBlockListTests
|
||||
{
|
||||
private readonly static IEnumerable<int> _testData = Enumerable.Range(1, 20);
|
||||
|
||||
[Fact]
|
||||
public void AddCountShouldSucceed()
|
||||
{
|
||||
// Prepare
|
||||
var testData = _testData.ToArray();
|
||||
var list = new RecyclableBlockList<int>();
|
||||
|
||||
// Act
|
||||
foreach (var item in testData)
|
||||
{
|
||||
list.Add(item);
|
||||
_ = list.LongCount.Should().Be(item);
|
||||
}
|
||||
|
||||
// Validate
|
||||
_ = list.Capacity.Should().Be(32);
|
||||
_ = list.Should().HaveCount(testData.Length)
|
||||
.And.ContainInConsecutiveOrder(testData)
|
||||
.And.BeEquivalentTo(testData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InsertAtTheBeginningShouldMoveItems()
|
||||
{
|
||||
// Prepare
|
||||
var testData = _testData.ToArray();
|
||||
var list = new RecyclableBlockList<int>();
|
||||
|
||||
// Act
|
||||
foreach (var item in testData)
|
||||
{
|
||||
list.Insert(0, item);
|
||||
_ = list.LongCount.Should().Be(item);
|
||||
}
|
||||
|
||||
// Validate
|
||||
_ = list.Capacity.Should().Be(32);
|
||||
_ = list.Should().HaveCount(testData.Length)
|
||||
.And.ContainInConsecutiveOrder(testData.Reverse())
|
||||
.And.BeEquivalentTo(testData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LongIndexOfShouldReturnCorrectIndexes()
|
||||
{
|
||||
// Prepare
|
||||
var testData = _testData.ToArray();
|
||||
var list = new RecyclableBlockList<int>(testData);
|
||||
|
||||
// Act & Validate
|
||||
foreach (var item in testData)
|
||||
{
|
||||
// Act
|
||||
var index = list.IndexOf(item);
|
||||
|
||||
// Validate
|
||||
_ = index.Should().Be(item - 1);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RemoveFromTheBeginningShouldRemoveTheCorrectItem()
|
||||
{
|
||||
// Prepare
|
||||
var testData = _testData.ToArray();
|
||||
var list = new RecyclableBlockList<int>(testData);
|
||||
|
||||
// Act & Validate
|
||||
for (var deleted = 1; deleted <= testData.LongLength; deleted++)
|
||||
{
|
||||
// Act
|
||||
_ = list.Remove(deleted).Should().BeTrue();
|
||||
|
||||
// Validate
|
||||
_ = list.Should().HaveCount(testData.Length - deleted)
|
||||
.And.ContainInConsecutiveOrder(testData.Skip(deleted))
|
||||
.And.BeEquivalentTo(testData.Skip(deleted));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RemoveFromTheEndShouldRemoveTheCorrectItem()
|
||||
{
|
||||
// Prepare
|
||||
var testData = _testData.ToArray();
|
||||
|
||||
// Act & Validate
|
||||
var list = new RecyclableBlockList<int>(testData);
|
||||
for (var deleted = 1; deleted <= testData.LongLength; deleted++)
|
||||
{
|
||||
// Act
|
||||
_ = list.Remove(testData[^deleted]).Should().BeTrue();
|
||||
|
||||
// Validate
|
||||
_ = list.Should().HaveCount(testData.Length - deleted)
|
||||
.And.ContainInConsecutiveOrder(testData.Take(testData.Length - deleted))
|
||||
.And.BeEquivalentTo(testData.Take(testData.Length - deleted));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RemoveAtFromTheBeginningShouldSucceed()
|
||||
{
|
||||
// Prepare
|
||||
var testData = _testData.ToArray();
|
||||
var list = new RecyclableBlockList<int>(testData);
|
||||
|
||||
// Act & Validate
|
||||
for (var deleted = 1; deleted <= testData.LongLength; deleted++)
|
||||
{
|
||||
// Act
|
||||
list.RemoveAt(0);
|
||||
|
||||
// Validate
|
||||
_ = list.Should().HaveCount(testData.Length - deleted)
|
||||
.And.ContainInConsecutiveOrder(testData.Skip(deleted))
|
||||
.And.BeEquivalentTo(testData.Skip(deleted));
|
||||
}
|
||||
|
||||
_ = list.Should().BeEmpty();
|
||||
_ = list.Capacity.Should().Be(32);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RemoveAtFromTheEndShouldSucceed()
|
||||
{
|
||||
// Prepare
|
||||
var testData = _testData.ToArray();
|
||||
var list = new RecyclableBlockList<int>(testData);
|
||||
|
||||
// Act & Validate
|
||||
for (var deleted = 1; deleted <= testData.LongLength; deleted++)
|
||||
{
|
||||
// Act
|
||||
list.RemoveAt(list.LongCount - 1);
|
||||
|
||||
// Validate
|
||||
_ = list.Should().HaveCount(testData.Length - deleted)
|
||||
.And.ContainInConsecutiveOrder(testData.Take(testData.Length - deleted))
|
||||
.And.BeEquivalentTo(testData.Take(testData.Length - deleted));
|
||||
}
|
||||
|
||||
_ = list.Should().BeEmpty();
|
||||
_ = list.Capacity.Should().Be(32);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ConstructorSourceShouldInitializeList()
|
||||
{
|
||||
// Prepare
|
||||
var testData = _testData.ToArray();
|
||||
|
||||
// Act
|
||||
var list = new RecyclableBlockList<int>(testData);
|
||||
|
||||
// Validate
|
||||
_ = list.Should().HaveCount(testData.Length)
|
||||
.And.ContainInConsecutiveOrder(testData)
|
||||
.And.BeEquivalentTo(testData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnumerateShouldYieldAllItemsInCorrectOrder()
|
||||
{
|
||||
// Prepare
|
||||
var testData = _testData.ToArray();
|
||||
var list = new RecyclableBlockList<int>(testData);
|
||||
|
||||
// Act
|
||||
var yieldedItems = new List<int>();
|
||||
foreach (var item in list)
|
||||
{
|
||||
yieldedItems.Add(item);
|
||||
}
|
||||
|
||||
// Validate
|
||||
_ = yieldedItems.Should().HaveCount(testData.Length)
|
||||
.And.ContainInConsecutiveOrder(testData)
|
||||
.And.BeEquivalentTo(testData);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@ using Recyclable.Collections;
|
||||
|
||||
namespace Recyclable.CollectionsTests
|
||||
{
|
||||
[TestClass()]
|
||||
public class RecyclableListTests
|
||||
{
|
||||
private const int _totalObjectCount = 5_000;
|
||||
@@ -11,7 +10,7 @@ namespace Recyclable.CollectionsTests
|
||||
private static readonly IEnumerable<int> _testData = Enumerable.Range(1, _totalObjectCount);
|
||||
private static RecyclableList<int> CreateReversedRecyclableList(IEnumerable<int> source) => new(source);
|
||||
|
||||
[TestMethod]
|
||||
[Fact]
|
||||
public void AddShouldAddItems()
|
||||
{
|
||||
// Prepare
|
||||
@@ -33,7 +32,7 @@ namespace Recyclable.CollectionsTests
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Fact]
|
||||
public void AddShouldAcceptDuplicates()
|
||||
{
|
||||
// Prepare
|
||||
@@ -51,7 +50,7 @@ namespace Recyclable.CollectionsTests
|
||||
_ = list.Should().BeEquivalentTo(testNumbers);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Fact]
|
||||
public void ConstructorShouldAcceptDuplicates()
|
||||
{
|
||||
// Prepare
|
||||
@@ -65,7 +64,7 @@ namespace Recyclable.CollectionsTests
|
||||
_ = list.Should().BeEquivalentTo(testNumbers);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Fact]
|
||||
public void InitializeSortClearShouldSucceed()
|
||||
{
|
||||
var expectedList = _testData;
|
||||
@@ -86,7 +85,7 @@ namespace Recyclable.CollectionsTests
|
||||
_ = list.LongCount.Should().Be(0);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Fact]
|
||||
public void CopyToShouldCopyAllItems()
|
||||
{
|
||||
// Prepare
|
||||
@@ -98,7 +97,7 @@ namespace Recyclable.CollectionsTests
|
||||
_ = actual.Should().BeEquivalentTo(_testData);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Fact]
|
||||
public void GetEnumeratorShouldYieldAllItems()
|
||||
{
|
||||
// Prepare
|
||||
@@ -116,7 +115,7 @@ namespace Recyclable.CollectionsTests
|
||||
_ = actual.Should().BeEquivalentTo(_testData);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Fact]
|
||||
public void IndexOfShouldFindTheIndexes()
|
||||
{
|
||||
// Prepare
|
||||
@@ -130,41 +129,37 @@ namespace Recyclable.CollectionsTests
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(NotSupportedException))]
|
||||
[Fact]
|
||||
public void InsertShouldRaiseNotSupportedException()
|
||||
{
|
||||
// Prepare
|
||||
using var list = NewRecyclableList;
|
||||
|
||||
// Act
|
||||
list.Insert(0, -1);
|
||||
_ = Assert.Throws<NotSupportedException>(() => list.Insert(0, -1));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(NotSupportedException))]
|
||||
[Fact]
|
||||
public void RemoveShouldRaiseNotSupportedException()
|
||||
{
|
||||
// Prepare
|
||||
using var list = NewRecyclableList;
|
||||
|
||||
// Act
|
||||
bool removed = list.Remove(_testData.First());
|
||||
_ = removed.Should().BeFalse();
|
||||
_ = Assert.Throws<NotSupportedException>(() => list.Remove(_testData.First()));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(NotSupportedException))]
|
||||
[Fact]
|
||||
public void RemoveAtShouldRaiseNotSupportedException()
|
||||
{
|
||||
// Prepare
|
||||
using var list = NewRecyclableList;
|
||||
|
||||
// Act
|
||||
list.RemoveAt(0);
|
||||
_ = Assert.Throws<NotSupportedException>(() => list.RemoveAt(0));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Fact]
|
||||
public void DisposeShouldSucceed()
|
||||
{
|
||||
// Prepare
|
||||
@@ -177,7 +172,7 @@ namespace Recyclable.CollectionsTests
|
||||
_ = list.LongCount.Should().Be(0L);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Fact]
|
||||
public void ConsecutiveDisposeShouldSucceed()
|
||||
{
|
||||
// Prepare
|
||||
|
||||
@@ -3,12 +3,11 @@ using Recyclable.Collections;
|
||||
|
||||
namespace Recyclable.CollectionsTests
|
||||
{
|
||||
[TestClass]
|
||||
public class RecyclableQueueTests
|
||||
{
|
||||
private static readonly string[] _testData = new[] { "a", "d", "c", "b", "a" };
|
||||
|
||||
[TestMethod]
|
||||
[Fact]
|
||||
public void ShouldNotBeSortedWhenCreated()
|
||||
{
|
||||
// Act
|
||||
@@ -19,7 +18,7 @@ namespace Recyclable.CollectionsTests
|
||||
.And.ContainInConsecutiveOrder(_testData);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Fact]
|
||||
public void ShouldBeEmptyWhenNotInitialized()
|
||||
{
|
||||
// Act
|
||||
@@ -29,7 +28,7 @@ namespace Recyclable.CollectionsTests
|
||||
_ = list.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Fact]
|
||||
public void ShouldNotBeSortedWhenInitialized()
|
||||
{
|
||||
// Act
|
||||
@@ -48,7 +47,7 @@ namespace Recyclable.CollectionsTests
|
||||
.And.BeEquivalentTo(_testData);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Fact]
|
||||
public void ShouldBeEmptyAfterClear()
|
||||
{
|
||||
// Prepare
|
||||
@@ -61,7 +60,7 @@ namespace Recyclable.CollectionsTests
|
||||
_ = list.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Fact]
|
||||
public void DequeueShouldReturnItemsInTheSameOrder()
|
||||
{
|
||||
// Prepare
|
||||
@@ -80,11 +79,11 @@ namespace Recyclable.CollectionsTests
|
||||
}
|
||||
|
||||
// Validate
|
||||
_ = dequeuedItems.Should().ContainInConsecutiveOrder(_testData);
|
||||
_ = dequeuedItems.Should().ContainInConsecutiveOrder(_testData)
|
||||
.And.BeEquivalentTo(_testData);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
[Fact]
|
||||
public void DequeueShoudRaiseArgumentOutOfRangeWhenNoMoreElementsFound()
|
||||
{
|
||||
// Prepare
|
||||
@@ -96,10 +95,11 @@ namespace Recyclable.CollectionsTests
|
||||
_ = list.Dequeue();
|
||||
}
|
||||
|
||||
_ = list.Dequeue();
|
||||
_ = Assert.Throws<ArgumentOutOfRangeException>(() => list.Dequeue());
|
||||
_ = list.LongCount.Should().Be(0);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Fact]
|
||||
public void GetEnumeratorShouldYieldAllItemsInTheSameOrder()
|
||||
{
|
||||
// Prepare
|
||||
@@ -114,7 +114,8 @@ namespace Recyclable.CollectionsTests
|
||||
}
|
||||
|
||||
// Validate
|
||||
_ = actual.Should().ContainInConsecutiveOrder(_testData);
|
||||
_ = actual.Should().ContainInConsecutiveOrder(_testData)
|
||||
.And.BeEquivalentTo(_testData);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,12 +3,11 @@ using Recyclable.Collections;
|
||||
|
||||
namespace Recyclable.CollectionsTests
|
||||
{
|
||||
[TestClass()]
|
||||
public class RecyclableSortedListTests
|
||||
{
|
||||
private static readonly (int, string)[] _testData = new[] { (5, "a"), (4, "d"), (3, "c"), (2, "b"), (1, "a") };
|
||||
|
||||
[TestMethod]
|
||||
[Fact]
|
||||
public void ShouldBeSortedWhenCreated()
|
||||
{
|
||||
// Act
|
||||
@@ -20,7 +19,7 @@ namespace Recyclable.CollectionsTests
|
||||
.And.BeInAscendingOrder((item) => item.Key);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Fact]
|
||||
public void ShouldBeEmptyWhenNotInitialized()
|
||||
{
|
||||
// Act
|
||||
@@ -30,7 +29,7 @@ namespace Recyclable.CollectionsTests
|
||||
_ = sortedList.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Fact]
|
||||
public void ShouldNotBeSortedWhenInitialized()
|
||||
{
|
||||
// Act
|
||||
@@ -48,7 +47,7 @@ namespace Recyclable.CollectionsTests
|
||||
.And.ContainInConsecutiveOrder(_testData);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Fact]
|
||||
public void ShouldBeSortedWhenUpdateEnds()
|
||||
{
|
||||
// Prepare
|
||||
@@ -71,7 +70,7 @@ namespace Recyclable.CollectionsTests
|
||||
_ = sortedList.Should().BeInAscendingOrder(x => x.Key);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Fact]
|
||||
public void ShouldBeEmptyAfterClear()
|
||||
{
|
||||
// Prepare
|
||||
|
||||
@@ -3,12 +3,11 @@ using Recyclable.Collections;
|
||||
|
||||
namespace Recyclable.CollectionsTests
|
||||
{
|
||||
[TestClass]
|
||||
public class RecyclableStackTests
|
||||
{
|
||||
private static readonly string[] _testData = new[] { "a", "d", "c", "b", "a" };
|
||||
|
||||
[TestMethod]
|
||||
[Fact]
|
||||
public void GetEnumeratorShouldYieldAllItemsInReversedOrder()
|
||||
{
|
||||
// Prepare
|
||||
@@ -26,7 +25,7 @@ namespace Recyclable.CollectionsTests
|
||||
_ = actual.Should().ContainInConsecutiveOrder(_testData.Reverse());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Fact]
|
||||
public void ShouldNotBeSortedWhenCreated()
|
||||
{
|
||||
// Act
|
||||
@@ -37,7 +36,7 @@ namespace Recyclable.CollectionsTests
|
||||
.And.ContainInConsecutiveOrder(_testData);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Fact]
|
||||
public void ShouldBeEmptyWhenNotInitialized()
|
||||
{
|
||||
// Act
|
||||
@@ -47,7 +46,7 @@ namespace Recyclable.CollectionsTests
|
||||
_ = sortedList.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Fact]
|
||||
public void ShouldNotBeSortedWhenInitialized()
|
||||
{
|
||||
// Act
|
||||
@@ -66,7 +65,7 @@ namespace Recyclable.CollectionsTests
|
||||
.And.BeEquivalentTo(_testData);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Fact]
|
||||
public void ShouldBeEmptyAfterClear()
|
||||
{
|
||||
// Prepare
|
||||
@@ -79,7 +78,7 @@ namespace Recyclable.CollectionsTests
|
||||
_ = sortedList.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Fact]
|
||||
public void PopShouldReturnItemsInReversedOrder()
|
||||
{
|
||||
// Prepare
|
||||
@@ -101,8 +100,7 @@ namespace Recyclable.CollectionsTests
|
||||
_ = dequeuedItems.Should().ContainInConsecutiveOrder(_testData.Reverse());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
[Fact]
|
||||
public void PopShoudRaiseArgumentOutOfRangeWhenNoMoreElementsFound()
|
||||
{
|
||||
// Prepare
|
||||
@@ -114,7 +112,7 @@ namespace Recyclable.CollectionsTests
|
||||
_ = list.Dequeue();
|
||||
}
|
||||
|
||||
_ = list.Dequeue();
|
||||
_ = Assert.Throws<ArgumentOutOfRangeException>(() => list.Dequeue());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
global using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
global using Xunit;
|
||||
Reference in new issue
Block a user