Exemple #1
0
        public void TestPriorityQueueWithBuildHeapOperation()
        {
            GraphPriorityQueue pq = new GraphPriorityQueue();

            pq.addFreely(new Path(new Vertex(""), 50));
            Assert.IsTrue("50".Equals(pq.PrintPreorder()));
            pq.addFreely(new Path(new Vertex(""), 25));
            Assert.IsTrue("50 25".Equals(pq.PrintPreorder()));
            pq.addFreely(new Path(new Vertex(""), 40));
            Assert.IsTrue("50 25 40".Equals(pq.PrintPreorder()));
            pq.addFreely(new Path(new Vertex(""), 60));
            Assert.IsTrue("50 25 40 60".Equals(pq.PrintPreorder()));
            pq.addFreely(new Path(new Vertex(""), 30));
            Assert.IsTrue("50 25 40 60 30".Equals(pq.PrintPreorder()));
            pq.BuildHeap();
            Assert.IsTrue("25 30 40 60 50".Equals(pq.PrintPreorder()));
        }
Exemple #2
0
        public void TestPriorityQueueFindMinAfterSeveralOperations()
        {
            GraphPriorityQueue pq = new GraphPriorityQueue();

            pq.addFreely(new Path(new Vertex(""), 50));
            Assert.IsTrue("50".Equals(pq.PrintPreorder()));
            pq.addFreely(new Path(new Vertex(""), 25));
            Assert.IsTrue("50 25".Equals(pq.PrintPreorder()));
            pq.addFreely(new Path(new Vertex(""), 40));
            Assert.IsTrue("50 25 40".Equals(pq.PrintPreorder()));
            pq.addFreely(new Path(new Vertex(""), 60));
            Assert.IsTrue("50 25 40 60".Equals(pq.PrintPreorder()));
            pq.addFreely(new Path(new Vertex(""), 30));
            Assert.IsTrue("50 25 40 60 30".Equals(pq.PrintPreorder()));
            pq.BuildHeap();
            Assert.IsTrue("25 30 40 60 50".Equals(pq.PrintPreorder()));
            Assert.AreEqual(25, pq.Element().cost);
            pq.Remove();
            Assert.AreEqual(30, pq.Element().cost);
            Assert.IsTrue("30 50 40 60".Equals(pq.PrintPreorder()));
            pq.Remove();
            Assert.AreEqual(40, pq.Element().cost);
            Assert.IsTrue("40 50 60".Equals(pq.PrintPreorder()));
        }