コード例 #1
0
        public void Peek_1Node_CorrectValue()
        {
            var fh = new FibonacciHeap <int>();

            fh.Push(3);

            Assert.AreEqual(3, fh.Peek());
        }
コード例 #2
0
        public void Peek_2NodesSmallerLast_CorrectValue()
        {
            var fh = new FibonacciHeap <int>();

            fh.Push(3);
            fh.Push(2);

            Assert.AreEqual(2, fh.Peek());
        }
コード例 #3
0
        public void Peek_MultipleValues_CorrectValue(int[] sequence)
        {
            var fh = new FibonacciHeap <int>();

            foreach (var value in sequence)
            {
                if (value < 0)
                {
                    var val = fh.Peek();
                    Assert.AreEqual(System.Math.Abs(value), val);
                }
                else
                {
                    fh.Push(value);
                }
            }
        }
コード例 #4
0
        public static void Union_EmptyHeap_BecomesOtherHeap()
        {
            var thisHeap  = new FibonacciHeap <int>();
            var otherHeap = BuildTestHeap();

            var minNode    = otherHeap.Peek();
            var otherCount = otherHeap.Count;

            Assert.Zero(thisHeap.Count);

            thisHeap.Union(otherHeap);

            Assert.Zero(otherHeap.Count);
            Assert.AreEqual(thisHeap.Peek(), minNode);
            Assert.Throws <InvalidOperationException>(() => otherHeap.Peek());

            Assert.AreEqual(otherCount, thisHeap.Count);
        }
コード例 #5
0
        public static void Peek_EmptyHeap_ThrowsCorrectException()
        {
            var heap = new FibonacciHeap <int>();

            Assert.Throws <InvalidOperationException>(() => heap.Peek());
        }