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 SynchronisedMaxPriorityQueuePeekReturnsItemWithHighestPriorityMultiThread()
        {
            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.Peek();

            Assert.AreEqual("A_50", item);
        }
        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 SynchronisedMaxPriorityQueuePeekDoesNotRemoveItemFromQueue()
        {
            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.Peek();

            Assert.AreEqual(8, priorityQueue.Count);
        }