Esempio n. 1
0
        public void Remove()
        {
            // Create a new heap.
            ConcurrentBinaryMinHeap <int> heap = new ConcurrentBinaryMinHeap <int>();

            // Create and store a few elements.
            PriorityValuePair <int> elem1 = new PriorityValuePair <int>(1f, 2);
            PriorityValuePair <int> elem2 = new PriorityValuePair <int>(2f, 4);
            PriorityValuePair <int> elem3 = new PriorityValuePair <int>(3f, 6);

            // Expect Remove() to return null for an empty heap.
            Assert.That(heap.Remove(elem1), Is.EqualTo(false));

            // Insert 2 of the elements into the heap.
            heap.Push(elem2);
            heap.Push(elem3);

            // Expect Remove() to return false for elem1, indicating the element was removed
            // (since it doesn't belong to the heap and can't be found). This tests the if-else
            // case for when the provided element isn't found in the heap.
            Assert.That(heap.Remove(elem1), Is.False);

            // Expect Remove() to return true for elem2, indicating the element was removed
            // (since it belongs to the heap and can be found). This tests the if-else case for
            // when Count is 2 or greater.
            Assert.That(heap.Remove(elem2), Is.True);

            // Expect Remove() to return true for elem3, indicating the element was removed
            // (since it belongs to the heap and can be found). This tests the if-else case for
            // when Count equals 1.
            Assert.That(heap.Remove(elem3), Is.True);
        }