public HierarchicalData CreateHierarchyFromFilesystem(string path, bool subDirs)
        {
            var item = new HierarchicalData(path);

            FillChildren(item, subDirs);

            item.RemoveLeafNodesWithoutArea();
            item.SumAreaMetrics();
            item.NormalizeWeightMetrics();

            return(item);
        }
        public HierarchicalDataContext CreateHierarchyFromFilesystem(string path, bool subDirs)
        {
            var item = new HierarchicalData(path);

            FillChildren(item, subDirs);

            item.RemoveLeafNodesWithoutArea();
            item.SumAreaMetrics();
            item.NormalizeWeightMetrics();

            Debug.WriteLine("Nodes: " + item.CountLeafNodes());
            return(new HierarchicalDataContext(item));
        }
        public void RemoveLeafNodesWithoutArea_ThrowsIfSingularRootNodeHasNoArea()
        {
            // Arrange
            var root    = new HierarchicalData("root");
            var a_level = new HierarchicalData("a_level");
            var a_leaf  = new HierarchicalData("a_leaf", double.NaN);

            root.AddChild(a_level);
            a_leaf.AddChild(a_leaf);

            // Nothing left but the root node!
            Assert.Throws(typeof(Exception), () => root.RemoveLeafNodesWithoutArea());

            // Assert
            Assert.AreEqual("root", root.Name);
            Assert.AreEqual(0, root.Children.Count);
            Assert.IsTrue(double.IsNaN(root.AreaMetric));
        }
        public void RemoveLeafNodesWithoutArea_WorksRecursively()
        {
            // Arrange
            var root    = new HierarchicalData("root");
            var a_leaf  = new HierarchicalData("a_leaf", 1);
            var b_empty = new HierarchicalData("b");
            var c_level = new HierarchicalData("c");
            var c_leaf  = new HierarchicalData("c_leaf", double.NaN);

            root.AddChild(a_leaf);
            root.AddChild(b_empty);
            root.AddChild(c_level);
            c_level.AddChild(c_leaf);

            root.RemoveLeafNodesWithoutArea();

            // Assert
            // After c_leaf was deleted, c_level is deleted too.
            Assert.AreEqual(1, root.CountLeafNodes());
            Assert.AreEqual("root", root.Name);
            Assert.AreEqual(1, root.Children.Count);
            Assert.AreEqual("a_leaf", root.Children.First().Name);
        }