示例#1
0
        public void PopPriority()
        {
            // Create a new heap.
            ConcurrentBinaryMinHeap <int> heap = new ConcurrentBinaryMinHeap <int>();

            // Ensure that the heap is empty.
            Assert.That(heap.Count, Is.EqualTo(0));

            // Try to PopPriority() and expect an NullReferenceException to be thrown.
            Assert.Throws <NullReferenceException>(() => {
                heap.PopPriority();
            });

            // Ensure that the heap is empty.
            Assert.That(heap.Count, Is.EqualTo(0));

            // Store an element and insert it into the heap.
            PriorityValuePair <int> elem = new PriorityValuePair <int>(1f, 2);

            heap.Push(elem);

            // Ensure that the element was inserted into the heap.
            Assert.That(heap.Peek(), Is.EqualTo(elem));

            // Ensure that the priority of the pushed element is returned.
            Assert.That(heap.PopPriority(), Is.EqualTo(1f));

            // Ensure that the element was removed from the heap.
            Assert.That(heap.Count, Is.EqualTo(0));
        }