本文整理汇总了C#中Deque.ToArray方法的典型用法代码示例。如果您正苦于以下问题:C# Deque.ToArray方法的具体用法?C# Deque.ToArray怎么用?C# Deque.ToArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Deque
的用法示例。
在下文中一共展示了Deque.ToArray方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: TestInsert
public void TestInsert()
{
Deque<int> test = new Deque<int>(10);
test.Add(0);
test.Add(1);
test.Add(2);
test.Add(3);
test.Add(4);
test.Add(5);
test.Add(6);
test.Add(7);
test.Add(8);
test.Add(9);
test.RemoveAt(0);
test.RemoveAt(0);
test.Insert(3, 7);
test.Insert(3, 8);
CollectionAssert.AreEqual(test.ToArray(), new int[] { 2, 3, 4, 8, 7, 5, 6, 7, 8, 9 });
Assert.AreEqual(test.Count, 10);
}
示例3: TestRemoveAt
public void TestRemoveAt()
{
Deque<int> test = new Deque<int>(6);
test.Add(0);
test.Add(1);
test.Add(2);
test.Add(3);
test.Add(4);
test.Add(5);
test.PopFront();
test.PopFront();
test.Add(6);
test.Add(7);
test.RemoveAt(2);
int[] arr = test.ToArray();
CollectionAssert.AreEqual(arr, new int[] { 2, 3, 5, 6, 7 });
Assert.AreEqual(test.Count, 5);
}
示例4: TestToArray
private static void TestToArray(Deque deque)
{
deque.Clear();
PopulateDequePushBack(deque);
object[] array = deque.ToArray();
int i = 0;
foreach(object obj in deque)
{
System.Diagnostics.Debug.Assert(obj.Equals(array[i]));
i++;
}
}
示例5: TestToArray
private static void TestToArray(Deque<int> deque)
{
deque.Clear();
PopulateDequePushBack(deque);
int[] array = deque.ToArray();
int i = 0;
foreach(int item in deque)
{
Debug.Assert(item.Equals(array[i]));
i++;
}
}
示例6: ToArrayTest
public void ToArrayTest()
{
Deque<int> actual = new Deque<int> { 123, 324, 12, 90, 23 };
int[] expected = { 123, 324, 12, 90, 23 };
CollectionAssert.AreEqual(expected, actual.ToArray());
}
示例7: TestRemoveAndTrim
public void TestRemoveAndTrim()
{
var d = new Deque<int>(4);
Assert.IsTrue(d.Count == 0);
Assert.IsTrue(d.Capacity == 4);
d.AddLast(0);
d.AddLast(1);
d.AddLast(2);
d.AddLast(3);
d.AddLast(4);
d.AddLast(5);
Assert.IsTrue(d.Count == 6);
Assert.IsTrue(d.Capacity == 8);
d.RemoveLast();
d.RemoveLast();
d.RemoveLast();
Assert.IsTrue(d.Count == 3);
Assert.IsTrue(d.Capacity == 8);
d.TrimExcess();
Assert.IsTrue(d.Count == 3);
Assert.IsTrue(d.Capacity == 3);
var arr = d.ToArray();
var exp = new int[] { 0, 1, 2 };
Assert.IsTrue(arr.Length == exp.Length);
for (int i = 0; i < arr.Length; i++) {
Assert.IsTrue(arr[i] == exp[i]);
}
}
示例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]);
}
}
示例9: ToArrayPUT
public void ToArrayPUT([PexAssumeUnderTest]int[] values)
{
Deque<int> actual = new Deque<int>(values);
CollectionAssert.AreEqual(values, actual.ToArray());
}