Пример #1
0
        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>());
        }
Пример #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);
        }
Пример #3
0
        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);
        }
Пример #4
0
        public void Enumerator()
        {
            var deque = new Deque<int>(new[] { 2, 3, 4 });
              Assert.IsNotNull(((IEnumerable<int>)deque).GetEnumerator());
              Assert.IsNotNull(((IEnumerable)deque).GetEnumerator());

              Deque<int>.Enumerator enumerator = deque.GetEnumerator();
              Assert.AreEqual(0, enumerator.Current);
              Assert.That(() => ((IEnumerator)enumerator).Current, Throws.TypeOf<InvalidOperationException>());

              Assert.IsTrue(enumerator.MoveNext());
              Assert.AreEqual(2, enumerator.Current);
              Assert.AreEqual(2, ((IEnumerator)enumerator).Current);
              Assert.IsTrue(enumerator.MoveNext());
              Assert.AreEqual(3, enumerator.Current);
              Assert.AreEqual(3, ((IEnumerator)enumerator).Current);
              Assert.IsTrue(enumerator.MoveNext());
              Assert.AreEqual(4, enumerator.Current);
              Assert.AreEqual(4, ((IEnumerator)enumerator).Current);
              Assert.IsFalse(enumerator.MoveNext());
              Assert.AreEqual(0, enumerator.Current);
              Assert.That(() => ((IEnumerator)enumerator).Current, Throws.TypeOf<InvalidOperationException>());

              enumerator.Reset();
              Assert.IsTrue(enumerator.MoveNext());
              Assert.AreEqual(2, enumerator.Current);

              enumerator.Dispose();
              Assert.AreEqual(0, enumerator.Current);
              Assert.IsFalse(enumerator.MoveNext());
              Assert.That(() => ((IEnumerator)enumerator).Current, Throws.TypeOf<InvalidOperationException>());

              enumerator = deque.GetEnumerator();
              enumerator.MoveNext();
              deque.EnqueueTail(5);
              Assert.That(() => enumerator.MoveNext(), Throws.TypeOf<InvalidOperationException>());
              Assert.That(() => enumerator.Reset(), Throws.TypeOf<InvalidOperationException>());
        }
Пример #5
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);
        }