public HierarchicalDataContext GetColoredNestedExample() { var root = new HierarchicalData("root"); var scheme = new ColorScheme(new[] { "c1", "c2", "c3" }); HierarchicalData child; child = new HierarchicalData("ra", 10) { ColorKey = "c1" }; root.AddChild(child); child = new HierarchicalData("ra", 10) { ColorKey = "c2" }; root.AddChild(child); child = new HierarchicalData("ra", 10) { ColorKey = "c3" }; root.AddChild(child); child = new HierarchicalData("ra", 10) { ColorKey = "unknown" }; root.AddChild(child); root.SumAreaMetrics(); Console.WriteLine(root.CountLeafNodes()); return(new HierarchicalDataContext(root, scheme)); }
public void Shrink_StopsOnMultipleChildren() { var a = new HierarchicalData("a"); var b = new HierarchicalData("b"); var c = new HierarchicalData("c"); var d = new HierarchicalData("d"); a.AddChild(b); b.AddChild(c); b.AddChild(d); // b has two children var data = a.Shrink(); Assert.AreEqual("b", data.Name); }
public HierarchicalDataContext ShowCollisionWithLastElementProblem() { var root = new HierarchicalData(""); root.AddChild(new HierarchicalData("6", 10)); root.AddChild(new HierarchicalData("6", 10)); root.AddChild(new HierarchicalData("4", 10)); root.AddChild(new HierarchicalData("3", 10)); root.AddChild(new HierarchicalData("1", 10)); root.AddChild(new HierarchicalData("3", 10)); root.AddChild(new HierarchicalData("1", 10)); root.AddChild(new HierarchicalData("3", 10)); root.AddChild(new HierarchicalData("1", 10)); root.SumAreaMetrics(); return(new HierarchicalDataContext(root)); }
private void FillChildren(HierarchicalData root, bool recursive) { try { // Files (leaf nodes) var files = Directory.EnumerateFiles(root.Name); foreach (var file in files) { var fi = new FileInfo(file); if (fi.Length > 1000) { // Skip 0 files. Division by 0. root.AddChild(new HierarchicalData(file, fi.Length, _random.Next(-1, 345))); } } } catch (Exception) { // } if (recursive == false) { return; } var subDirs = Directory.EnumerateDirectories(root.Name); try { foreach (var dir in subDirs) { var subTreeRoot = new HierarchicalData(dir, 0); root.AddChild(subTreeRoot); FillChildren(subTreeRoot, true); } } catch (Exception) { // } }
internal HierarchicalData GetNumberOfCircles(int circles, int radius) { var root = new HierarchicalData(""); for (var i = 0; i < circles; i++) { root.AddChild(new HierarchicalData("i", radius)); } root.SumAreaMetrics(); return(root); }
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); }
private void InsertLeaf(HierarchicalData parent, Artifact item, string leafName) { if (!IsAccepted(item)) { // Division 0. No area = no code lines, no weight = no commits return; } var leaf = new HierarchicalData(leafName, GetArea(item), GetWeight(item), GetWeightIsAlreadyNormalized()); leaf.Description = GetDescription(item); leaf.ColorKey = GetColorKey(item); leaf.Tag = item.LocalPath; parent.AddChild(leaf); }
public void Shrink_StopsAtLeafNode() { var a = new HierarchicalData("a"); var b = new HierarchicalData("b"); var c = new HierarchicalData("c"); a.AddChild(b); b.AddChild(c); // c is leaf node var data = a.Shrink(); Assert.AreEqual("c", data.Name); }
protected HierarchicalData GetBranch(HierarchicalData parent, string branch) { var found = parent.Children.FirstOrDefault(child => child.Name == branch); if (found == null) { var newBranch = new HierarchicalData(branch); parent.AddChild(newBranch); // Call when parent relation is set. newBranch.Description = GetDescription(newBranch); found = newBranch; } return((HierarchicalData)found); }
public HierarchicalDataContext GetFlatExample() { var root = new HierarchicalData(""); root.AddChild(new HierarchicalData("6", 300, 8)); root.AddChild(new HierarchicalData("6", 60, 7)); root.AddChild(new HierarchicalData("4", 40, 6)); root.AddChild(new HierarchicalData("3", 30, 6)); root.AddChild(new HierarchicalData("1", 10, 6)); root.AddChild(new HierarchicalData("2", 20, 200)); root.AddChild(new HierarchicalData("2", 20, 1)); var child = new HierarchicalData("3", 30, 1); root.AddChild(child); root.SumAreaMetrics(); root.NormalizeWeightMetrics(); return(new HierarchicalDataContext(root)); }
private void FillChildren(HierarchicalData data, int numChildren, int depth) { depth--; for (var i = 0; i < numChildren; i++) { HierarchicalData newChild; if (GetRandomIsLeaf() || depth <= 0) { newChild = new HierarchicalData("leaf", GetRandomArea()); } else { newChild = new HierarchicalData("folder"); FillChildren(newChild, GetRandmomNumberOfChildren(), depth); } data.AddChild(newChild); } }
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)); }