public void AddChild_1Node_CorrectParent()
        {
            var p1 = FibonacciHeapTestHelpers.CreateNodeConnectedToSelf(1);
            var p2 = FibonacciHeapTestHelpers.CreateNodeConnectedToSelf(2);

            _heap.AddChild(p1, p2);

            Assert.AreEqual(p1, p2.Parent);
        }
        public void Consolidate_3Node_CorrectMin()
        {
            var node1 = FibonacciHeapTestHelpers.CreateNodeConnectedToSelf(3);
            var node2 = FibonacciHeapTestHelpers.CreateNodeConnectedToSelf(4);

            _heap.AddChild(node1, node2);

            var node3 = FibonacciHeapTestHelpers.CreateNodeConnectedToSelf(5);

            _heap.Join(node3, node1);

            var newMin = _heap.Consolidate(node3, 2);

            Assert.AreEqual(3, newMin.Value);
        }
Exemplo n.º 3
0
        public void Degree_1Degree_1Degree()
        {
            var parent = FibonacciHeapTestHelpers.CreateNodeConnectedToSelf(7);
            var child  = FibonacciHeapTestHelpers.CreateNodeConnectedToSelf(7);

            _heap.AddChild(parent, child);

            Assert.Multiple(() =>
            {
                Assert.AreEqual(1, parent.Degree);
                Assert.AreEqual(0, child.Degree);
            });
        }
Exemplo n.º 4
0
        public void Cut_2NodesWithIndirectParent_CorrectNextPrev()
        {
            var p1 = FibonacciHeapTestHelpers.CreateNodeConnectedToSelf(1);
            var c1 = FibonacciHeapTestHelpers.CreateNodeConnectedToSelf(1);
            var c2 = FibonacciHeapTestHelpers.CreateNodeConnectedToSelf(2);

            _heap.AddChild(p1, c1);
            _heap.AddChild(p1, c2);
            _heap.Cut(c2);

            Assert.Multiple(() =>
            {
                Assert.AreEqual(c1, c1.Next);
                Assert.AreEqual(c1, c1.Prev);

                Assert.AreEqual(c2, c2.Next);
                Assert.AreEqual(c2, c2.Prev);
            });
        }