public void MinPriorityQueueEnumerationYieldsHighestPriorityAsLastItem() { var priorityQueue = new MinPriorityQueue <string, int>(50); List <Tuple <string, int> > items = new List <Tuple <string, int> > { new Tuple <string, int>("A_50", 50), new Tuple <string, int>("A_41", 41), new Tuple <string, int>("A_38", 38), new Tuple <string, int>("A_37", 37), new Tuple <string, int>("A_23", 23), new Tuple <string, int>("A_11", 11), new Tuple <string, int>("A_5", 5), new Tuple <string, int>("A_3", 3), }.Randomize() .ToList(); priorityQueue.EnqueueRange(items); List <string> list = new List <string>(); foreach (string s in priorityQueue) { list.Add(s); } Assert.AreEqual("A_50", list.Last()); }
public void MinPriorityQueueDoesNotInsertItemToHeadIfItemIsHigherPriorityThanHead() { var priorityQueue = new MinPriorityQueue <string, int>(50); List <Tuple <string, int> > items = new List <Tuple <string, int> > { new Tuple <string, int>("A_50", 50), new Tuple <string, int>("A_41", 41), new Tuple <string, int>("A_38", 38), new Tuple <string, int>("A_37", 37), new Tuple <string, int>("A_23", 23), new Tuple <string, int>("A_11", 11), new Tuple <string, int>("A_5", 5), new Tuple <string, int>("A_3", 3), }.Randomize() .ToList(); priorityQueue.EnqueueRange(items); string originalHead = priorityQueue.Peek(); priorityQueue.Enqueue("A_4", 4); string newHead = priorityQueue.Peek(); Assert.AreEqual("A_3", originalHead); Assert.AreEqual("A_3", newHead); }
public void MinPriorityQueueMovesNextLowestPriorityItemToHeadAfterRemoveItem() { var priorityQueue = new MinPriorityQueue <string, int>(50); List <Tuple <string, int> > items = new List <Tuple <string, int> > { new Tuple <string, int>("A_50", 50), new Tuple <string, int>("A_41", 41), new Tuple <string, int>("A_38", 38), new Tuple <string, int>("A_37", 37), new Tuple <string, int>("A_23", 23), new Tuple <string, int>("A_11", 11), new Tuple <string, int>("A_5", 5), new Tuple <string, int>("A_3", 3), }.Randomize() .ToList(); priorityQueue.EnqueueRange(items); priorityQueue.Dequeue(); string item = priorityQueue.Peek(); Assert.AreEqual("A_5", item); }
public void MinQueueAddItemsWithSize() { var queue = new MinPriorityQueue <string, int>(Number); queue.EnqueueRange(_array); Assert.AreEqual(Number, queue.Count); }
public void MinPriorityQueueDoesInsertItemInCollectionAsHeadIfItemIsLowerPriorityThanOriginalHead() { var priorityQueue = new MinPriorityQueue <string, int>(50); List <Tuple <string, int> > items = new List <Tuple <string, int> > { new Tuple <string, int>("A_50", 50), new Tuple <string, int>("A_41", 41), new Tuple <string, int>("A_38", 38), new Tuple <string, int>("A_37", 37), new Tuple <string, int>("A_23", 23), new Tuple <string, int>("A_11", 11), new Tuple <string, int>("A_5", 5), new Tuple <string, int>("A_3", 3), }.Randomize() .ToList(); priorityQueue.EnqueueRange(items); string originalHead = priorityQueue.Peek(); List <Tuple <string, int> > newItems = new List <Tuple <string, int> > { new Tuple <string, int>("A_2", 2), new Tuple <string, int>("A_4", 4), new Tuple <string, int>("A_6", 6), new Tuple <string, int>("A_8", 8), new Tuple <string, int>("A_10", 10), new Tuple <string, int>("A_12", 12), new Tuple <string, int>("A_14", 14), new Tuple <string, int>("A_16", 16), }.Randomize() .ToList(); priorityQueue.EnqueueRange(newItems); string newHead = priorityQueue.Peek(); Assert.AreEqual("A_3", originalHead); Assert.AreEqual("A_2", newHead); }
public void MinPriorityQueueInsertsItems() { var priorityQueue = new MinPriorityQueue <string, int>(50); List <Tuple <string, int> > items = new List <Tuple <string, int> > { new Tuple <string, int>("A_50", 50), new Tuple <string, int>("A_41", 41), new Tuple <string, int>("A_38", 38), new Tuple <string, int>("A_37", 37), new Tuple <string, int>("A_23", 23), new Tuple <string, int>("A_11", 11), new Tuple <string, int>("A_5", 5), new Tuple <string, int>("A_3", 3), }.Randomize() .ToList(); priorityQueue.EnqueueRange(items); Assert.AreEqual(8, priorityQueue.Count); }
public void MinPriorityQueueClearRemovesAllItems() { var priorityQueue = new MinPriorityQueue <string, int>(50); List <Tuple <string, int> > items = new List <Tuple <string, int> > { new Tuple <string, int>("A_50", 50), new Tuple <string, int>("A_41", 41), new Tuple <string, int>("A_38", 38), new Tuple <string, int>("A_37", 37), new Tuple <string, int>("A_23", 23), new Tuple <string, int>("A_11", 11), new Tuple <string, int>("A_5", 5), new Tuple <string, int>("A_3", 3), }.Randomize() .ToList(); priorityQueue.EnqueueRange(items); priorityQueue.Clear(); Assert.IsTrue(priorityQueue.IsEmpty); }
public void MinPriorityQueueDequeueReturnsItemWithLowestPriority() { var priorityQueue = new MinPriorityQueue <string, int>(50); List <Tuple <string, int> > items = new List <Tuple <string, int> > { new Tuple <string, int>("A_50", 50), new Tuple <string, int>("A_41", 41), new Tuple <string, int>("A_38", 38), new Tuple <string, int>("A_37", 37), new Tuple <string, int>("A_23", 23), new Tuple <string, int>("A_11", 11), new Tuple <string, int>("A_5", 5), new Tuple <string, int>("A_3", 3), }.Randomize() .ToList(); priorityQueue.EnqueueRange(items); string item = priorityQueue.Dequeue(); Assert.AreEqual("A_3", item); }