本文整理汇总了C#中BlockList.AddItem方法的典型用法代码示例。如果您正苦于以下问题:C# BlockList.AddItem方法的具体用法?C# BlockList.AddItem怎么用?C# BlockList.AddItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BlockList
的用法示例。
在下文中一共展示了BlockList.AddItem方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestAddRejectsBadIndexes
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);
}
}
示例2: TestGet
public virtual void TestGet()
{
BlockList<string> list = new BlockList<string>(4);
string b;
try
{
b = list[-1];
}
catch (IndexOutOfRangeException badIndex)
{
NUnit.Framework.Assert.AreEqual((-1).ToString(), badIndex.Message);
}
try
{
b = list[0];
}
catch (IndexOutOfRangeException badIndex)
{
NUnit.Framework.Assert.AreEqual(0.ToString(), badIndex.Message);
}
try
{
b = list[4];
}
catch (IndexOutOfRangeException badIndex)
{
NUnit.Framework.Assert.AreEqual(4.ToString(), badIndex.Message);
}
string fooStr = "foo";
string barStr = "bar";
string foobarStr = "foobar";
list.AddItem(fooStr);
list.AddItem(barStr);
list.AddItem(foobarStr);
NUnit.Framework.Assert.AreSame(fooStr, list[0]);
NUnit.Framework.Assert.AreSame(barStr, list[1]);
NUnit.Framework.Assert.AreSame(foobarStr, list[2]);
try
{
b = list[3];
}
catch (IndexOutOfRangeException badIndex)
{
NUnit.Framework.Assert.AreEqual(3.ToString(), badIndex.Message);
}
}
示例3: TestFastIterator
public virtual void TestFastIterator()
{
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);
Iterator<int> itr = list.Iterator();
for (int i_1 = 0; i_1 < cnt; i_1++)
{
NUnit.Framework.Assert.IsTrue(itr.HasNext());
NUnit.Framework.Assert.AreEqual(Sharpen.Extensions.ValueOf(42 + i_1), itr.Next());
}
NUnit.Framework.Assert.IsFalse(itr.HasNext());
}
示例4: TestAddAllFromOtherList
public virtual void TestAddAllFromOtherList()
{
BlockList<int> src = new BlockList<int>(4);
int cnt = BlockList<int>.BLOCK_SIZE * 2;
for (int i = 0; i < cnt; i++)
{
src.AddItem(Sharpen.Extensions.ValueOf(42 + i));
}
src.AddItem(Sharpen.Extensions.ValueOf(1));
BlockList<int> dst = new BlockList<int>(4);
dst.AddItem(Sharpen.Extensions.ValueOf(255));
dst.AddAll(src);
NUnit.Framework.Assert.AreEqual(cnt + 2, dst.Count);
for (int i_1 = 0; i_1 < cnt; i_1++)
{
NUnit.Framework.Assert.AreEqual(Sharpen.Extensions.ValueOf(42 + i_1), dst[i_1 + 1
]);
}
NUnit.Framework.Assert.AreEqual(Sharpen.Extensions.ValueOf(1), dst[dst.Count - 1]
);
}
示例5: TestAddRemoveAdd
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]);
}
示例6: TestRemoveSlowPath
public virtual void TestRemoveSlowPath()
{
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(barStr, list.Remove(1));
NUnit.Framework.Assert.AreEqual(2, list.Count);
NUnit.Framework.Assert.AreSame(fooStr, list[0]);
NUnit.Framework.Assert.AreSame(foobarStr, list[1]);
NUnit.Framework.Assert.AreSame(fooStr, list.Remove(0));
NUnit.Framework.Assert.AreEqual(1, list.Count);
NUnit.Framework.Assert.AreSame(foobarStr, list[0]);
NUnit.Framework.Assert.AreSame(foobarStr, list.Remove(0));
NUnit.Framework.Assert.AreEqual(0, list.Count);
}
示例7: TestAddSlowPath
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]);
}
示例8: TestAddToEnd
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]);
}
}