Exemple #1
0
        public void EnqueueDequeueHead()
        {
            var deque = new Deque<int>();
              Assert.That(() => deque.DequeueHead(), Throws.TypeOf<InvalidOperationException>());
              deque.EnqueueHead(1);
              Assert.AreEqual(1, deque.Count);
              Assert.AreEqual(1, deque.DequeueHead());
              Assert.AreEqual(0, deque.Count);

              deque = new Deque<int>(new[] { 2, 3, 4 });
              Assert.AreEqual(2, deque.DequeueHead());
              deque.EnqueueHead(0);
              Assert.AreEqual(3, deque.Count);
              Assert.AreEqual(0, deque.DequeueHead());
              Assert.AreEqual(2, deque.Count);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        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);
        }