diff --git a/Source/Collections/Deque.Test.cs b/Source/Collections/Deque.Test.cs
index 81be7fe..a5a52ef 100644
--- a/Source/Collections/Deque.Test.cs
+++ b/Source/Collections/Deque.Test.cs
@@ -122,7 +122,10 @@ namespace Nuclex.Support.Collections {
}
}
- /// Verifies that the Insert() method works in all cases
+ ///
+ /// Verifies that the Insert() method works in all cases when the deque doesn't
+ /// start at a block boundary
+ ///
[Test]
public void TestInsertNonNormalized() {
for(int testedIndex = 0; testedIndex <= 96; ++testedIndex) {
@@ -171,7 +174,10 @@ namespace Nuclex.Support.Collections {
}
}
- /// Verifies the the RemoveAt() method works in all cases
+ ///
+ /// Verifies the the RemoveAt() method works in all cases when the deque doesn't
+ /// start at a block boundary
+ ///
[Test]
public void TestRemoveAtNonNormalized() {
for(int testedIndex = 0; testedIndex < 96; ++testedIndex) {
@@ -196,6 +202,51 @@ namespace Nuclex.Support.Collections {
}
}
}
+
+ ///
+ /// Tests whether the RemoveAt() method keeps the state of the deque intact when
+ /// it has to remove a block from the left end of the deque
+ ///
+ [Test]
+ public void TestRemoveAtEmptiesLeftBlock() {
+ Deque intDeque = new Deque(16);
+ for(int item = 1; item <= 16; ++item) {
+ intDeque.AddLast(item);
+ }
+ intDeque.AddFirst(0);
+ intDeque.RemoveAt(3);
+
+ Assert.AreEqual(16, intDeque.Count);
+
+ for(int index = 0; index < 3; ++index) {
+ Assert.AreEqual(index, intDeque[index]);
+ }
+ for(int index = 3; index < 16; ++index) {
+ Assert.AreEqual(index + 1, intDeque[index]);
+ }
+ }
+
+ ///
+ /// Tests whether the RemoveAt() method keeps the state of the deque intact when
+ /// it has to remove a block from the right end of the deque
+ ///
+ [Test]
+ public void TestRemoveAtEmptiesRightBlock() {
+ Deque intDeque = new Deque(16);
+ for(int item = 0; item <= 16; ++item) {
+ intDeque.AddLast(item);
+ }
+ intDeque.RemoveAt(13);
+
+ Assert.AreEqual(16, intDeque.Count);
+
+ for(int index = 0; index < 13; ++index) {
+ Assert.AreEqual(index, intDeque[index]);
+ }
+ for(int index = 13; index < 16; ++index) {
+ Assert.AreEqual(index + 1, intDeque[index]);
+ }
+ }
///
/// Validates that an exception is thrown if the 'First' property is accessed
@@ -284,6 +335,22 @@ namespace Nuclex.Support.Collections {
/// Tests the IndexOf() method
[Test, TestCase(0), TestCase(16), TestCase(32), TestCase(48)]
public void TestIndexOf(int count) {
+ Deque intDeque = new Deque(16);
+ for(int item = 0; item < count; ++item) {
+ intDeque.AddLast(item);
+ }
+
+ for(int item = 0; item < count; ++item) {
+ Assert.AreEqual(item, intDeque.IndexOf(item));
+ }
+ Assert.AreEqual(-1, intDeque.IndexOf(count));
+ }
+
+ ///
+ /// Tests the IndexOf() method with the deque not starting at a block boundary
+ ///
+ [Test, TestCase(0), TestCase(16), TestCase(32), TestCase(48)]
+ public void TestIndexOfNonNormalized(int count) {
Deque intDeque = new Deque(16);
for(int item = 4; item < count; ++item) {
intDeque.AddLast(item);
@@ -293,7 +360,9 @@ namespace Nuclex.Support.Collections {
if(count > 1) { intDeque.AddFirst(1); }
if(count > 0) { intDeque.AddFirst(0); }
- Assert.AreEqual(count - 1, intDeque.IndexOf(count - 1));
+ for(int item = 0; item < count; ++item) {
+ Assert.AreEqual(item, intDeque.IndexOf(item));
+ }
Assert.AreEqual(-1, intDeque.IndexOf(count));
}
diff --git a/Source/Collections/Deque.cs b/Source/Collections/Deque.cs
index 72d5577..6bd1f30 100644
--- a/Source/Collections/Deque.cs
+++ b/Source/Collections/Deque.cs
@@ -110,7 +110,7 @@ namespace Nuclex.Support.Collections {
int lastBlock = this.blocks.Count - 1;
for(int tempIndex = 1; tempIndex < lastBlock; ++tempIndex) {
index = Array.IndexOf(
- this.blocks[1], item, 0, this.blockSize
+ this.blocks[tempIndex], item, 0, this.blockSize
);
if(index != -1) {
return (index - this.firstBlockStartIndex + tempIndex * this.blockSize);