public void TopologicalSort_on_self_ref_can_break_cycle()
        {
            var vertexOne = new Vertex {
                Id = 1
            };

            var edgeOne = new Edge {
                Id = 1
            };

            var graph = new Multigraph <Vertex, Edge>();

            graph.AddVertex(vertexOne);

            // 1 -> {1}
            graph.AddEdge(vertexOne, vertexOne, edgeOne);

            Assert.Equal(
                new[] { vertexOne },
                graph.TopologicalSort(
                    (from, to, edges) =>
                    (from == vertexOne) &&
                    (to == vertexOne) &&
                    (edges.Intersect(new[] { edgeOne }).Count() == 1)).ToArray());
        }
Exemplo n.º 2
0
        public void AddEdges_throws_on_verticies_not_in_the_graph()
        {
            var vertexOne = new Vertex
            {
                Id = 1
            };
            var vertexTwo = new Vertex
            {
                Id = 2
            };

            var edgeOne = new Edge
            {
                Id = 1
            };

            var graph = new Multigraph <Vertex, Edge>();

            graph.AddVertex(vertexOne);

            Assert.Equal(
                CoreStrings.GraphDoesNotContainVertex(vertexTwo),
                Assert.Throws <InvalidOperationException>(() => graph.AddEdges(vertexOne, vertexTwo, new[] { edgeOne })).Message);

            Assert.Equal(
                CoreStrings.GraphDoesNotContainVertex(vertexTwo),
                Assert.Throws <InvalidOperationException>(() => graph.AddEdges(vertexTwo, vertexOne, new[] { edgeOne })).Message);
        }
        public void AddVertex_adds_a_vertex()
        {
            var vertexOne = new Vertex {
                Id = 1
            };
            var vertexTwo = new Vertex {
                Id = 2
            };

            var graph = new Multigraph <Vertex, Edge>();

            graph.AddVertex(vertexOne);
            graph.AddVertex(vertexTwo);

            Assert.Equal(2, graph.Vertices.Count());
            Assert.Equal(2, graph.Vertices.Intersect(new[] { vertexOne, vertexTwo }).Count());
        }