Ejemplo n.º 1
0
        public virtual void TestAddSlowPath()
        {
            BlockList <string> list      = new BlockList <string>(4);
            string             fooStr    = "foo";
            string             barStr    = "bar";
            string             foobarStr = "foobar";
            string             firstStr  = "first";
            string             zeroStr   = "zero";

            list.AddItem(fooStr);
            list.AddItem(barStr);
            list.AddItem(foobarStr);
            NUnit.Framework.Assert.AreEqual(3, list.Count);
            list.Add(1, firstStr);
            NUnit.Framework.Assert.AreEqual(4, list.Count);
            NUnit.Framework.Assert.AreSame(fooStr, list[0]);
            NUnit.Framework.Assert.AreSame(firstStr, list[1]);
            NUnit.Framework.Assert.AreSame(barStr, list[2]);
            NUnit.Framework.Assert.AreSame(foobarStr, list[3]);
            list.Add(0, zeroStr);
            NUnit.Framework.Assert.AreEqual(5, list.Count);
            NUnit.Framework.Assert.AreSame(zeroStr, list[0]);
            NUnit.Framework.Assert.AreSame(fooStr, list[1]);
            NUnit.Framework.Assert.AreSame(firstStr, list[2]);
            NUnit.Framework.Assert.AreSame(barStr, list[3]);
            NUnit.Framework.Assert.AreSame(foobarStr, list[4]);
        }
Ejemplo n.º 2
0
        public virtual void TestAddToEnd()
        {
            BlockList <int> list = new BlockList <int>(4);
            int             cnt  = BlockList <int> .BLOCK_SIZE * 3;

            for (int i = 0; i < cnt; i++)
            {
                list.AddItem(Sharpen.Extensions.ValueOf(42 + i));
            }
            NUnit.Framework.Assert.AreEqual(cnt, list.Count);
            for (int i_1 = 0; i_1 < cnt; i_1++)
            {
                NUnit.Framework.Assert.AreEqual(Sharpen.Extensions.ValueOf(42 + i_1), list[i_1]);
            }
            list.Clear();
            NUnit.Framework.Assert.AreEqual(0, list.Count);
            NUnit.Framework.Assert.IsTrue(list.IsEmpty());
            for (int i_2 = 0; i_2 < cnt; i_2++)
            {
                list.Add(i_2, Sharpen.Extensions.ValueOf(42 + i_2));
            }
            NUnit.Framework.Assert.AreEqual(cnt, list.Count);
            for (int i_3 = 0; i_3 < cnt; i_3++)
            {
                NUnit.Framework.Assert.AreEqual(Sharpen.Extensions.ValueOf(42 + i_3), list[i_3]);
            }
        }
Ejemplo n.º 3
0
        public virtual void TestAddRejectsBadIndexes()
        {
            BlockList <int> list = new BlockList <int>(4);

            list.AddItem(Sharpen.Extensions.ValueOf(41));
            try
            {
                list.Add(-1, Sharpen.Extensions.ValueOf(42));
            }
            catch (IndexOutOfRangeException badIndex)
            {
                NUnit.Framework.Assert.AreEqual((-1).ToString(), badIndex.Message);
            }
            try
            {
                list.Add(4, Sharpen.Extensions.ValueOf(42));
            }
            catch (IndexOutOfRangeException badIndex)
            {
                NUnit.Framework.Assert.AreEqual(4.ToString(), badIndex.Message);
            }
        }