예제 #1
0
        public void TestcountOfNodes()
        {
            // Testcase 2
            int    n_2 = 7, q_2 = 3;
            String s_2 = "abaacab";
            GeneralTreeNode <int> root_2 = new GeneralTreeNode <int>(1);

            root_2.ChildNodes.Add(new GeneralTreeNode <int>(2));
            root_2.ChildNodes.Add(new GeneralTreeNode <int>(3));
            root_2.ChildNodes.Add(new GeneralTreeNode <int>(7));
            root_2.ChildNodes[0].ChildNodes.Add(new GeneralTreeNode <int>(4));
            root_2.ChildNodes[0].ChildNodes.Add(new GeneralTreeNode <int>(5));
            root_2.ChildNodes[1].ChildNodes.Add(new GeneralTreeNode <int>(6));

            var queries_2 = new List <Query>();

            queries_2.Add(new Query(1, 'a'));
            queries_2.Add(new Query(2, 'b'));
            queries_2.Add(new Query(3, 'a'));
            int[] output_2   = TreesAndGraphs.CountOfNodes(root_2, queries_2, s_2);
            int[] expected_2 = { 4, 1, 2 };
            Assert.AreEqual(expected_2, output_2);

            //Testcase 1
            int    n_1 = 3, q_1 = 1;
            String s_1 = "aba";
            GeneralTreeNode <int> root_1 = new GeneralTreeNode <int>(1);

            root_1.ChildNodes.Add(new GeneralTreeNode <int>(2));
            root_1.ChildNodes.Add(new GeneralTreeNode <int>(3));
            var queries_1 = new List <Query>();

            queries_1.Add(new Query(1, 'a'));
            int[] output_1   = TreesAndGraphs.CountOfNodes(root_1, queries_1, s_1);
            int[] expected_1 = { 2 };
            Assert.AreEqual(expected_1, output_1);
        }