public void SynchronisedMaxPriorityQueueEnumerationYieldsLowestPriorityAsLastItem() { var priorityQueue = new SynchronisedMaxPriorityQueue <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_3", list.Last()); }
public void SynchronisedMaxPriorityQueueDequeueReturnsItemWithHighestPriorityMultiThread() { var priorityQueue = new SynchronisedMaxPriorityQueue <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_50", item); }
public void SynchronisedMaxPriorityQueueDoesNotInsertItemToHeadIfItemIsLowerPriorityThanHead() { var priorityQueue = new SynchronisedMaxPriorityQueue <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_49", 49); string newHead = priorityQueue.Peek(); Assert.AreEqual("A_50", originalHead); Assert.AreEqual("A_50", newHead); }
public void SynchronisedMaxPriorityQueueMovesNextHighestPriorityItemToHeadAfterDequeueItem() { var priorityQueue = new SynchronisedMaxPriorityQueue <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_41", item); }
public void SynchronisedMaxPriorityQueueDoesNotInsertsItemInCollectionAsHeadIfItemIsLowerPriorityThanOriginalHeadMultiThreaded() { var priorityQueue = new SynchronisedMaxPriorityQueue <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 originalHead = priorityQueue.Peek(); List <Tuple <string, int> > newItems = new List <Tuple <string, int> > { new Tuple <string, int>("A_49", 49), 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(); List <Task> newtasks = new List <Task>(); newItems.ForEach(i => newtasks.Add(Task.Factory.StartNew(() => priorityQueue.Enqueue(i.Item1, i.Item2)))); Task.WaitAll(newtasks.ToArray()); string newHead = priorityQueue.Peek(); Assert.AreEqual("A_50", originalHead); Assert.AreEqual("A_50", newHead); }
public void SynchronisedMaxPriorityQueueDoesNotInsertsItemInCollectionAsHeadIfItemIsLowerPriorityThanOriginalHead() { var priorityQueue = new SynchronisedMaxPriorityQueue <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_49", 49), 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_50", originalHead); Assert.AreEqual("A_50", newHead); }
public void SynchronisedMaxPriorityQueueInsertsItems() { var priorityQueue = new SynchronisedMaxPriorityQueue <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 SynchronisedMaxPriorityQueueClearRemovesAllItems() { var priorityQueue = new SynchronisedMaxPriorityQueue <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 SynchronisedMaxPriorityQueueInitialisesEmpty() { var priorityQueue = new SynchronisedMaxPriorityQueue <string, int>(50); Assert.IsTrue(priorityQueue.IsEmpty); }
public void SynchronisedMaxPriorityQueueInitialisesWithSpecifiedPriorityComparer() { var priorityQueue = new SynchronisedMaxPriorityQueue <string, int>(Comparer <int> .Default); Assert.IsNotNull(priorityQueue); }
public void SynchronisedMaxPriorityQueueInitialisesWithSpecifiedInitialQueueSize() { var priorityQueue = new SynchronisedMaxPriorityQueue <string, int>(25); Assert.IsNotNull(priorityQueue); }
public void SynchronisedMaxPriorityQueueIntialises() { var priorityQueue = new SynchronisedMaxPriorityQueue <string, int>(); Assert.IsNotNull(priorityQueue); }
public void SynchronisedMaxPriorityQueueEnqueueThrowsIfPriorityIsNull() { var priorityQueue = new SynchronisedMaxPriorityQueue <string, TestPriority>(50); Assert.Throws <ArgumentNullException>(() => priorityQueue.Enqueue("A_1", null as TestPriority)); }