コード例 #1
0
        public void ComputeAdjacencyMatrixIsSymmetricForUndirectedGraph()
        {
            var graph = CreateTestGraph();

            Assume.That(!graph.Edges.Any(e => e.IsDirected));

            var sut = GraphAlgorithms.ComputeAdjacencyMatrix(graph);

            // Check the size
            var vertexCount = graph.Vertices.Count();

            Assert.That(sut.GetLength(0), Is.EqualTo(vertexCount));
            Assert.That(sut.GetLength(1), Is.EqualTo(vertexCount));

            // Check for symmetry
            for (int i = 0; i < vertexCount; i++)
            {
                for (int j = i + 1; j < vertexCount; j++)
                {
                    Assert.That(sut[i, j], Is.EqualTo(sut[j, i]));
                }
            }
        }