本文整理汇总了C#中Deque.AddFirst方法的典型用法代码示例。如果您正苦于以下问题:C# Deque.AddFirst方法的具体用法?C# Deque.AddFirst怎么用?C# Deque.AddFirst使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Deque
的用法示例。
在下文中一共展示了Deque.AddFirst方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestAddAndGrow
public void TestAddAndGrow()
{
var d = new Deque<int>(0);
Assert.IsTrue(d.Count == 0);
Assert.IsTrue(d.Capacity == 0);
d.AddFirst(1);
Assert.IsTrue(d.Count == 1);
Assert.IsTrue(d.Capacity == 4);
d.AddFirst(0);
Assert.IsTrue(d.Count == 2);
Assert.IsTrue(d.Capacity == 4);
d.AddLast(2);
d.AddLast(3);
Assert.IsTrue(d.Count == 4);
Assert.IsTrue(d.Capacity == 4);
d.AddLast(4);
Assert.IsTrue(d.Count == 5);
Assert.IsTrue(d.Capacity == 8);
var arr = d.ToArray();
var exp = new int[] { 0, 1, 2, 3, 4 };
Assert.IsTrue(arr.Length == exp.Length);
for (int i = 0; i < arr.Length; i++) {
Assert.IsTrue(arr[i] == exp[i]);
}
}
示例2: Remove_element_should_decrease_size
public void Remove_element_should_decrease_size()
{
// arrange
var deque = new Deque<string>();
deque.AddFirst("Item");
deque.AddFirst("Item2");
// act
deque.RemoveFirst();
deque.RemoveLast();
// assert
Assert.AreEqual(0, deque.Size());
}
示例3: Given_null_item_add_should_throw_NullPointerException
public void Given_null_item_add_should_throw_NullPointerException()
{
// arrange
var deque = new Deque<string>();
// act
// assert
Assert.Throws<NullReferenceException>(() => deque.AddFirst(null));
Assert.Throws<NullReferenceException>(() => deque.AddLast(null));
}
示例4: BulletPool
public BulletPool()
{
_bulletDeque = new Deque<Bullet>(POOL_SIZE);
//Initialize the pool.
for (int i = 0; i < POOL_SIZE; i++)
{
_bulletDeque.AddFirst(new Bullet(GameContent.Assets.Images.Ships.Bullets[ShipType.BattleCruiser, ShipTier.Tier1], Vector2.Zero, GameScreen.World, null));
}
}
示例5: Add_element_should_increment_size
public void Add_element_should_increment_size()
{
// arrange
var deque = new Deque<string>();
// act
deque.AddFirst("Item");
deque.AddLast("Item2");
// assert
Assert.AreEqual(2, deque.Size());
}
示例6: AdvancedTestDequeFirst
public void AdvancedTestDequeFirst()
{
var deque = new Deque<String>();
var items = new List<string>
{
"0",
"1",
"2",
"-",
"-",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
};
Assert.AreEqual(0, deque.Size);
Assert.IsTrue(deque.IsEmpty);
foreach (var item in items)
{
if (item != "-")
{
deque.AddFirst(item);
}
else
{
if (!deque.IsEmpty)
{
deque.RemoveFirst();
}
}
}
var builder = new StringBuilder();
foreach (var item in deque)
{
builder.Append(item);
}
Assert.AreEqual("98765430", builder.ToString());
Assert.AreEqual(8, deque.Size);
Assert.IsFalse(deque.IsEmpty);
while (!deque.IsEmpty)
{
deque.RemoveFirst();
}
Assert.AreEqual(0, deque.Size);
Assert.IsTrue(deque.IsEmpty);
}
示例7: Remove_item_should_return_last_added_item
public void Remove_item_should_return_last_added_item()
{
// arrange
var deque = new Deque<string>();
deque.AddLast("LastItem");
deque.AddFirst("Item");
// act
var actual = deque.RemoveFirst();
var actualLast = deque.RemoveLast();
// assert
Assert.AreEqual("Item", actual);
Assert.AreEqual("LastItem", actualLast);
}
示例8: TestValuesAndWrapAround
public void TestValuesAndWrapAround()
{
var d = new Deque<int>(4);
d.AddLast(1); // internally it contains [H:1, 2, 3, 4]
d.AddLast(2);
d.AddLast(3);
d.AddLast(4);
Assert.IsTrue(d.PeekFirst() == 1 & d.PeekLast() == 4);
d.RemoveFirst();
d.RemoveLast(); // now it's [0, H:2, 3, 0]
Assert.IsTrue(d.Count == 2 && d.Capacity == 4);
Assert.IsTrue(d.PeekFirst() == 2 & d.PeekLast() == 3);
d.AddLast(4);
d.RemoveFirst(); // now it's [0, 0, H:3, 4]
Assert.IsTrue(d.Count == 2 && d.Capacity == 4);
Assert.IsTrue(d.PeekFirst() == 3 & d.PeekLast() == 4);
d.AddLast(5);
d.RemoveFirst(); // now it's [5, 0, 0, H:4]
Assert.IsTrue(d.Count == 2 && d.Capacity == 4);
Assert.IsTrue(d.PeekFirst() == 4 & d.PeekLast() == 5);
d.AddFirst(3);
d.AddFirst(2); // now it's [5, H:2, 3, 4]
Assert.IsTrue(d.Count == 4 && d.Capacity == 4);
Assert.IsTrue(d.PeekFirst() == 2 & d.PeekLast() == 5);
d.AddFirst(1); // reallocated to [H:1, 2, 3, 4, 5, 0, 0, 0]
d.AddFirst(0); // now it's [1, 2, 3, 4, 5, 0, 0, H:0]
Assert.IsTrue(d.Count == 6 && d.Capacity == 8);
Assert.IsTrue(d.PeekFirst() == 0 & d.PeekLast() == 5);
var arr = d.ToArray();
var exp = new int[] { 0, 1, 2, 3, 4, 5 };
Assert.IsTrue(arr.Length == exp.Length);
for (int i = 0; i < arr.Length; i++) {
Assert.IsTrue(arr[i] == exp[i]);
}
}