Пример #1
0
        public void DecreasePriorityTest()
        {
            // Heap
            FibonacciHeap <float, char> heap = new FibonacciHeap <float, char>();

            // Add collection of nodes
            HeapNode <float, char> node2 = heap.Insert(7, 'b');
            HeapNode <float, char> node1 = heap.Insert(3, 'a');
            HeapNode <float, char> node3 = heap.Insert(14, 'c');
            HeapNode <float, char> node4 = heap.Insert(35, 'd');

            // Decrease priority of node
            heap.DecreasePriority(node4, 1);

            // Check minimum is correct, and contains correct values
            Assert.AreEqual(heap.Minimum.Priority, 1);
            Assert.AreEqual(heap.Minimum.Value, 'd');
            Assert.AreEqual(heap.Minimum, node4);
            Assert.AreEqual(heap.Count, 4);

            // Delete min so trees are consolidated
            heap.DeleteMin();

            // Decrease priority of node
            heap.DecreasePriority(node2, 0);

            // Check minimum is correct, and contains correct values
            Assert.AreEqual(heap.Minimum, node2);
            Assert.AreEqual(heap.Minimum.Priority, 0);
            Assert.AreEqual(heap.Minimum.Value, 'b');
            Assert.AreEqual(heap.Count, 3);
        }