public void IndexOf() { var deque = new Deque<int>(new[] { 2, 3, 4, 5, 6 }); Assert.AreEqual(0, deque.IndexOf(2)); Assert.AreEqual(4, deque.IndexOf(6)); Assert.AreEqual(-1, deque.IndexOf(7)); deque = new Deque<int>(new[] { 2, 3, 4, 5, 6 }); deque.EnqueueHead(1); deque.EnqueueHead(0); Assert.AreEqual(0, deque.IndexOf(0)); Assert.AreEqual(2, deque.IndexOf(2)); Assert.AreEqual(6, deque.IndexOf(6)); Assert.AreEqual(-1, deque.IndexOf(7)); var deque2 = new Deque<string>(); deque2.EnqueueHead("item 1"); deque2.EnqueueHead(null); Assert.AreEqual(1, deque2.IndexOf("item 1")); Assert.AreEqual(0, deque2.IndexOf(null)); Assert.AreEqual(-1, deque2.IndexOf(String.Empty)); Assert.AreEqual(-1, deque2.IndexOf("item 2")); }
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)); }