Esempio n. 1
0
        public virtual void TestBasics()
        {
            int NElems = 100000;
            ChunkedArrayList <int> l = new ChunkedArrayList <int>();

            Assert.True(l.IsEmpty());
            // Insert a bunch of elements.
            for (int i = 0; i < NElems; i++)
            {
                l.AddItem(i);
            }
            NUnit.Framework.Assert.IsFalse(l.IsEmpty());
            Assert.Equal(NElems, l.Count);
            // Check that it got chunked.
            Assert.True(l.GetNumChunks() > 10);
            Assert.Equal(8192, l.GetMaxChunkSize());
        }
Esempio n. 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());
        }