Esempio n. 1
0
        public void PeekPriority()
        {
            // 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 PeekPriority() and expect an NullReferenceException to be thrown.
            Assert.Throws <NullReferenceException>(() => {
                heap.PeekPriority();
            });

            // 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.Count, Is.EqualTo(1));
            Assert.That(heap.Peek(), Is.EqualTo(elem));

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

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