Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        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]);
                }
            }
        }
Exemplo n.º 3
0
        /// <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);
        }
Exemplo n.º 4
0
        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]); }
                );
        }
Exemplo n.º 5
0
        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]);
            }
        }
Exemplo n.º 6
0
        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));
        }
Exemplo n.º 7
0
        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();
            }
        }
Exemplo n.º 8
0
        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]);
            }
        }