Exemple #1
0
        private void DequeOperations(IDeque <string> deque)
        {
            var lastPrepend = string.Empty;
            var lastAppend  = string.Empty;
            var testNumber  = 10000;

            for (var i = 0; i < testNumber; i++)
            {
                lastPrepend = Guid.NewGuid().ToString();
                lastAppend  = Guid.NewGuid().ToString();
                deque.Prepend(lastPrepend);
                deque.Append(lastAppend);
            }
            Assert.Equal(testNumber * 2, deque.Count);
            Assert.Equal(lastPrepend, deque.First);
            Assert.Equal(lastAppend, deque.Last);
            Assert.Equal(lastPrepend, deque.Shift());
            Assert.Equal(testNumber * 2 - 1, deque.Count);
            Assert.Equal(lastAppend, deque.Pop());
            Assert.Equal(testNumber * 2 - 2, deque.Count);

            for (var i = 0; i < (testNumber * 2 - 2); i++)
            {
                Assert.False(string.IsNullOrEmpty(deque.Pop()));
            }
            Assert.Equal(0, deque.Count);
        }
Exemple #2
0
 private void DequeExceptions(IDeque <int> deque)
 {
     Assert.Throws(typeof(InvalidOperationException), () => deque.Pop());
     Assert.Throws(typeof(InvalidOperationException), () => deque.Shift());
     Assert.Throws(typeof(InvalidOperationException), () => deque.First);
     Assert.Throws(typeof(InvalidOperationException), () => deque.Last);
 }
Exemple #3
0
        private void DequePrependAndPop(IDeque <int> deque)
        {
            for (var i = 0; i < 100000; i++)
            {
                deque.Prepend(i);
            }

            for (var i = 0; i < 100000; i++)
            {
                Assert.Equal(99999, deque.First);
                Assert.Equal(i, deque.Last);
                Assert.Equal(i, deque.Pop());
            }
            Assert.Equal(0, deque.Count);
        }
Exemple #4
0
        private void DequeAppendAndPop(IDeque <int> deque)
        {
            for (var i = 0; i < 100000; i++)
            {
                deque.Append(i);
            }

            for (var i = 100000; i > 0; i--)
            {
                Assert.Equal(0, deque.First);
                Assert.Equal(i - 1, deque.Last);
                Assert.Equal(i - 1, deque.Pop());
            }
            Assert.Equal(0, deque.Count);
        }