Пример #1
0
        public void Remove_RangeOfZeroElements_HasNoEffect()
        {
            var deque = new Deque <int>(new[] { 1, 2, 3 });

            deque.RemoveRange(1, 0);
            Assert.AreEqual(new[] { 1, 2, 3 }, deque);
        }
Пример #2
0
        public void Remove_NegativeCount_ActsLikeList()
        {
            var list = new List <int>(new[] { 1, 2, 3 });

            Assert.Throws <ArgumentOutOfRangeException>(() => list.RemoveRange(1, -1));

            var deque = new Deque <int>(new[] { 1, 2, 3 });

            Assert.Throws <ArgumentOutOfRangeException>(() => deque.RemoveRange(1, -1));
        }
Пример #3
0
        private void RemoveTest(IReadOnlyCollection <int> initial)
        {
            for (int count = 0; count <= initial.Count; ++count)
            {
                for (int rotated = 0; rotated <= initial.Count; ++rotated)
                {
                    for (int index = 0; index <= initial.Count - count; ++index)
                    {
                        // Calculated the expected result using the slower List<int>.
                        var result = new List <int>(initial);
                        for (int i = 0; i != rotated; ++i)
                        {
                            var item = result[0];
                            result.RemoveAt(0);
                            result.Add(item);
                        }
                        result.RemoveRange(index, count);

                        // First, start off the deque with the initial items.
                        var deque = new Deque <int>(initial);

                        // Rotate the existing items.
                        for (int i = 0; i != rotated; ++i)
                        {
                            var item = deque[0];
                            deque.RemoveFromFront();
                            deque.AddToBack(item);
                        }

                        // Do the remove.
                        deque.RemoveRange(index, count);

                        // Ensure the results are as expected.
                        Assert.AreEqual(result, deque);
                    }
                }
            }
        }