コード例 #1
0
        public void IsConnectedTest3()
        {
            // arrange
            СonnectedСomponent connectedСomponent = new СonnectedСomponent();
            Graph <CVertex>    graph = new Graph <CVertex>(6);

            graph.AddEdge(0, 1);
            graph.AddEdge(2, 3);
            graph.AddEdge(4, 5);
            bool expectedResult = false;
            // act
            bool actualResult = connectedСomponent.IsConnected(graph);

            // assert
            Assert.AreEqual(expectedResult, actualResult, "");
        }
コード例 #2
0
        //-------------------------------------------------------------------------------------------------------
        private void EnumerateGraphBySize(int pSize)
        {
            СonnectedСomponent connectedСomponent = new СonnectedСomponent();
            ArticulationPointsSearch <CVertex>     articulationPointsSearch     = new ArticulationPointsSearch <CVertex>();
            ArticulationPointsBruteForce <CVertex> articulationPointsBruteForce = new ArticulationPointsBruteForce <CVertex>();
            int length   = pSize * (pSize - 1) / 2;
            int maxValue = 1 << (length - 1);
            int maxI     = pSize - 1;

            for (int k = 0; k < maxValue; k++)
            {
                Graph <CVertex> graph     = new Graph <CVertex>(pSize);
                Graph <CVertex> graph1    = new Graph <CVertex>(pSize);
                Graph <CVertex> graph2    = new Graph <CVertex>(pSize);
                int             val       = k;
                StringBuilder   iAsString = new StringBuilder();
                for (int i = 0; i < pSize; i++)
                {
                    for (int j = i + 1; j < pSize; j++)
                    {
                        int bin = val & 1;
                        if (bin != 0)
                        {
                            graph.AddEdge(i, j);
                            graph1.AddEdge(i, j);
                            graph2.AddEdge(i, j);
                        }
                        val >>= 1;
                        string sbin = (bin == 0 ? "0" : "1");
                        iAsString.Append(sbin);
                    }
                }
                if (connectedСomponent.IsConnected(graph))
                {
                    List <int> points1         = articulationPointsSearch.FindArticulationPoints(graph1);
                    List <int> points2         = articulationPointsBruteForce.FindArticulationPoints(graph2);
                    string     points1AsString = string.Join(",", points1);
                    string     points2AsString = string.Join(",", points2);
                    Assert.AreEqual(points2AsString, points1AsString, "Different result - articulationPointsSearch and articulationPointsBruteForce.");
                }
            }
        }