当前位置: 首页>>代码示例>>C#>>正文


C# PriorityQueue.ToArray方法代码示例

本文整理汇总了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());
        }
开发者ID:GHScan,项目名称:DailyProjects,代码行数:27,代码来源:PriorityQueueTest.cs

示例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());
        }
开发者ID:sq,项目名称:Fracture,代码行数:9,代码来源:PriorityQueueTests.cs

示例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());
        }
开发者ID:jthelin,项目名称:SparkCLR,代码行数:20,代码来源:PriorityQueueTest.cs

示例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);
        }
开发者ID:robertrancz,项目名称:dsa,代码行数:9,代码来源:PriorityQueueTest.cs

示例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);
 }
开发者ID:taoxiease,项目名称:asegrp,代码行数:8,代码来源:PriorityQueueTest.cs

示例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());
 }
开发者ID:taoxiease,项目名称:asegrp,代码行数:6,代码来源:PriorityQueueTest.cs


注:本文中的System.Collections.Generic.PriorityQueue.ToArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。