Beispiel #1
0
        public void Day7_GetExecutableWeight()
        {
            var input = "fwft (72) -> ktlj, cntj, xhth";

            var day = new Day7();

            var children = 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 exe = new Executable {
                Name = "fwft", Entry = input, Weight = 72, Children = children
            };

            var weight = day.GetExecutableWeight(exe);

            weight.ShouldBe(243);
        }
Beispiel #2
0
        public void Day7_PopulateChildLists()
        {
            var input = "fwft (72) -> ktlj, cntj, xhth";

            var day = new Day7();

            var exe = new Executable {
                Name = "fwft", Entry = input
            };

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

            day.PopulateChildLists(executables);

            exe.Children.Count.ShouldBe(3);
            exe.Children.ShouldContain(c => c.Name == "ktlj");
            exe.Children.ShouldContain(c => c.Name == "cntj");
            exe.Children.ShouldContain(c => c.Name == "xhth");
        }
Beispiel #3
0
        public void Day7_GetChildDepth()
        {
            var day = new Day7();

            var child1 = new Executable {
                Name = "ktlj", Entry = "ktlj (57)"
            };
            var child2 = new Executable {
                Name = "cntj", Entry = "cntj (57)"
            };
            var child3 = new Executable {
                Name = "xhth", Entry = "xhth (57)"
            };

            var root = new Executable
            {
                Name     = "fwft",
                Entry    = "fwft (72) -> ktlj, cntj, xhth",
                Children = new List <Executable>(new[] { child1, child2, child3 })
            };

            var result = day.GetChildDepth(root);

            result.ShouldBe(1);
        }
Beispiel #4
0
        public void Day7_PopulateChildListsWithThreeLevels()
        {
            var day = new Day7();

            var executables = new List <Executable>(new[]
            {
                new Executable {
                    Name = "fwft", Entry = "fwft (72) -> ktlj"
                },
                new Executable {
                    Name = "ktlj", Entry = "ktlj (57) -> cntj"
                },
                new Executable {
                    Name = "cntj", Entry = "cntj (57) -> xhth"
                },
                new Executable {
                    Name = "xhth", Entry = "xhth (57)"
                },
            });

            day.PopulateChildLists(executables);

            executables[0].Children.Count.ShouldBe(1);
            executables[0].Children.ShouldContain(c => c.Name == "ktlj");
            executables[1].Children.Count.ShouldBe(1);
            executables[1].Children.ShouldContain(c => c.Name == "cntj");
            executables[2].Children.Count.ShouldBe(1);
            executables[2].Children.ShouldContain(c => c.Name == "xhth");
            executables[3].Children.Count.ShouldBe(0);
        }
Beispiel #5
0
        public void Day7_GetChildrenFromEntryWhenNone()
        {
            var input = "ktlj (57)";

            var day = new Day7();

            var exe = new Executable {
                Name = "ktlj", Entry = input
            };

            var executables = new List <Executable>(new[]
            {
                exe,
                new Executable {
                    Name = "cntj"
                },
                new Executable {
                    Name = "xhth"
                },
            });

            var results = day.GetChildren(exe, executables);

            results.Count.ShouldBe(0);
        }
Beispiel #6
0
        public void Day7_GetChildrenFromEntry()
        {
            var input = "fwft (72) -> ktlj, cntj, xhth";

            var day = new Day7();

            var exe = new Executable {
                Name = "fwft", Entry = input
            };

            var executables = new List <Executable>(new[]
            {
                exe,
                new Executable {
                    Name = "ktlj"
                },
                new Executable {
                    Name = "cntj"
                },
                new Executable {
                    Name = "xhth"
                },
            });

            var results = day.GetChildren(exe, executables);

            results.Count.ShouldBe(3);
            results.ShouldContain(c => c.Name == "ktlj");
            results.ShouldContain(c => c.Name == "cntj");
            results.ShouldContain(c => c.Name == "xhth");
        }
Beispiel #7
0
            public void Day7_Test1()
            {
                var input =
                    @"pbga (66)
xhth (57)
ebii (61)
havc (66)
ktlj (57)
fwft (72) -> ktlj, cntj, xhth
qoyq (66)
padx (45) -> pbga, havc, qoyq
tknk (41) -> ugml, padx, fwft
jptl (61)
ugml (68) -> gyxo, ebii, jptl
gyxo (61)
cntj (57)";
                var day = new Day7();

                var bottomProgram = day.Run(input);

                bottomProgram.ShouldBe("tknk");
            }
Beispiel #8
0
        public void Day7_GetExecutables()
        {
            var input =
                @"pbga (66)
xhth (57)
ebii (61)
havc (66)
ktlj (57)
fwft (72) -> ktlj, cntj, xhth
qoyq (66)
padx (45) -> pbga, havc, qoyq
tknk (41) -> ugml, padx, fwft
jptl (61)
ugml (68) -> gyxo, ebii, jptl
gyxo (61)
cntj (57)";
            var day = new Day7();

            var results = day.GetExecutables(input);

            results.Count.ShouldBe(13);
            results.First().Name.ShouldBe("pbga");
            results.First().Weight.ShouldBe(66);
        }
Beispiel #9
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);
        }