예제 #1
0
        public void EnumerateTest()
        {
            var slimDeque    = new SlimDeque <Int32>();
            var frontNumbers = Enumerable.Range(0, 15);
            var backNumbers  = Enumerable.Range(42, 15);

            foreach (var frontNumber in frontNumbers)
            {
                slimDeque.EnqueueFront(frontNumber);
            }
            foreach (var backNumber in backNumbers)
            {
                slimDeque.EnqueueBack(backNumber);
            }
            var enumerateNumbers    = frontNumbers.Reverse().Concat(backNumbers);
            var slimDequeEnumerated = new List <Int32>(slimDeque.Count);

            foreach (var x in slimDeque)
            {
                slimDequeEnumerated.Add(x);
            }
            Assert.True(enumerateNumbers.SequenceEqual(slimDequeEnumerated));
            var slimDequeReverseEnumerated = new List <Int32>(slimDeque.Count);

            foreach (var x in slimDeque.Reverse())
            {
                slimDequeReverseEnumerated.Add(x);
            }
            Assert.True(enumerateNumbers.Reverse().SequenceEqual(slimDequeReverseEnumerated));
        }
예제 #2
0
        private static void Helper2(Int32[] a, Int32[] b)
        {
            var slimDeque = new SlimDeque <Int32>();

            for (var i = 0; i != a.Length; i++)
            {
                slimDeque.EnqueueFront(a[i]);
                Assert.Equal(i + 1, slimDeque.Count);
            }

            for (var i = 0; i != a.Length; i++)
            {
                slimDeque.DequeueFront();
                //Assert.Equal(i + 1, slimDeque.Count);
            }

            for (var i = 0; i != b.Length; i++)
            {
                slimDeque.EnqueueBack(b[i]);
                Assert.Equal(i + a.Length + 1, slimDeque.Count);
            }

            for (var i = 0; i != b.Length; i++)
            {
                slimDeque.DequeueBack();
            }
        }
예제 #3
0
        public void EmptySlimDequeExceptionTests()
        {
            var slimDeque = new SlimDeque <Int32>();

            Assert.Throws <EmptySlimDequeException>(() => slimDeque.DequeueFront());
            Assert.ThrowsAny <InvalidOperationException>(() => slimDeque.DequeueFront());
            Assert.Throws <EmptySlimDequeException>(() => slimDeque.DequeueBack());
            Assert.ThrowsAny <InvalidOperationException>(() => slimDeque.DequeueBack());

            slimDeque = new SlimDeque <Int32>();
            slimDeque.EnqueueFront(1);
            Assert.Equal(1, slimDeque.DequeueFront());

            slimDeque = new SlimDeque <Int32>();
            slimDeque.EnqueueBack(1);
            Assert.Equal(1, slimDeque.DequeueBack());
        }