Пример #1
0
        public void SubgraphConstructedCorrectly()
        {
            var vertices = new List <Vertex <object> >
            {
                new Vertex <object>(1),
                new Vertex <object>(2),
                new Vertex <object>(3),
                new Vertex <object>(4),
                new Vertex <object>(5),
                new Vertex <object>(6),
                new Vertex <object>(7)
            };
            var edges = new List <Edge <object> >
            {
                new Edge <object>(1, 1, 3),
                new Edge <object>(2, 2, 3),
                new Edge <object>(3, 3, 4),
                new Edge <object>(4, 3, 5),
                new Edge <object>(5, 4, 5),
                new Edge <object>(6, 5, 6),
                new Edge <object>(7, 5, 7)
            };
            var testGraph        = new Graph <object, object>(vertices, edges);
            var subgraphVertices = new uint[] { 3, 4, 5 };
            var subGraph         = GraphAlgorithms.GetSubgraph(testGraph, subgraphVertices);

            Assert.That(subGraph.Vertices.Select(v => v.Id), Is.EquivalentTo(subgraphVertices));
            Assert.That(subGraph.Edges.Select(v => v.Id), Is.EquivalentTo(new ulong[] { 3, 4, 5 }));
            Assert.That(subGraph.GetVertexFromId(3).EdgeIds, Is.EquivalentTo(new ulong[] { 3, 4 }));
            Assert.That(subGraph.GetVertexFromId(4).EdgeIds, Is.EquivalentTo(new ulong[] { 3, 5 }));
            Assert.That(subGraph.GetVertexFromId(5).EdgeIds, Is.EquivalentTo(new ulong[] { 4, 5 }));
        }