public void Test_CalculateTotalWeightMultipleLevels() { Node root = new Node { Weight = 1, Id = "A" }; root.Children.Add(new Node { Weight = 13, Id = "AA" }); root.Children.Add(new Node { Weight = 13, Id = "AB" }); Node ac = new Node { Weight = 1, Id = "AC" }; root.Children.Add(ac); ac.Children.Add(new Node { Weight = 4, Id = "ACA" }); ac.Children.Add(new Node { Weight = 4, Id = "ACB" }); Node acc = new Node { Weight = 0, Id = "ACC" }; ac.Children.Add(acc); acc.Children.Add(new Node { Weight = 1, Id = "ACCA" }); acc.Children.Add(new Node { Weight = 1, Id = "ACCB" }); acc.Children.Add(new Node { Weight = 1, Id = "ACCC" }); var result = AdventOfCode2017Day7.CalculateTotalWeight(root); Assert.AreEqual(3, acc.TotalWeight); Assert.AreEqual(12, ac.TotalWeight); Assert.AreEqual(39, root.TotalWeight); Assert.AreEqual(39, result); }
public void Test_CalculateTotalWeight() { Node root = new Node { Weight = 3 }; Assert.AreEqual(3, AdventOfCode2017Day7.CalculateTotalWeight(root)); root.Children.Add(new Node { Weight = 2 }); Assert.AreEqual(5, AdventOfCode2017Day7.CalculateTotalWeight(root)); root.Children.Add(new Node { Weight = 7 }); Assert.AreEqual(12, AdventOfCode2017Day7.CalculateTotalWeight(root)); root.Children[0].Children.Add(new Node { Weight = 1 }); Assert.AreEqual(13, AdventOfCode2017Day7.CalculateTotalWeight(root)); }