Exemplo n.º 1
0
        public void Test_CompareTo()
        {
            MyDeque <int> deq = new MyDeque <int>();

            deq.EnqueueLast(1);
            deq.EnqueueLast(2);
            deq.EnqueueLast(3);
            deq.EnqueueLast(4);

            MyDeque <int> deq2 = new MyDeque <int>();

            deq2.EnqueueFirst(2);
            deq2.EnqueueFirst(2);

            Assert.AreEqual(deq.CompareTo(deq2), 1);

            deq2.EnqueueFirst(2);
            deq2.EnqueueFirst(2);

            Assert.AreEqual(deq.CompareTo(deq2), 0);

            deq2.EnqueueFirst(2);
            deq2.EnqueueFirst(2);

            Assert.AreEqual(deq.CompareTo(deq2), -1);
        }
Exemplo n.º 2
0
        public void Test_PeekLast()
        {
            MyDeque <int> deq = new MyDeque <int>();

            deq.EnqueueLast(1);
            deq.EnqueueLast(2);
            deq.EnqueueLast(3);
            deq.EnqueueLast(4);
            Assert.AreEqual(deq.PeekLast(), 4);
        }
Exemplo n.º 3
0
        public void Test_EnqueueLast()
        {
            MyDeque <int> deq = new MyDeque <int>();

            deq.EnqueueLast(1);
            deq.EnqueueLast(2);
            deq.EnqueueLast(3);
            deq.EnqueueLast(4);
            Assert.AreEqual(deq.Count, 4);
            Assert.AreNotEqual(deq.PeekFirst(), deq.PeekLast());
        }
Exemplo n.º 4
0
        public void Test_Clone()
        {
            MyDeque <int> deq1 = new MyDeque <int>();
            MyDeque <int> deq2 = new MyDeque <int>();

            deq1.EnqueueLast(1);
            deq1.EnqueueLast(2);
            deq1.EnqueueLast(3);
            deq1.EnqueueLast(4);

            deq2 = (MyDeque <int>)deq1.Clone();

            Assert.AreEqual(deq1.Count, deq2.Count);
            Assert.AreEqual(deq1.PeekLast(), deq2.PeekLast());
        }
Exemplo n.º 5
0
        public void Test_DequeueLast()
        {
            MyDeque <int> deq = new MyDeque <int>();

            deq.EnqueueLast(1);
            deq.EnqueueLast(2);
            deq.EnqueueLast(3);
            deq.EnqueueLast(4);
            int expected = deq.PeekLast();
            int count1   = deq.Count;
            int actual   = deq.DequeueLast();
            int count2   = deq.Count;

            Assert.AreEqual(actual, expected);
            Assert.AreNotEqual(count1, count2);
        }
Exemplo n.º 6
0
        public void Test_GetEnumerator()
        {
            MyDeque <int> deq = new MyDeque <int>();

            deq.EnqueueLast(1);
            deq.EnqueueLast(2);
            deq.EnqueueLast(3);
            deq.EnqueueLast(4);

            int[] numbers = new int[deq.Count];

            foreach (int i in deq)
            {
                for (int n = 0; n < numbers.Length; n++)
                {
                    numbers[n] = i;
                }
            }

            Assert.AreEqual(deq.PeekLast(), numbers[deq.Count - 1]);
        }