示例#1
0
        public virtual void TestGet()
        {
            int NumElems = 100001;
            ChunkedArrayList <int> list = new ChunkedArrayList <int>();

            for (int i = 0; i < NumElems; i++)
            {
                list.AddItem(i);
            }
            Assert.Equal(Extensions.ValueOf(100), list[100]);
            Assert.Equal(Extensions.ValueOf(1000), list[1000]);
            Assert.Equal(Extensions.ValueOf(10000), list[10000]);
            Assert.Equal(Extensions.ValueOf(100000), list[100000]);
            IEnumerator <int> iter = list.GetEnumerator();

            iter.Next();
            iter.Remove();
            Assert.Equal(Extensions.ValueOf(1), list[0]);
            iter = list.GetEnumerator();
            for (int i_1 = 0; i_1 < 500; i_1++)
            {
                iter.Next();
            }
            iter.Remove();
            Assert.Equal(Extensions.ValueOf(502), list[500]);
            Assert.Equal(Extensions.ValueOf(602), list[600]);
        }
示例#2
0
        public virtual void TestRemovals()
        {
            int NumElems = 100000;
            ChunkedArrayList <int> list = new ChunkedArrayList <int>();

            for (int i = 0; i < NumElems; i++)
            {
                list.AddItem(i);
            }
            // Iterate through all list elements.
            IEnumerator <int> iter = list.GetEnumerator();

            for (int i_1 = 0; i_1 < NumElems; i_1++)
            {
                Assert.True(iter.HasNext());
                int val = iter.Next();
                Assert.Equal(Extensions.ValueOf(i_1), val);
            }
            NUnit.Framework.Assert.IsFalse(iter.HasNext());
            Assert.Equal(NumElems, list.Count);
            // Remove even elements.
            iter = list.GetEnumerator();
            for (int i_2 = 0; i_2 < NumElems; i_2++)
            {
                Assert.True(iter.HasNext());
                int val = iter.Next();
                Assert.Equal(Extensions.ValueOf(i_2), val);
                if (i_2 % 2 == 0)
                {
                    iter.Remove();
                }
            }
            NUnit.Framework.Assert.IsFalse(iter.HasNext());
            Assert.Equal(NumElems / 2, list.Count);
            // Iterate through all odd list elements.
            iter = list.GetEnumerator();
            for (int i_3 = 0; i_3 < NumElems / 2; i_3++)
            {
                Assert.True(iter.HasNext());
                int val = iter.Next();
                Assert.Equal(Extensions.ValueOf(1 + (2 * i_3)), val);
                iter.Remove();
            }
            NUnit.Framework.Assert.IsFalse(iter.HasNext());
            // Check that list is now empty.
            Assert.Equal(0, list.Count);
            Assert.True(list.IsEmpty());
            iter = list.GetEnumerator();
            NUnit.Framework.Assert.IsFalse(iter.HasNext());
        }