public void CopyTo() { int[] array = new int[5]; var deque = new Deque<int>(new[] { 2, 3, 4 }); deque.CopyTo(array, 2); Assert.AreEqual(0, array[0]); Assert.AreEqual(0, array[1]); Assert.AreEqual(2, array[2]); Assert.AreEqual(3, array[3]); Assert.AreEqual(4, array[4]); array = new int[5]; deque = new Deque<int>(); deque.EnqueueHead(3); deque.EnqueueHead(2); deque.EnqueueTail(4); deque.CopyTo(array, 2); Assert.AreEqual(0, array[0]); Assert.AreEqual(0, array[1]); Assert.AreEqual(2, array[2]); Assert.AreEqual(3, array[3]); Assert.AreEqual(4, array[4]); Assert.That(() => deque.CopyTo(null, 0), Throws.TypeOf<ArgumentNullException>()); Assert.That(() => deque.CopyTo(new int[5], -1), Throws.TypeOf<ArgumentOutOfRangeException>()); Assert.That(() => deque.CopyTo(new int[2], 0), Throws.TypeOf<ArgumentException>()); Assert.That(() => deque.CopyTo(new int[5], 5), Throws.TypeOf<ArgumentException>()); Assert.That(() => deque.CopyTo(new int[5], 4), Throws.TypeOf<ArgumentException>()); }
public void Clear() { var deque = new Deque<int>(new[] { 2, 3, 4, 5, 6 }); deque.Clear(); Assert.AreEqual(0, deque.Count); deque = new Deque<int>(new[] { 2, 3, 4, 5, 6 }); deque.EnqueueHead(1); deque.EnqueueHead(0); deque.Clear(); Assert.AreEqual(0, deque.Count); deque = new Deque<int>(); deque.EnqueueHead(1); deque.EnqueueHead(0); deque.Clear(); Assert.AreEqual(0, deque.Count); }
public void Contains() { var deque = new Deque<int>(new[] { 2, 3, 4, 5, 6 }); Assert.IsTrue(deque.Contains(2)); Assert.IsTrue(deque.Contains(6)); Assert.IsFalse(deque.Contains(7)); deque = new Deque<int>(new[] { 2, 3, 4, 5, 6 }); deque.EnqueueHead(1); deque.EnqueueHead(0); Assert.IsTrue(deque.Contains(0)); Assert.IsTrue(deque.Contains(6)); Assert.IsFalse(deque.Contains(7)); var deque2 = new Deque<string>(); deque2.EnqueueHead("item 1"); deque2.EnqueueHead(null); Assert.IsTrue(deque2.Contains("item 1")); Assert.IsTrue(deque2.Contains(null)); Assert.IsFalse(deque2.Contains(String.Empty)); Assert.IsFalse(deque2.Contains("item 2")); }
public void Tail() { var deque = new Deque<int>(); Assert.That(() => { int i = deque.Tail; }, Throws.TypeOf<InvalidOperationException>()); Assert.That(() => { deque.Tail = 0; }, Throws.TypeOf<InvalidOperationException>()); deque.EnqueueHead(123); Assert.AreEqual(123, deque.Tail); deque.EnqueueTail(234); Assert.AreEqual(234, deque.Tail); deque.EnqueueHead(345); Assert.AreEqual(234, deque.Tail); deque.Tail = 1; Assert.AreEqual(1, deque.Tail); deque.DequeueHead(); Assert.AreEqual(1, deque.Tail); deque.DequeueTail(); Assert.AreEqual(123, deque.Head); }
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 EnqueueDequeueTail() { var deque = new Deque<int>(); Assert.That(() => deque.DequeueTail(), Throws.TypeOf<InvalidOperationException>()); deque.EnqueueHead(1); Assert.AreEqual(1, deque.Count); Assert.AreEqual(1, deque.DequeueTail()); Assert.AreEqual(0, deque.Count); deque = new Deque<int>(new[] { 2, 3, 4 }); Assert.AreEqual(4, deque.DequeueTail()); deque.EnqueueTail(0); Assert.AreEqual(3, deque.Count); Assert.AreEqual(0, deque.DequeueTail()); Assert.AreEqual(2, deque.Count); }
public void Count() { var deque = new Deque<int>(); Assert.AreEqual(0, deque.Count); deque.EnqueueHead(1); deque.EnqueueHead(0); deque.EnqueueTail(2); deque.EnqueueTail(3); deque.EnqueueTail(4); deque.DequeueHead(); deque.DequeueTail(); Assert.AreEqual(3, deque.Count); deque.Clear(); Assert.AreEqual(0, deque.Count); }