Performance & standardization improvements.
Business logic fixes. RecyclableQueue & RecyclableStack added - pending improvements.
This commit is contained in:
1 parent
4e5835b20e
commit
aba28028b1
17 files changed
+1269
-190
No files matched your search
@@ -25,7 +25,7 @@ namespace Recyclable.CollectionsTests
|
||||
}
|
||||
|
||||
// Validate
|
||||
_ = list.Count.Should().Be(itemsCount, "we added so many items");
|
||||
_ = list.LongCount.Should().Be(itemsCount, "we added so many items");
|
||||
for (var index = 0; index < itemsCount; index++)
|
||||
{
|
||||
var actual = list[index];
|
||||
@@ -76,7 +76,6 @@ namespace Recyclable.CollectionsTests
|
||||
|
||||
// Validate
|
||||
_ = list.LongCount.Should().Be(_totalObjectCount);
|
||||
_ = list.Count.Should().Be(_totalObjectCount);
|
||||
_ = list.Should().Equal(expectedList);
|
||||
_ = expectedList.Should().AllSatisfy(expected => list.Contains(expected));
|
||||
|
||||
@@ -85,7 +84,6 @@ namespace Recyclable.CollectionsTests
|
||||
|
||||
// Validate
|
||||
_ = list.LongCount.Should().Be(0);
|
||||
_ = list.Count.Should().Be(0);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -95,7 +93,7 @@ namespace Recyclable.CollectionsTests
|
||||
using var list = NewRecyclableList;
|
||||
|
||||
// Act
|
||||
var actual = new int[list.Count];
|
||||
var actual = new int[list.LongCount];
|
||||
list.CopyTo(actual, 0);
|
||||
_ = actual.Should().BeEquivalentTo(_testData);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
using FluentAssertions;
|
||||
using Recyclable.Collections;
|
||||
|
||||
namespace Recyclable.CollectionsTests
|
||||
{
|
||||
[TestClass]
|
||||
public class RecyclableQueueTests
|
||||
{
|
||||
private static readonly string[] _testData = new[] { "a", "d", "c", "b", "a" };
|
||||
|
||||
[TestMethod]
|
||||
public void ShouldNotBeSortedWhenCreated()
|
||||
{
|
||||
// Act
|
||||
using var list = new RecyclableQueue<string>(_testData, 2);
|
||||
|
||||
// Validate
|
||||
_ = list.Should().HaveCount(_testData.Length)
|
||||
.And.ContainInConsecutiveOrder(_testData);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ShouldBeEmptyWhenNotInitialized()
|
||||
{
|
||||
// Act
|
||||
using var list = new RecyclableQueue<string>(2);
|
||||
|
||||
// Validate
|
||||
_ = list.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ShouldNotBeSortedWhenInitialized()
|
||||
{
|
||||
// Act
|
||||
using var list = new RecyclableQueue<string>(2)
|
||||
{
|
||||
_testData[0],
|
||||
_testData[1],
|
||||
_testData[2],
|
||||
_testData[3],
|
||||
_testData[4]
|
||||
};
|
||||
|
||||
// Validate
|
||||
_ = list.Should().NotBeEmpty()
|
||||
.And.ContainInConsecutiveOrder(_testData)
|
||||
.And.BeEquivalentTo(_testData);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ShouldBeEmptyAfterClear()
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableQueue<string>(_testData);
|
||||
|
||||
// Act
|
||||
list.Clear();
|
||||
|
||||
// Validate
|
||||
_ = list.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DequeueShouldReturnItemsInTheSameOrder()
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableQueue<string>();
|
||||
|
||||
// Act
|
||||
for (var itemIdx = 0; itemIdx < _testData.Length; itemIdx++)
|
||||
{
|
||||
list.Enqueue(_testData[itemIdx]);
|
||||
}
|
||||
|
||||
var dequeuedItems = new RecyclableList<string>();
|
||||
while (list.LongCount > 0)
|
||||
{
|
||||
dequeuedItems.Add(list.Dequeue());
|
||||
}
|
||||
|
||||
// Validate
|
||||
_ = dequeuedItems.Should().ContainInConsecutiveOrder(_testData);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public void DequeueShoudRaiseArgumentOutOfRangeWhenNoMoreElementsFound()
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableQueue<string>(_testData);
|
||||
|
||||
// Act
|
||||
while (list.LongCount > 0)
|
||||
{
|
||||
_ = list.Dequeue();
|
||||
}
|
||||
|
||||
_ = list.Dequeue();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GetEnumeratorShouldYieldAllItemsInTheSameOrder()
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableQueue<string>(_testData);
|
||||
|
||||
// Act
|
||||
var actual = new RecyclableList<string>();
|
||||
var enumerator = list.GetEnumerator();
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
actual.Add(enumerator.Current);
|
||||
}
|
||||
|
||||
// Validate
|
||||
_ = actual.Should().ContainInConsecutiveOrder(_testData);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ namespace Recyclable.CollectionsTests
|
||||
public void ShouldBeSortedWhenCreated()
|
||||
{
|
||||
// Act
|
||||
using var sortedList = new RecyclableSortedList<int, string>(_testData);
|
||||
using var sortedList = new RecyclableSortedList<int, string>(_testData, 2);
|
||||
|
||||
// Validate
|
||||
_ = sortedList.Should().HaveCount(_testData.Length)
|
||||
@@ -24,17 +24,17 @@ namespace Recyclable.CollectionsTests
|
||||
public void ShouldBeEmptyWhenNotInitialized()
|
||||
{
|
||||
// Act
|
||||
using var sortedList = new RecyclableSortedList<int, string>();
|
||||
using var sortedList = new RecyclableSortedList<int, string>(2);
|
||||
|
||||
// Validate
|
||||
_ = sortedList.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ShouldBeSortedWhenInitialized()
|
||||
public void ShouldNotBeSortedWhenInitialized()
|
||||
{
|
||||
// Act
|
||||
using var sortedList = new RecyclableSortedList<int, string>()
|
||||
using var sortedList = new RecyclableSortedList<int, string>(2)
|
||||
{
|
||||
_testData[0],
|
||||
_testData[1],
|
||||
@@ -45,15 +45,14 @@ namespace Recyclable.CollectionsTests
|
||||
|
||||
// Validate
|
||||
_ = sortedList.Should().NotBeEmpty()
|
||||
.And.BeInAscendingOrder(x => x.Key)
|
||||
.And.BeEquivalentTo(_testData);
|
||||
.And.ContainInConsecutiveOrder(_testData);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ShouldBeSortedWhenUpdateEnds()
|
||||
{
|
||||
// Prepare
|
||||
using var sortedList = new RecyclableSortedList<int, string>();
|
||||
using var sortedList = new RecyclableSortedList<int, string>(2);
|
||||
|
||||
// Act
|
||||
sortedList.BeginUpdate();
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
using FluentAssertions;
|
||||
using Recyclable.Collections;
|
||||
|
||||
namespace Recyclable.CollectionsTests
|
||||
{
|
||||
[TestClass]
|
||||
public class RecyclableStackTests
|
||||
{
|
||||
private static readonly string[] _testData = new[] { "a", "d", "c", "b", "a" };
|
||||
|
||||
[TestMethod]
|
||||
public void GetEnumeratorShouldYieldAllItemsInReversedOrder()
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableStack<string>(_testData);
|
||||
|
||||
// Act
|
||||
var actual = new RecyclableList<string>();
|
||||
var enumerator = list.GetEnumerator();
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
actual.Add(enumerator.Current);
|
||||
}
|
||||
|
||||
// Validate
|
||||
_ = actual.Should().ContainInConsecutiveOrder(_testData.Reverse());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ShouldNotBeSortedWhenCreated()
|
||||
{
|
||||
// Act
|
||||
using var sortedList = new RecyclableStack<string>(_testData, 2);
|
||||
|
||||
// Validate
|
||||
_ = sortedList.Should().HaveCount(_testData.Length)
|
||||
.And.ContainInConsecutiveOrder(_testData);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ShouldBeEmptyWhenNotInitialized()
|
||||
{
|
||||
// Act
|
||||
using var sortedList = new RecyclableStack<string>(2);
|
||||
|
||||
// Validate
|
||||
_ = sortedList.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ShouldNotBeSortedWhenInitialized()
|
||||
{
|
||||
// Act
|
||||
using var sortedList = new RecyclableStack<string>(2)
|
||||
{
|
||||
_testData[0],
|
||||
_testData[1],
|
||||
_testData[2],
|
||||
_testData[3],
|
||||
_testData[4]
|
||||
};
|
||||
|
||||
// Validate
|
||||
_ = sortedList.Should().NotBeEmpty()
|
||||
.And.ContainInConsecutiveOrder(_testData)
|
||||
.And.BeEquivalentTo(_testData);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ShouldBeEmptyAfterClear()
|
||||
{
|
||||
// Prepare
|
||||
using var sortedList = new RecyclableStack<string>(_testData);
|
||||
|
||||
// Act
|
||||
sortedList.Clear();
|
||||
|
||||
// Validate
|
||||
_ = sortedList.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void PopShouldReturnItemsInReversedOrder()
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableStack<string>();
|
||||
|
||||
// Act
|
||||
for (var itemIdx = 0; itemIdx < _testData.Length; itemIdx++)
|
||||
{
|
||||
list.Push(_testData[itemIdx]);
|
||||
}
|
||||
|
||||
var dequeuedItems = new RecyclableList<string>();
|
||||
while (list.LongCount > 0)
|
||||
{
|
||||
dequeuedItems.Add(list.Pop());
|
||||
}
|
||||
|
||||
// Validate
|
||||
_ = dequeuedItems.Should().ContainInConsecutiveOrder(_testData.Reverse());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public void PopShoudRaiseArgumentOutOfRangeWhenNoMoreElementsFound()
|
||||
{
|
||||
// Prepare
|
||||
using var list = new RecyclableQueue<string>(_testData);
|
||||
|
||||
// Act
|
||||
while (list.LongCount > 0)
|
||||
{
|
||||
_ = list.Dequeue();
|
||||
}
|
||||
|
||||
_ = list.Dequeue();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user