예제 #1
0
        public void InsertMethodReturnAProperObject()
        {
            var pQueue = new PQueue();
            string key = "theKey";
            var pNode = pQueue.Insert(key);

            Assert.IsNotNull(pNode);
            Assert.AreEqual(pNode.Key, key);
        }
예제 #2
0
        private static PQueue CreatePriorityQueue(string baseKey, int numOfElements)
        {
            var pQueue = new PQueue();

            for (var i = 0; i < numOfElements; ++i)
            {
                pQueue.Insert(baseKey + ":" + (i + 1).ToString());
            }

            return pQueue;
        }
예제 #3
0
        public void IncreasePriorityWorksWithOneObject()
        {
            var pQueue = new PQueue();
            string key = "theKey";
            var createdNode = pQueue.Insert(key);
            int originalPriority = createdNode.Priority;
            pQueue.IncreasePriority(createdNode);
            var extractedNode = pQueue.Extract();

            Assert.IsTrue(extractedNode.Priority > originalPriority);
        }
예제 #4
0
        public void ExtractMethodReturnAProperObject()
        {
            var pQueue = new PQueue();
            string key = "theKey";
            var createdNode = pQueue.Insert(key);
            var extractedNode = pQueue.Extract();

            Assert.IsNotNull(extractedNode);
            Assert.AreEqual(createdNode.Key, extractedNode.Key);
            Assert.AreEqual(createdNode.Priority, extractedNode.Priority);
        }
예제 #5
0
        public void NodesAreExtractedInOrderOfLowerPriority2()
        {
            var pQueue = new PQueue();
            var node1 = pQueue.Insert("A:11");
            var node2 = pQueue.Insert("A:12");
            var node3 = pQueue.Insert("A:13");

            pQueue.IncreasePriority(node1);
            var extractedNodeA = pQueue.Extract();
            Assert.AreEqual(node2, extractedNodeA);

            pQueue.IncreasePriority(node3);
            var extractedNodeB = pQueue.Extract();
            Assert.AreEqual(node1, extractedNodeB);
        }
예제 #6
0
        public void CanRemoveSpecificNode()
        {
            var pQueue = new PQueue();
            var node1 = pQueue.Insert("A:11");
            var node2 = pQueue.Insert("A:12");
            var node3 = pQueue.Insert("A:13");

            pQueue.Remove(node2);

            var extractedNodeA = pQueue.Extract();
            Assert.AreEqual(node1, extractedNodeA);

            var extractedNodeB = pQueue.Extract();
            Assert.AreEqual(node3, extractedNodeB);

            Assert.IsTrue(pQueue.IsEmpty());
        }
예제 #7
0
    static void TestFunc(PriorityQueue.PQueue <TestThing> pq)
    {
        while (pq.Count > 5)
        {
            Console.Write(pq.Pop() + ", ");
        }
        Console.WriteLine(pq.Pop());

        pq.Push(new TestThing("", 8));
        pq.Push(new TestThing("", 2));
        pq.Remove(new TestThing("a", 7));
        pq.Push(new TestThing("", 6));
        pq.Push(new TestThing("", 4));

        while (pq.Count > 1)
        {
            Console.Write(pq.Pop() + ", ");
        }
        Console.WriteLine(pq.Pop());
        Console.WriteLine(HR);
    }
예제 #8
0
 public void CanCreateAnInstanceOfPQueue()
 {
     var pQueue = new PQueue();
     Assert.IsNotNull(pQueue);
 }