public void TestAddLast() { Deque<int> intDeque = new Deque<int>(16); for(int item = 0; item < 48; ++item) { intDeque.AddLast(item); } for(int item = 0; item < 48; ++item) { Assert.AreEqual(item, intDeque[item]); } }
public void TestRemoveLast() { Deque<int> intDeque = new Deque<int>(16); for(int item = 0; item < 48; ++item) { intDeque.AddLast(item); } for(int item = 0; item < 48; ++item) { Assert.AreEqual(47 - item, intDeque.Last); Assert.AreEqual(48 - item, intDeque.Count); intDeque.RemoveLast(); } }
/// <summary>Creates a deque filled with the specified number of items /// </summary> /// <param name="count">Number of items the deque will be filled with</param> /// <returns>The newly created deque</returns> private static Deque<int> createDeque(int count) { Deque<int> intDeque = new Deque<int>(16); for(int item = 0; item < count; ++item) { intDeque.AddLast(item); } return intDeque; }
/// <summary> /// Creates a deque whose first element does not coincide with a block boundary /// </summary> /// <param name="count">Number of items the deque will be filled with</param> /// <returns>The newly created deque</returns> private static Deque<int> createNonNormalizedDeque(int count) { Deque<int> intDeque = new Deque<int>(16); for(int item = 4; item < count; ++item) { intDeque.AddLast(item); } if(count > 3) { intDeque.AddFirst(3); } if(count > 2) { intDeque.AddFirst(2); } if(count > 1) { intDeque.AddFirst(1); } if(count > 0) { intDeque.AddFirst(0); } return intDeque; }
public void TestIndexOf(int count) { Deque<int> intDeque = new Deque<int>(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)); }
public void TestThrowOnInvalidIndex() { Deque<int> intDeque = new Deque<int>(16); for(int item = 0; item < 32; ++item) { intDeque.AddLast(item); } Assert.Throws<ArgumentOutOfRangeException>( delegate() { Console.WriteLine(intDeque[32]); } ); }
public void TestRemoveAtEmptiesRightBlock() { Deque<int> intDeque = new Deque<int>(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]); } }
public void TestRemoveAtNonNormalized() { for(int testedIndex = 0; testedIndex < 96; ++testedIndex) { Deque<int> intDeque = new Deque<int>(16); for(int item = 4; item < 96; ++item) { intDeque.AddLast(item); } intDeque.AddFirst(3); intDeque.AddFirst(2); intDeque.AddFirst(1); intDeque.AddFirst(0); intDeque.RemoveAt(testedIndex); Assert.AreEqual(95, intDeque.Count); for(int index = 0; index < testedIndex; ++index) { Assert.AreEqual(index, intDeque[index]); } for(int index = testedIndex; index < 95; ++index) { Assert.AreEqual(index + 1, intDeque[index]); } } }