Ejemplo n.º 1
0
        public void PriorityQueueTest()
        {
            Comparison <int> comparison = (x, y) => x.CompareTo(y);

            for (int i = 0; i < 10; i++)
            {
                for (int j = 1; j < 100; j++)
                {
                    int[] data = Utilities.ArrayUtilities.CreateRandomArray(j, 0, 1000);
                    MaxPriorityQueue <int> queue = new MaxPriorityQueue <int>();

                    for (int k = 0; k < data.Length; k++)
                    {
                        queue.Insert(data[k]);
                        Assert.AreEqual(k + 1, queue.Count);
                    }

                    int previous = queue.Pop();

                    while (queue.Count > 0)
                    {
                        int current = queue.Pop();
                        Assert.IsTrue(comparison(previous, current) >= 0);
                        previous = current;
                    }

                    Assert.IsTrue(queue.IsEmpty);
                }
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            MaxPriorityQueue <IHeapValue> maxheap = new MaxPriorityQueue <IHeapValue>();
            MinPriorityQueue <IHeapValue> minheap = new MinPriorityQueue <IHeapValue>();
            List <IHeapValue>             list    = new List <IHeapValue>();
            Random rnd = new Random(DateTime.Now.Millisecond);

            for (int i = 0; i < 10; i++)
            {
                HeapNode hn = new HeapNode()
                {
                    Value = rnd.Next(0, 100)
                };
                list.Add(hn);
                maxheap.Insert(hn);
                minheap.Insert(hn);
            }
            Console.WriteLine("RandomData:");
            list.ForEach(n => Console.Write("{0},", n.Value));
            Console.WriteLine(Environment.NewLine + "MaxHeapOutput:");
            while (!maxheap.IsEmpty)
            {
                Console.Write("{0},", maxheap.ExtractMax().Value);
            }
            Console.WriteLine(Environment.NewLine + "MinHeapOutput:");
            while (!minheap.IsEmpty)
            {
                Console.Write("{0},", minheap.ExtractMin().Value);
            }
            Console.ReadKey();
        }
Ejemplo n.º 3
0
        public void PriorityQueueTest()
        {
            Comparison<int> comparison = (x, y) => x.CompareTo(y);
            for (int i = 0; i < 10; i++)
            {
                for (int j = 1; j < 100; j++)
                {
                    int[] data = Utilities.ArrayUtilities.CreateRandomArray(j, 0, 1000);
                    MaxPriorityQueue<int> queue = new MaxPriorityQueue<int>();

                    for(int k = 0; k < data.Length; k++)
                    {
                        queue.Insert(data[k]);
                        Assert.AreEqual(k + 1, queue.Count);
                    }

                    int previous = queue.Pop();

                    while(queue.Count > 0)
                    {
                        int current = queue.Pop();
                        Assert.IsTrue(comparison(previous, current) >= 0);
                        previous = current;
                    }

                    Assert.IsTrue(queue.IsEmpty);
                }
            }
        }
        } // end of BuildAccumulator(List<String> query)

        /// <summary>
        /// Creates a new priority queue by inserting the rank of the document and document id
        /// </summary>
        /// <returns> a priority queue with max heap property</returns>
        private MaxPriorityQueue BuildPriorityQueue()
        {
            //temporary variable to hold the doc weight
            double normalizer;
            //temporary variable to hold the final ranking value of that document
            double finalRank;

            //Make a new priority queue
            MaxPriorityQueue priorityQueue = new MaxPriorityQueue();

            //for every key value in the Accumulator divide A_{d} by L_{d}
            foreach (KeyValuePair <int, double> candidate in this.accumulator)
            {
                //get corresponding L_{d} value according to ranking system
                normalizer = this.rankVariant.GetDocumentWeight(candidate.Key, this.index);

                // divide Accumulated Value A_{d} by L_{d}
                finalRank = (double)candidate.Value / normalizer;

                //add to list to perform priority queue on
                priorityQueue.MaxHeapInsert(finalRank, candidate.Key);
            }

            return(priorityQueue);
        } // end of BuildPriorityQueuer();
        public void MaxPriorityQueueMovesNextHighestPriorityItemToHeadAfterDequeueItem()
        {
            var priorityQueue = new MaxPriorityQueue <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 MaxPriorityQueueEnumerationYieldsLowestPriorityAsLastItem()
        {
            var priorityQueue = new MaxPriorityQueue <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());
        }
Ejemplo n.º 7
0
        public void Test_Remove()
        {
            PriorityQueue <double> q = null;

            double[] items = { 5, 85, 43, 2, 28, 99, 67, 1.98, 33, 19, 17, 44 };
            SortedList <double, double> monitor = new SortedList <double, double>();

            q = new MaxPriorityQueue <double>(7);

            for (int i = 0; i < items.Length; i++)
            {
                q.Enqueue(items[i]);
                monitor.Add(-1 * items[i], items[i]);
            }

            q.Remove(1.98);
            monitor.Remove(-1.98);
            q.Remove(85);
            monitor.Remove(-85);

            foreach (double monitorItem in monitor.Values)
            {
                Assert.AreEqual(monitorItem, q.Dequeue());
            }
        }
        public void MaxPriorityQueueDoesNotInsertItemToHeadIfItemIsLowerPriorityThanHead()
        {
            var priorityQueue = new MaxPriorityQueue <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);
        }
Ejemplo n.º 9
0
        public void Test_Integration_2()
        {
            PriorityQueue <double> q = null;

            double[] items = { 82, 100, 9.3, 1.19, 10, 29, 12, 9.0006, 22, 20.9, 207, 13.56, 30, 2, 66 };
            SortedList <double, double> monitor = new SortedList <double, double>();

            q = new MaxPriorityQueue <double>();

            for (int i = 0; i < items.Length; i++)
            {
                q.Enqueue(items[i]);
                monitor.Add(-1 * items[i], items[i]);

                if (i == 3)
                {
                    q.Dequeue();
                    monitor.Remove(-100);
                }
                else if (i == 8)
                {
                    q.Dequeue();
                    monitor.Remove(-82);
                }
            }

            foreach (double monitorItem in monitor.Values)
            {
                Assert.AreEqual(monitorItem, q.Dequeue());
            }
        }
Ejemplo n.º 10
0
        public void CreateTiers()
        {
            Console.WriteLine("Creating Tier Indices");
            List <Posting> termPostings;
            List <string>  vocab = this.tempPostingMap.Keys.ToList();

            foreach (string term in vocab)
            {
                //get postings for the term
                termPostings = tempPostingMap[term];


                //make priority queue

                MaxPriorityQueue tierQueue = new MaxPriorityQueue();
                foreach (Posting p in termPostings)
                {
                    tierQueue.MaxHeapInsert(p.Positions.Count, p.DocumentId);
                }

                //Create the Tiers using a priority queue
                List <MaxPriorityQueue.InvertedIndex> temp = tierQueue.RetrieveTier(1);
                tempTier1.Add(term, temp);

                temp = tierQueue.RetrieveTier(10);
                tempTier2.Add(term, temp);


                temp = tierQueue.RetrieveTier(100);
                tempTier3.Add(term, temp);
            }
        }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            MaxPriorityQueue<IHeapValue> maxheap = new MaxPriorityQueue<IHeapValue>();
            MinPriorityQueue<IHeapValue> minheap = new MinPriorityQueue<IHeapValue>();
            List<IHeapValue> list = new List<IHeapValue>();
            Random rnd = new Random(DateTime.Now.Millisecond);
            for (int i = 0; i < 10; i++)
            {
                HeapNode hn = new HeapNode() { Value = rnd.Next(0, 100) };
                list.Add(hn);
                maxheap.Insert(hn);
                minheap.Insert(hn);
            }
            Console.WriteLine("RandomData:");
            list.ForEach(n => Console.Write("{0},", n.Value));
            Console.WriteLine(Environment.NewLine + "MaxHeapOutput:");
            while (!maxheap.IsEmpty)
            {
                Console.Write("{0},", maxheap.ExtractMax().Value);
            }
            Console.WriteLine(Environment.NewLine + "MinHeapOutput:");
            while (!minheap.IsEmpty)
            {
                Console.Write("{0},", minheap.ExtractMin().Value);
            }
            Console.ReadKey();

        }
Ejemplo n.º 12
0
        public void Dequeue_Should_Always_Return_The_Max_Value()
        {
            var pq = new MaxPriorityQueue <int>();

            pq.Enqueue(6);
            pq.Enqueue(9);
            pq.Enqueue(8);
            pq.Enqueue(3);
            pq.Enqueue(5);
            pq.Enqueue(1);
            pq.Enqueue(3);

            pq.Count.Should().Be(7);

            pq.Dequeue().Should().Be(9);
            pq.Count.Should().Be(6);
            pq.Dequeue().Should().Be(8);
            pq.Count.Should().Be(5);
            pq.Dequeue().Should().Be(6);
            pq.Count.Should().Be(4);
            pq.Dequeue().Should().Be(5);
            pq.Count.Should().Be(3);
            pq.Dequeue().Should().Be(3);
            pq.Count.Should().Be(2);
            pq.Dequeue().Should().Be(3);
            pq.Count.Should().Be(1);
            pq.Dequeue().Should().Be(1);
            pq.Count.Should().Be(0);
        }
Ejemplo n.º 13
0
        public void Add_ExpectCountIncrement()
        {
            var queue = new MaxPriorityQueue<int>();

            queue.Add(ITEM);

            Assert.AreEqual(1, queue.Count);
        }
Ejemplo n.º 14
0
        public void Test_Capacity()
        {
            PriorityQueue <double> q = null;

            q = new MaxPriorityQueue <double>(10);

            Assert.AreEqual(10, q.Capacity);
        }
Ejemplo n.º 15
0
        public void Test_Capacity_NegativeInput()
        {
            PriorityQueue <double> q = null;

            q = new MaxPriorityQueue <double>(-4);

            Assert.AreEqual(64, q.Capacity);
        }
Ejemplo n.º 16
0
        public void Test_Capacity_Default()
        {
            PriorityQueue <double> q = null;

            q = new MaxPriorityQueue <double>();

            Assert.AreEqual(64, q.Capacity);
        }
Ejemplo n.º 17
0
        public void Test_Dequeue_EmptyQ()
        {
            PriorityQueue <double> q = null;

            q = new MaxPriorityQueue <double>();

            Assert.AreEqual(default(double), q.Dequeue());
        }
        public void MaxQueueAddItemsWithSize()
        {
            var queue = new MaxPriorityQueue <string, int>(Number);

            queue.EnqueueRange(_array);

            Assert.AreEqual(Number, queue.Count);
        }
Ejemplo n.º 19
0
        public void Test_IsEmpty_EmptyQ()
        {
            PriorityQueue <double> q = null;

            q = new MaxPriorityQueue <double>();

            Assert.IsTrue(q.IsEmpty);
        }
Ejemplo n.º 20
0
        public void Test_Count_EmptyQ()
        {
            PriorityQueue <double> q = null;

            q = new MaxPriorityQueue <double>();

            Assert.AreEqual(0, q.Count);
        }
Ejemplo n.º 21
0
        public IList <IList <int> > GetSkyline(int[][] buildings)
        {
            var sortedList = new SortedList <int, IList <int> >();

            foreach (var building in buildings)
            {
                if (!sortedList.ContainsKey(building[0]))
                {
                    sortedList.Add(building[0], new List <int>());
                }
                sortedList[building[0]].Add(-building[2]);

                if (!sortedList.ContainsKey(building[1]))
                {
                    sortedList.Add(building[1], new List <int>());
                }
                sortedList[building[1]].Add(building[2]);
            }

            var result  = new List <IList <int> >();
            var heights = new MaxPriorityQueue();

            foreach (var x in sortedList.Keys)
            {
                foreach (var height in sortedList[x])
                {
                    if (height < 0)
                    {
                        heights.Insert(-height);
                    }
                    else
                    {
                        heights.Delete(height);
                    }
                }

                if (heights.Size() == 0)
                {
                    result.Add(new List <int>()
                    {
                        x, 0
                    });
                }
                else
                {
                    var height = heights.Max();
                    if (result.Count == 0 || result[result.Count - 1][1] != height)
                    {
                        result.Add(new List <int>()
                        {
                            x, height
                        });
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 22
0
 private void Pop(MaxPriorityQueue <Order> pq, TreeSet <int> set, int count)
 {
     for (var i = 0; i < count; i++)
     {
         Assert.Equal(set.Max, pq.Top.Id);
         Assert.Equal(set.Max, pq.Pop().Id);
         set.RemoveMax();
     }
 }
Ejemplo n.º 23
0
 public void IncreaseKey()
 {
     var job = new MockJob { Name = "cooking" };
     var job2 = new MockJob { Name = "homework" };
     var job3 = new MockJob { Name = "hoover" };
     var priorityQueue = new MaxPriorityQueue<MockJob>(new[] { new KeyValuePair<double, MockJob>(2.0, job), new KeyValuePair<double, MockJob>(1.1, job2), new KeyValuePair<double, MockJob>(2.5, job3) });
     priorityQueue.IncreaseKey(1, 3.0);
     Assert.AreEqual("homework", priorityQueue.Maximum().Name,"#E8");
 }
Ejemplo n.º 24
0
        public void Add_ExpectQueueContainsItem()
        {
            var queue = new MaxPriorityQueue<int>();

            queue.Add(ITEM);

            var items = queue.ToArray();
            CollectionAssert.AreEquivalent(new[] { ITEM }, items);
        }
Ejemplo n.º 25
0
        public void DequeueMax_OneItem_ExpectCountDecrement()
        {
            var queue = new MaxPriorityQueue<int>();
            queue.Add(ITEM);

            queue.DequeueMax();

            Assert.AreEqual(0, queue.Count);
        }
Ejemplo n.º 26
0
        public void DequeueMax_OneItem_ExpectReturnItem()
        {
            var queue = new MaxPriorityQueue<int>();
            queue.Add(ITEM);

            var dequeuedItem = queue.DequeueMax();

            Assert.AreEqual(ITEM, dequeuedItem);
        }
Ejemplo n.º 27
0
        public void Test_Peek()
        {
            PriorityQueue <double> q = null;

            q = new MaxPriorityQueue <double>();
            q.Enqueue(1);

            Assert.AreEqual(1, q.Peek());
        }
Ejemplo n.º 28
0
        public void TestPriorityQueueBoundary()
        {
            var pq1 = new MinPriorityQueue <int>();

            PriorityQueueBoundary(pq1);

            var pq2 = new MaxPriorityQueue <int>();

            PriorityQueueBoundary(pq2);
        }
Ejemplo n.º 29
0
        public void TestPriorityQueueEnumerator()
        {
            var pq = new MinPriorityQueue <int>();

            Enumerate(pq);

            var pq2 = new MaxPriorityQueue <int>();

            Enumerate(pq2);
        }
Ejemplo n.º 30
0
 public void Insert()
 {
     var job = new MockJob { Name = "cooking" };
     var job2 = new MockJob { Name = "homework" };
     var job3 = new MockJob { Name = "hoover" };
     var priorityQueue = new MaxPriorityQueue<MockJob>(new[] { new KeyValuePair<double, MockJob>(2.0, job), new KeyValuePair<double, MockJob>(1.1, job2)});
     priorityQueue.Insert(new KeyValuePair<double, MockJob>(2.5, job3) );
     Assert.AreEqual(3, priorityQueue.Count, "#E9");
     Assert.AreEqual("hoover", priorityQueue.Maximum().Name, "#E10");
 }
Ejemplo n.º 31
0
        public void Test_IsEmpty_FilledQ()
        {
            PriorityQueue <double> q = null;

            q = new MaxPriorityQueue <double>();
            q.Enqueue(1);
            q.Enqueue(2);

            Assert.IsFalse(q.IsEmpty);
        }
Ejemplo n.º 32
0
        public void Test_Count()
        {
            PriorityQueue <double> q = null;

            q = new MaxPriorityQueue <double>();
            q.Enqueue(1);
            q.Enqueue(2);

            Assert.AreEqual(2, q.Count);
        }
Ejemplo n.º 33
0
        public void MaxPriorityQueue_Add_AddSingleItemToEmptyHeap()
        {
            MaxPriorityQueue maxPriorityQueue = new MaxPriorityQueue();

            Node node2add = new Node { c = 'a', frequency = 100 };
            maxPriorityQueue.Add(node2add);

            Node returnNode = maxPriorityQueue.Extract();
            Assert.AreEqual(node2add, returnNode);
        }
Ejemplo n.º 34
0
        public void Test_Contains_Not()
        {
            PriorityQueue <double> q = null;

            q = new MaxPriorityQueue <double>();
            q.Enqueue(3);
            q.Enqueue(2);
            q.Enqueue(1);

            Assert.IsFalse(q.Contains(4));
        }
        public void MaxQueueAddItemWithSize()
        {
            var queue = new MaxPriorityQueue <string, int>(Number);

            for (int i = 0; i < _array.Length; i++)
            {
                queue.Enqueue(_array[i].Item1, _array[i].Item2);
            }

            Assert.AreEqual(Number, queue.Count);
        }
Ejemplo n.º 36
0
        public void MaxPriorityQueue_Empty_EnumeratorTest()
        {
            var queue = new MaxPriorityQueue <string>();

            Assert.IsTrue(queue.IsEmpty);
            Assert.AreEqual(0, queue.Size);
            foreach (var item in queue)
            {
                Assert.Fail("Check enumerator implementation. Queue is empty.");
            }
        }
Ejemplo n.º 37
0
        public void Test_Capacity_AutoResize()
        {
            PriorityQueue <double> q = null;

            q = new MaxPriorityQueue <double>(3);
            q.Enqueue(1);
            q.Enqueue(2);
            q.Enqueue(3);
            q.Enqueue(4);

            Assert.AreEqual(6, q.Capacity);
        }
        /// <summary>
        /// Method that takes in the query and returns a list of the top ten ranking documents
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public IList <MaxPriorityQueue.InvertedIndex> GetTopTen(List <string> query)
        {
            //Build the Accumulator Hashmap
            BuildAccumulator(query);

            //Build Priority Queue using the Accumulator divided by L_{d}
            MaxPriorityQueue priorityQueue = BuildPriorityQueue();

            accumulator.Clear();

            //Retrieve Top Ten Documents according to percent
            return(priorityQueue.RetrieveTopTen());
        }
Ejemplo n.º 39
0
        public void Test_Dequeue()
        {
            PriorityQueue <double> q = null;

            q = new MaxPriorityQueue <double>();
            q.Enqueue(1);
            q.Enqueue(2);
            q.Enqueue(3);

            Assert.AreEqual(3, q.Dequeue());
            Assert.AreEqual(2, q.Dequeue());
            Assert.AreEqual(1, q.Dequeue());
        }
Ejemplo n.º 40
0
        public void Dequeue()
        {
            var queue = new MaxPriorityQueue<int>(5);
            queue.Enqueue(4);
            queue.Enqueue(5);
            queue.Enqueue(0);
            queue.Enqueue(6);

            Assert.Equal(6, queue.Dequeue());
            Assert.Equal(3, queue.Count);

            Assert.Equal(5, queue.Dequeue());
            Assert.Equal(2, queue.Count);
        }
Ejemplo n.º 41
0
        public void MaxPriorityQueue_Add_AddTwoItemsToEmptyHeap()
        {
            MaxPriorityQueue maxPriorityQueue = new MaxPriorityQueue();

            Node node1 = new Node { c = 'a', frequency = 100 };
            Node node2 = new Node { c = 'f', frequency = 1000 };
            maxPriorityQueue.Add(node1);
            maxPriorityQueue.Add(node2);

            Node returnNode = maxPriorityQueue.Extract();
            Assert.AreEqual(node2, returnNode);

            returnNode = maxPriorityQueue.Extract();
            Assert.AreEqual(node1, returnNode);
        }
Ejemplo n.º 42
0
        public void ExtractMax()
        {
            var job = new MockJob { Name = "cooking" };
            var priorityQueue = new MaxPriorityQueue<MockJob>(new[] { new KeyValuePair<double, MockJob>(2.0, job) });
            Assert.AreEqual(job.Name, priorityQueue.ExtractMax().Name, "#E2");
            Assert.AreEqual(0, priorityQueue.Count, "#E3");

            var job2 = new MockJob { Name = "homework" };
            var job3 = new MockJob { Name = "hoover" };
            priorityQueue = new MaxPriorityQueue<MockJob>(new[] { new KeyValuePair<double, MockJob>(2.0, job), new KeyValuePair<double, MockJob>(1.1, job2), new KeyValuePair<double, MockJob>(2.5, job3) });
            Assert.AreEqual("hoover", priorityQueue.ExtractMax().Name, "#E4");
            Assert.AreEqual(2, priorityQueue.Count,"#E5");
            Assert.AreEqual("cooking",priorityQueue.ExtractMax().Name,"#E6");
            Assert.AreEqual(1, priorityQueue.Count, "#E7");
        }
Ejemplo n.º 43
0
 public void MaxPQ_Basic()
 {
     var pq = new MaxPriorityQueue<int>();
     pq.Insert(2, null);
     pq.Insert(6, null);
     pq.Insert(1, null);
     Assert.AreEqual(6, (int)(pq.DelMax().Item1));
     pq.Insert(9, null);
     pq.Insert(7, null);
     pq.Insert(1, null);
     Assert.AreEqual(9, (int)(pq.DelMax().Item1));
     pq.Insert(2, null);
     pq.Insert(6, null);
     pq.Insert(1, null);
     Assert.AreEqual(7, (int)(pq.DelMax().Item1));
     Assert.AreEqual(6, (int)(pq.Max().Item1));
     Assert.AreEqual(6, (int)(pq.DelMax().Item1));
     Assert.AreEqual(2, (int)(pq.DelMax().Item1));
     Assert.AreEqual(2, (int)(pq.DelMax().Item1));
 }
Ejemplo n.º 44
0
 public void Create_ExpectCountToBeZero()
 {
     var queue = new MaxPriorityQueue<int>();
     Assert.AreEqual(0, queue.Count);
 }
Ejemplo n.º 45
0
        public void PeekMax_ExpectCountNotChange()
        {
            var queue = new MaxPriorityQueue<int>();
            queue.Add(ITEM);

            queue.PeekMax();

            Assert.AreEqual(1, queue.Count);
        }
Ejemplo n.º 46
0
        public void PeekMax_OneItem_ExpectReturnItem()
        {
            var queue = new MaxPriorityQueue<int>();
            queue.Add(ITEM);

            var peekedItem = queue.PeekMax();

            Assert.AreEqual(ITEM, peekedItem);
        }
Ejemplo n.º 47
0
        public void UltimateTest()
        {
            const int COUNT = 100000;

            var random = new Random();

            var array = new int[COUNT];
            var queue = new MaxPriorityQueue<int>();

            for (var i = 0; i < COUNT; i++)
            {
                array[i] = random.Next(COUNT);
                queue.Add(array[i]);
            }

            Array.Sort(array);
            Array.Reverse(array);

            var numbersFromQueue = new int[COUNT];
            for (var i = 0; i < COUNT; i++)
            {
                numbersFromQueue[i] = queue.DequeueMax();
            }

            Assert.AreEqual(0, queue.Count);
            CollectionAssert.AreEqual(array, numbersFromQueue);
        }
Ejemplo n.º 48
0
 private MaxPriorityQueue<int> CreateQueueAddTwoNotEqualItems()
 {
     var queue = new MaxPriorityQueue<int>();
     queue.Add(MIN_ITEM);
     queue.Add(MAX_ITEM);
     return queue;
 }
Ejemplo n.º 49
0
        public void DequeueMax_EmptyQueue_ExpectThrowInvalidOperationException()
        {
            var queue = new MaxPriorityQueue<int>();

            queue.DequeueMax();
        }
Ejemplo n.º 50
0
        public void DequeueMax_TwoNotEqualItems_ExpectReturnMax()
        {
            var queue = CreateQueueAddTwoNotEqualItems();
            queue.Add(MIN_ITEM);
            queue.Add(MAX_ITEM);

            var dequeuedItem = queue.DequeueMax();
            Assert.AreEqual(MAX_ITEM, dequeuedItem);

            //check order of insertion does not matter
            queue = new MaxPriorityQueue<int>();
            queue.Add(MAX_ITEM);
            queue.Add(MIN_ITEM);

            dequeuedItem = queue.DequeueMax();
            Assert.AreEqual(MAX_ITEM, dequeuedItem);
        }