Пример #1
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));
            }
        }
Пример #2
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);
        }
Пример #3
0
        public void TestFractionOfRoot_tree_complete()
        {
            Allocation root = Allocation.NewRoot("ignored", 2);

            Allocation left         = root.NewChild("ignored", 3);
            Allocation leftLeft     = left.NewChild("ignored", 1);
            Allocation leftLeftDown = leftLeft.NewChild("ignored", 100);
            Allocation leftMiddle   = left.NewChild("ignored", 100);
            Allocation leftRight    = left.NewChild("ignored", 100);

            Allocation right     = root.NewChild("ignored", 1);
            Allocation rightDown = right.NewChild("ignored", 100);

            // Checks that the leaf allocations add up to a full 1.0.
            double total =
                (leftLeftDown.GetFractionOfRoot() * leftLeftDown.GetAllocationUnits())
                + (leftMiddle.GetFractionOfRoot() * leftMiddle.GetAllocationUnits())
                + (leftRight.GetFractionOfRoot() * leftRight.GetAllocationUnits())
                + (rightDown.GetFractionOfRoot() * rightDown.GetAllocationUnits());

            Assert.AreEqual(1.0, total, DOUBLE_ERROR_MARGIN);
        }
Пример #4
0
 public override string ToString()
 {
     return($"ProgressEvent:{progressUnits}:{allocation.GetAllocationUnits()}:{allocation.GetDescription()}");
 }
Пример #5
0
 public override string ToString()
 {
     return($"{(progressUnits==allocation.GetAllocationUnits()?"End":"Start")}:{allocation.GetDescription()}");
 }