public void InsertMethodReturnAProperObject() { var pQueue = new PQueue(); string key = "theKey"; var pNode = pQueue.Insert(key); Assert.IsNotNull(pNode); Assert.AreEqual(pNode.Key, key); }
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; }
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); }
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); }
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); }
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()); }
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); }
public void CanCreateAnInstanceOfPQueue() { var pQueue = new PQueue(); Assert.IsNotNull(pQueue); }