Esempio n. 1
0
        public void TestSmoke_linear()
        {
            Allocation root  = Allocation.NewRoot("root", 1);
            Allocation node1 = root.NewChild("node1", 2);
            Allocation node2 = node1.NewChild("node2", 3);

            Assert.AreEqual("node2", node2.GetDescription());
            Assert.AreEqual(1.0 / 2 / 3, node2.GetFractionOfRoot(), DOUBLE_ERROR_MARGIN);
            Assert.IsTrue(node2.GetParent().IsPresent());
            Assert.AreEqual(node1, node2.GetParent().Get());

            Assert.AreEqual("node1", node1.GetDescription());
            Assert.IsTrue(node1.GetParent().IsPresent());
            Assert.AreEqual(root, node1.GetParent().Get());
            Assert.AreEqual(1.0 / 2, node1.GetFractionOfRoot(), DOUBLE_ERROR_MARGIN);

            Assert.AreEqual("root", root.GetDescription());
            Assert.AreEqual(1, root.GetAllocationUnits());
            Assert.IsFalse(root.GetParent().IsPresent());
            Assert.AreEqual(1.0, root.GetFractionOfRoot(), DOUBLE_ERROR_MARGIN);
        }
Esempio n. 2
0
        /**
         * Updates the {@link #allocationCompletionMap} with {@code units} more progress for {@code
         * allocation}. This also updates {@link Allocation} parents if {@code allocation} is complete in
         * terms of progress.
         *
         * @param allocation the allocation the progress is made on
         * @param units the progress units
         */
        private void UpdateCompletionMap(Allocation allocation, long units)
        {
            if (allocationCompletionMap.ContainsKey(allocation))
            {
                units += allocationCompletionMap[allocation];
            }
            allocationCompletionMap[allocation] = units;

            if (allocation.GetAllocationUnits() == units)
            {
                allocation
                .GetParent()
                .IfPresent(parentAllocation => UpdateCompletionMap(parentAllocation, 1));
            }
        }