本文整理汇总了C#中System.Collections.Generic.PriorityQueue.ToArray方法的典型用法代码示例。如果您正苦于以下问题:C# PriorityQueue.ToArray方法的具体用法?C# PriorityQueue.ToArray怎么用?C# PriorityQueue.ToArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Generic.PriorityQueue
的用法示例。
在下文中一共展示了PriorityQueue.ToArray方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestBasicFunctionality
public void TestBasicFunctionality()
{
var q = new PriorityQueue<int>();
Assert.AreEqual(0, q.Count);
Assert.AreEqual(0, q.Capacity);
Assert.Throws<InvalidOperationException>(() => q.Peek());
Assert.Throws<InvalidOperationException>(() => q.Dequeue());
q.Enqueue(5);
q.Enqueue(2);
q.Enqueue(4);
Assert.AreEqual(3, q.Count);
Assert.IsTrue(q.Capacity >= 3);
Assert.IsTrue(q.Contains(2));
Assert.IsFalse(q.Contains(3));
Assert.AreEqual(3, q.ToArray().Length);
CollectionAssert.AreEqual(q.ToArray(), q);
Assert.AreEqual(2, q.Peek());
Assert.AreEqual(2, q.Dequeue());
Assert.AreEqual(4, q.Dequeue());
Assert.AreEqual(5, q.Dequeue());
}
示例2: Interfaces
public void Interfaces()
{
var pq = new PriorityQueue<int>(new int[] { 8, 4, 3, 1, 2 });
var icoll = (System.Collections.ICollection)pq;
var expected = new int[5];
icoll.CopyTo(expected, 0);
Assert.AreEqual(expected, pq.ToArray());
}
示例3: TestDuplication
public void TestDuplication()
{
var numbers = new [] { -1, -1, -1, 1, 1, 2, 3, 9, 20, 15, 11 }.ToList();
var queue = new PriorityQueue<int>(1, Comparer<int>.Create((x, y) => x - y));
numbers.ForEach(queue.Offer);
Assert.AreEqual(-1, queue.ToArray()[0]);
queue = new PriorityQueue<int>(3, Comparer<int>.Create((x, y) => x - y));
numbers.ForEach(queue.Offer);
queue.ToList().ForEach(x => Assert.AreEqual(-1, x));
queue = new PriorityQueue<int>(4, Comparer<int>.Create((x, y) => x - y));
numbers.ForEach(queue.Offer);
Assert.AreEqual(1, queue.OrderBy(x => x).Last());
queue = new PriorityQueue<int>(100, Comparer<int>.Create((x, y) => x - y));
numbers.ForEach(queue.Offer);
Assert.AreEqual(20, queue.OrderBy(x => x).Last());
}
示例4: ToArrayTest
public void ToArrayTest()
{
PriorityQueue<int> queue = new PriorityQueue<int> { 12, 6, 3, 1, 0, 8 };
int[] expected = { 0, 1, 6, 12, 3, 8 };
int[] actual = queue.ToArray();
CollectionAssert.AreEqual(expected, actual);
}
示例5: ToArrayTest
public void ToArrayTest([PexAssumeUnderTest]List<int> elemList)
{
PriorityQueue<int> queue = new PriorityQueue<int>(elemList);
elemList.Sort();
int[] actual = queue.ToArray();
PexObserve.ValueForViewing<int[]>("Actual", queue.ToArray());
CollectionAssert.AreEquivalent(elemList, queue);
}
示例6: GetEnumeratorTest
public void GetEnumeratorTest([PexAssumeUnderTest]List<int> elemList)
{
PriorityQueue<int> actual = new PriorityQueue<int>(elemList, Strategy.Max);
PexObserve.ValueForViewing<int[]>("Actual", actual.ToArray());
//CollectionAssert.AreEqual(elemList.ToArray(), actual.ToArray());
}