Esempio n. 1
0
 public int GetExecutableWeight(Executable executable)
 {
     return(executable.Weight + executable.Children.Sum(GetExecutableWeight));
 }
Esempio n. 2
0
        public void Day7_GetDiviatingChildWeightExecutable()
        {
            var day = new Day7();

            var children_ugml = new List <Executable>(new[]
            {
                new Executable {
                    Name = "gyxo", Entry = "ugml (61)", Weight = 61
                },
                new Executable {
                    Name = "ebii", Entry = "padx (61)", Weight = 61
                },
                new Executable {
                    Name = "jptl", Entry = "fwft (61)", Weight = 61
                },
            });

            var children_padx = new List <Executable>(new[]
            {
                new Executable {
                    Name = "pbga", Entry = "pbga (66)", Weight = 66
                },
                new Executable {
                    Name = "havc", Entry = "havc (66)", Weight = 66
                },
                new Executable {
                    Name = "qoyq", Entry = "qoyq (66)", Weight = 66
                },
            });

            var children_fwft = new List <Executable>(new[]
            {
                new Executable {
                    Name = "ktlj", Entry = "ktlj (57)", Weight = 57
                },
                new Executable {
                    Name = "cntj", Entry = "cntj (57)", Weight = 57
                },
                new Executable {
                    Name = "xhth", Entry = "xhth (57)", Weight = 57
                },
            });

            var ugml = new Executable
            {
                Name     = "ugml",
                Entry    = "ugml (68)",
                Weight   = 68,
                Children = children_ugml
            };

            var childrenRoot = new List <Executable>(new[]
            {
                ugml,
                new Executable {
                    Name = "padx", Entry = "padx (45)", Weight = 45, Children = children_padx
                },
                new Executable {
                    Name = "fwft", Entry = "fwft (72)", Weight = 72, Children = children_fwft
                },
            });

            var root = new Executable {
                Name = "tknk", Entry = "tknk (41) -> ugml, padx, fwft", Weight = 41, Children = childrenRoot
            };

            var diviatingExecutable = day.GetDiviatingChildWeightExecutable(root);

            diviatingExecutable.Executable.ShouldBe(ugml);
            diviatingExecutable.Diviation.ShouldBe(8);
        }