public void SynchronisedMinPriorityQueueDequeueReturnsItemWithLowestPriorityMultiThread() { var priorityQueue = new SynchronisedMinPriorityQueue <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(); List <Task> tasks = new List <Task>(); items.ForEach(i => tasks.Add(Task.Factory.StartNew(() => priorityQueue.Enqueue(i.Item1, i.Item2)))); Task.WaitAll(tasks.ToArray()); string item = priorityQueue.Dequeue(); Assert.AreEqual("A_3", item); }
public void SynchronisedMinPriorityQueueMovesNextLowestPriorityItemToHeadAfterRemoveItem() { var priorityQueue = new SynchronisedMinPriorityQueue <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 SynchronisedMinPriorityQueueDequeueDoesRemoveItemFromQueue() { var priorityQueue = new SynchronisedMinPriorityQueue <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(); Assert.AreEqual(7, priorityQueue.Count); }
public void SynchronisedMinPriorityQueueDequeueReturnsItemWithLowestPriority() { var priorityQueue = new SynchronisedMinPriorityQueue <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); }