public void PriorityQueueFillAndEmpty() { List <PriorityQueueNode> nodesToEnqueue = new List <PriorityQueueNode>() { new Node(new NodeData(uniqueKey: 0.ToString(), name: "A"), priority: 3), new Node(new NodeData(uniqueKey: 1.ToString(), name: "B"), priority: 2), new Node(new NodeData(uniqueKey: 2.ToString(), name: "C"), priority: 1), }; PriorityQueue pq = PriorityQueueFactory.CreatePriorityQueue(); foreach (Node node in nodesToEnqueue) { pq.Enqueue(node); } int expectedCount = pq.Count(); Assert.AreEqual(expectedCount, nodesToEnqueue.Count); int expectedPriority = 1; while (pq.Count() > 0) { PriorityQueueNode peek = pq.Peek(); PriorityQueueNode n = pq.Dequeue(); Assert.AreEqual(peek.Data.UniqueKey, n.Data.UniqueKey); Assert.AreEqual(n.Priority, expectedPriority); expectedPriority++; expectedCount--; Assert.AreEqual(pq.Count(), expectedCount); } }
public void InsertInRandomOrder_RemoveInOrder() { IPriorityQueue <int> priorityQueue = PriorityQueueFactory <int> .CreatePriorityQueue(HeapType.MIN, 4); priorityQueue.Insert(3); priorityQueue.Insert(2); priorityQueue.Insert(1); priorityQueue.Insert(5); priorityQueue.Insert(4); priorityQueue.Insert(10); priorityQueue.Insert(8); priorityQueue.Insert(7); Queue <int> queue = new Queue <int>(); queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); queue.Enqueue(4); queue.Enqueue(5); queue.Enqueue(7); queue.Enqueue(8); queue.Enqueue(10); while (!priorityQueue.IsEmpty()) { var item = priorityQueue.Remove(); var itemExpected = queue.Dequeue(); Assert.AreEqual(item, itemExpected); } }
public void Insert_Check_Size() { IPriorityQueue <int> priorityQueue = PriorityQueueFactory <int> .CreatePriorityQueue(HeapType.MIN); priorityQueue.Insert(2); priorityQueue.Insert(1); priorityQueue.Insert(3); priorityQueue.Insert(10); Assert.True(priorityQueue.Size() == SizeOfQueue); }
public void InsertMoreThanInitialSize_CapacityDoubled() { IPriorityQueue <int> priorityQueue = PriorityQueueFactory <int> .CreatePriorityQueue(HeapType.MIN, 4); priorityQueue.Insert(1); priorityQueue.Insert(2); priorityQueue.Insert(3); priorityQueue.Insert(4); priorityQueue.Insert(5); Assert.True(priorityQueue.Capacity() == CapacityDouble); }
public void InsertThanRemove_CheckIsEmpty() { IPriorityQueue <int> priorityQueue = PriorityQueueFactory <int> .CreatePriorityQueue(HeapType.MIN, 4); priorityQueue.Insert(3); priorityQueue.Insert(2); priorityQueue.Insert(1); priorityQueue.Insert(5); priorityQueue.Remove(); priorityQueue.Remove(); priorityQueue.Remove(); priorityQueue.Remove(); Assert.True(priorityQueue.IsEmpty()); }
public void PriorityQueueVerifyFIFOChangePriority() { List <PriorityQueueNode> nodesToEnqueue = new List <PriorityQueueNode>() { new Node(new NodeData(uniqueKey: 0.ToString(), name: "11"), priority: 1), new Node(new NodeData(uniqueKey: 1.ToString(), name: "21"), priority: 2), new Node(new NodeData(uniqueKey: 2.ToString(), name: "12"), priority: 1), new Node(new NodeData(uniqueKey: 3.ToString(), name: "22"), priority: 2), new Node(new NodeData(uniqueKey: 4.ToString(), name: "13"), priority: 1), }; PriorityQueue pq = PriorityQueueFactory.CreatePriorityQueue(); foreach (Node node in nodesToEnqueue) { pq.Enqueue(node); } int expectedCount = pq.Count(); Assert.AreEqual(expectedCount, nodesToEnqueue.Count); pq.ChangePriority(nodeUniqueKey: 0.ToString(), priority: 3); Assert.AreEqual(expectedCount, nodesToEnqueue.Count); int[] expectedPriorities = { 1, 1, 2, 2, 3 }; string[] expectedUniqueKeys = new List <int>() { 2, 4, 1, 3, 0 }. Select(uk => uk.ToString()).ToArray(); int i = 0; while (pq.Count() > 0) { PriorityQueueNode n = pq.Dequeue(); Assert.AreEqual(n.Priority, expectedPriorities[i]); Assert.AreEqual(n.Data.UniqueKey, expectedUniqueKeys[i]); expectedCount--; Assert.AreEqual(pq.Count(), expectedCount); i++; } }
public void EmptyPriorityQueueChangePriorityException() { PriorityQueue pq = PriorityQueueFactory.CreatePriorityQueue(); pq.ChangePriority(0.ToString(), 0); }
public void EmptyPriorityQueuePeekException() { PriorityQueue pq = PriorityQueueFactory.CreatePriorityQueue(); pq.Peek(); }
public void EmptyPriorityQueueDequeueException() { PriorityQueue pq = PriorityQueueFactory.CreatePriorityQueue(); pq.Dequeue(); }
public void EmptyPriorityQueueCountZero() { PriorityQueue pq = PriorityQueueFactory.CreatePriorityQueue(); Assert.AreEqual(pq.Count(), 0); }