Exemplo n.º 1
0
            public CircusProgram(IEnumerable <ProgramNodeDeclaration> programNodes)
            {
                var nodeDictionary = new FlexibleDictionary <string, ProgramTreeNode>();

                // Register all nodes
                foreach (var node in programNodes)
                {
                    nodeDictionary[node.Name] = new(new(node));
                }

                // Declare the relationships
                var availableChildren = new HashSet <string>(nodeDictionary.Keys);

                foreach (var node in programNodes)
                {
                    if (node.IsLeafNode)
                    {
                        continue;
                    }

                    foreach (var child in node.ChildrenNodes)
                    {
                        nodeDictionary[node.Name].AddChild(nodeDictionary[child]);
                        availableChildren.Remove(child);
                    }
                }

                // Identify the tree root
                var rootName = availableChildren.Single();

                programTree = new(nodeDictionary[rootName]);
            }
Exemplo n.º 2
0
        public void DaySeven_PartOne_ReturnsBottomDisc()
        {
            var input = File.ReadAllLines($"{inputsPrefix}Day7.txt");
            var tower = new ProgramTree(input);

            var result = tower.GetBottomDisc();

            Assert.NotNull(result);
            Assert.Equal("uownj", result.Name);
        }
Exemplo n.º 3
0
        public void DaySeven_PartTwo_ReturnsWeightDifference()
        {
            var input = File.ReadAllLines($"{inputsPrefix}Day7.txt");
            var tower = new ProgramTree(input);

            var bottomDisc = tower.GetBottomDisc();

            tower.BuildTree(bottomDisc);

            var result = tower.DetermineOptimalWeightOfUnbalancedDisc();

            Assert.Equal(596, result);
        }
Exemplo n.º 4
0
        public void GetBottomDiscShould_ReturnBottomDisc()
        {
            var input = new[]
            {
                "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 tree   = new ProgramTree(input);
            var result = tree.GetBottomDisc();

            Assert.Equal("tknk", result.Name);
        }
Exemplo n.º 5
0
        public void ConstructorShould_PopulateDiscs()
        {
            var input = new []
            {
                "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 tree = new ProgramTree(input);

            Assert.Equal(13, tree.Discs.Count);
            Assert.Equal("pbga", tree.Discs.First().Name);
            Assert.Equal("cntj", tree.Discs.Last().Name);
        }
Exemplo n.º 6
0
        public void BuildTreeShould_PopulateChildren()
        {
            var input = new[]
            {
                "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 tower      = new ProgramTree(input);
            var bottomDisc = tower.GetBottomDisc();

            tower.BuildTree(bottomDisc);

            Assert.NotNull(tower.Discs);
            foreach (var disc in tower.Discs.Where(d => d.HasChildren))
            {
                Assert.NotNull(disc.ChildDiscs);
            }
        }
Exemplo n.º 7
0
        private void UpdateProgramTree()                                                                                                //обновление дерева с установленными программами
        {
            ProgramTree.Nodes.Clear();                                                                                                  //очистка дерева

            if (parentForm.GetTableFromDB("SELECT EXISTS(SELECT * FROM host_programs WHERE host_id=" + host_id + ");", 1)[0][0] == "1") // если у узла есть программы
            {
                foreach (string[] vendors in parentForm.GetTableFromDB("SELECT DISTINCT vendor FROM programs WHERE id IN (SELECT program_id FROM host_programs WHERE host_id=" + host_id + ");", 1))
                {
                    //то поочереди добавляем вектки с производителями
                    ProgramTree.Nodes.Add(vendors[0], vendors[0]);

                    foreach (string[] programs in parentForm.GetTableFromDB("SELECT id, name, version FROM programs WHERE vendor='" + vendors[0] + "' AND id IN(SELECT program_id FROM host_programs WHERE host_id=" + host_id + ");", 3))
                    {
                        //а в эти ветки добавляем ветки с программами от этих производителей
                        ProgramTree.Nodes[vendors[0]].Nodes.Add(programs[0], programs[1] + " Version: " + programs[2]);
                    }
                }
            }

            ProgramTree.Update(); //перерисовка дерева
        }
Exemplo n.º 8
0
 private void collapse_programs_button_Click(object sender, EventArgs e)
 {
     ProgramTree.CollapseAll();
 }
Exemplo n.º 9
0
 private void expand_programs_button_Click(object sender, EventArgs e)
 {
     ProgramTree.ExpandAll();
 }