Ejemplo n.º 1
0
        internal static RootedProjectTree ConstructVeryLargeTree(Random random, int depth, int maxImmediateChildrenCount, int totalNodeCount, Func <string> counter = null)
        {
            Requires.NotNull(random, "random");
            Requires.Range(depth > 0, "maxDepth");
            Requires.Range(totalNodeCount > 0, "totalNodeCount");

            if (counter == null)
            {
                int counterPosition = 0;
                counter = () => "Node " + ++counterPosition;
            }

            var tree           = RootedProjectTree.Create(counter());
            int nodesAllocated = 1;

            int maxChildrenCount = Math.Min(maxImmediateChildrenCount, totalNodeCount - nodesAllocated);

            if (depth == 1)
            {
                tree            = tree.AddChildren(Enumerable.Range(1, maxChildrenCount).Select(n => ProjectTree.Create(counter())));
                nodesAllocated += maxChildrenCount;
            }
            else
            {
                int childrenCount = random.Next(maxChildrenCount) + 1;
                int sizePerBranch = (totalNodeCount - nodesAllocated) / childrenCount;
                if (sizePerBranch > 0)
                {
                    tree = tree.AddChildren(Enumerable.Range(1, childrenCount).Select(n => ConstructVeryLargeTree(random, depth - 1, maxImmediateChildrenCount, sizePerBranch, counter).ProjectTree));
                }
            }

            return(tree);
        }
Ejemplo n.º 2
0
        internal RootedProjectTree CloneProjectTreeRootToLeafWithoutBuilders(RootedProjectTree templateTree)
        {
            var root             = RootedProjectTree.Create(templateTree.Caption);
            var rootWithChildren = RecursiveAddChildren(templateTree.ProjectTree, root);

            return(rootWithChildren);
        }