예제 #1
0
        public virtual void TestAddRemoveAdd()
        {
            BlockList <int> list = new BlockList <int>();

            for (int i = 0; i < BlockList <int> .BLOCK_SIZE + 1; i++)
            {
                list.AddItem(Sharpen.Extensions.ValueOf(i));
            }
            NUnit.Framework.Assert.AreEqual(Sharpen.Extensions.ValueOf(BlockList <int> .BLOCK_SIZE),
                                            list.Remove(list.Count - 1));
            NUnit.Framework.Assert.AreEqual(Sharpen.Extensions.ValueOf(BlockList <int> .BLOCK_SIZE -
                                                                       1), list.Remove(list.Count - 1));
            NUnit.Framework.Assert.IsTrue(list.AddItem(Sharpen.Extensions.ValueOf(1)));
            NUnit.Framework.Assert.AreEqual(Sharpen.Extensions.ValueOf(1), list[list.Count -
                                                                                1]);
        }
예제 #2
0
        public virtual void TestRemoveFromEnd()
        {
            BlockList <string> list      = new BlockList <string>(4);
            string             fooStr    = "foo";
            string             barStr    = "bar";
            string             foobarStr = "foobar";

            list.AddItem(fooStr);
            list.AddItem(barStr);
            list.AddItem(foobarStr);
            NUnit.Framework.Assert.AreSame(foobarStr, list.Remove(2));
            NUnit.Framework.Assert.AreEqual(2, list.Count);
            NUnit.Framework.Assert.AreSame(barStr, list.Remove(1));
            NUnit.Framework.Assert.AreEqual(1, list.Count);
            NUnit.Framework.Assert.AreSame(fooStr, list.Remove(0));
            NUnit.Framework.Assert.AreEqual(0, list.Count);
        }
예제 #3
0
        public virtual void TestRemoveRejectsBadIndexes()
        {
            BlockList <int> list = new BlockList <int>(4);

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