Beispiel #1
0
        public void Range()
        {
            Deque <int> main  = new Deque <int>(new int[] { 0, 1, 2, 3, 4, 5, 6, 7 });
            IList <int> range = main.Range(2, 4);

            InterfaceTests.TestListGeneric(range, new int[] { 2, 3, 4, 5 }, null);

            main     = new Deque <int>(new int[] { 0, 1, 2, 3, 4, 5, 6, 7 });
            range    = main.Range(2, 4);
            range[1] = 7;
            range.Add(99);
            Assert.AreEqual(5, range.Count);
            range.RemoveAt(0);
            Assert.AreEqual(4, range.Count);
            InterfaceTests.TestEnumerableElements(main, new int[] { 0, 1, 7, 4, 5, 99, 6, 7 });
            main[3] = 11;
            InterfaceTests.TestEnumerableElements(range, new int[] { 7, 11, 5, 99 });

            main  = new Deque <int>(new int[] { 0, 1, 2, 3, 4, 5, 6, 7 });
            range = main.Range(5, 3);
            Assert.AreEqual(3, range.Count);
            main.Remove(6);
            main.Remove(5);
            Assert.AreEqual(1, range.Count);
            Assert.AreEqual(7, range[0]);

            main  = new Deque <int>(new int[] { 0, 1, 2, 3, 4, 5, 6, 7 });
            range = main.Range(8, 0);
            range.Add(8);
            range.Add(9);
            InterfaceTests.TestEnumerableElements(main, new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });
            InterfaceTests.TestEnumerableElements(range, new int[] { 8, 9 });

            main  = new Deque <int>(new int[] { 0, 1, 2, 3, 4, 5, 6, 7 });
            range = main.Range(0, 4);
            range.Clear();
            Assert.AreEqual(0, range.Count);
            InterfaceTests.TestEnumerableElements(main, new int[] { 4, 5, 6, 7 });
            range.Add(100);
            range.Add(101);
            InterfaceTests.TestEnumerableElements(main, new int[] { 100, 101, 4, 5, 6, 7 });

            main  = new Deque <int>(new int[] { 0, 1, 2, 3, 4, 5, 6, 7 });
            range = main.Range(8, 0);
            InterfaceTests.TestListGeneric(range, new int[] { }, null);
        }
        public void Clone()
        {
            Deque <int> deque1, deque2, deque3, deque4;

            deque1 = new Deque <int>();
            deque2 = deque1.Clone();
            deque3 = (Deque <int>)(((ICloneable)deque1).Clone());
            deque4 = new Deque <int>(deque1);
            InterfaceTests.TestListGeneric <int>(deque2, new int[0], null);
            InterfaceTests.TestListGeneric <int>(deque3, new int[0], null);
            InterfaceTests.TestListGeneric <int>(deque4, new int[0], null);
            deque1.Add(5);
            InterfaceTests.TestListGeneric <int>(deque2, new int[0], null);
            InterfaceTests.TestListGeneric <int>(deque3, new int[0], null);
            InterfaceTests.TestListGeneric <int>(deque4, new int[0], null);

            int[] array = new int[100];
            for (int i = 0; i < 100; ++i)
            {
                array[i] = i;
            }
            deque1.Clear();
            for (int i = 63; i < 100; ++i)
            {
                deque1.AddToBack(i);
            }
            for (int i = 62; i >= 0; --i)
            {
                deque1.AddToFront(i);
            }
            deque2 = deque1.Clone();
            deque3 = (Deque <int>)(((ICloneable)deque1).Clone());
            deque4 = new Deque <int>(deque1);
            InterfaceTests.TestListGeneric <int>(deque2, array, null);
            InterfaceTests.TestListGeneric <int>(deque3, array, null);
            InterfaceTests.TestListGeneric <int>(deque4, array, null);
            deque4.Clear();
            InterfaceTests.TestListGeneric <int>(deque1, array, null);
            InterfaceTests.TestListGeneric <int>(deque2, array, null);
            InterfaceTests.TestListGeneric <int>(deque3, array, null);
        }