public void Test_BalanceOneLevel() { Node root = new Node { Weight = 1, TotalWeight = 3, Id = "A" }; root.Children.Add(new Node { Weight = 1, TotalWeight = 1, Id = "AA" }); root.Children.Add(new Node { Weight = 1, TotalWeight = 1, Id = "AB" }); root.Children.Add(new Node { Weight = 0, TotalWeight = 0, Id = "AC" }); var result = AdventOfCode2017Day7.Balance(root); Assert.AreEqual(1, result.Count); Assert.AreEqual("AC", result.First().Id); Assert.AreEqual(1, result.First().BalancedWidth); Assert.AreEqual(1, result.First().Weight); Assert.AreEqual(1, result.First().TotalWeight); Assert.AreEqual(4, root.TotalWeight); }
public void Test_BalanceSecondOfThreeLevels() { Node root = new Node { Weight = 1, TotalWeight = 39, Id = "A" }; root.Children.Add(new Node { Weight = 13, TotalWeight = 13, Id = "AA" }); root.Children.Add(new Node { Weight = 13, TotalWeight = 13, Id = "AB" }); Node ac = new Node { Weight = 1, TotalWeight = 12, Id = "AC" }; root.Children.Add(ac); ac.Children.Add(new Node { Weight = 4, TotalWeight = 4, Id = "ACA" }); ac.Children.Add(new Node { Weight = 4, TotalWeight = 4, Id = "ACB" }); Node acc = new Node { Weight = 0, TotalWeight = 3, Id = "ACC" }; ac.Children.Add(acc); acc.Children.Add(new Node { Weight = 1, TotalWeight = 1, Id = "ACCA" }); acc.Children.Add(new Node { Weight = 1, TotalWeight = 1, Id = "ACCB" }); acc.Children.Add(new Node { Weight = 1, TotalWeight = 1, Id = "ACCC" }); var result = AdventOfCode2017Day7.Balance(root); Assert.AreEqual(1, result.Count); Assert.AreEqual("ACC", result.First().Id); Assert.AreEqual(1, result.First().BalancedWidth); Assert.AreEqual(1, result.First().Weight); Assert.AreEqual(4, result.First().TotalWeight); Assert.AreEqual(13, ac.TotalWeight); Assert.AreEqual(40, root.TotalWeight); }
public void Test_BalanceSingleNode() { Node root = new Node { Weight = 1, TotalWeight = 1 }; var result = AdventOfCode2017Day7.Balance(root); Assert.AreEqual(0, result.Count); result = AdventOfCode2017Day7.Balance(root, 2); Assert.AreEqual(1, result.Count); Assert.AreEqual(2, result.First().BalancedWidth); Assert.AreEqual(3, result.First().Weight); Assert.AreEqual(3, result.First().TotalWeight); }