public void AddEdge_adds_an_edge()
        {
            var vertexOne = new Vertex {
                Id = 1
            };
            var vertexTwo = new Vertex {
                Id = 2
            };

            var edgeOne = new Edge {
                Id = 1
            };
            var edgeTwo = new Edge {
                Id = 2
            };

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

            graph.AddVertices(new[] { vertexOne, vertexTwo });
            graph.AddEdge(vertexOne, vertexTwo, edgeOne);
            graph.AddEdge(vertexOne, vertexTwo, edgeTwo);

            Assert.Equal(2, graph.Edges.Count());
            Assert.Equal(2, graph.Edges.Intersect(new[] { edgeOne, edgeTwo }).Count());

            Assert.Empty(graph.GetEdges(vertexTwo, vertexOne));
            Assert.Equal(2, graph.GetEdges(vertexOne, vertexTwo).Count());
            Assert.Equal(2, graph.GetEdges(vertexOne, vertexTwo).Intersect(new[] { edgeOne, edgeTwo }).Count());
        }
Esempio n. 2
0
        public void AddEdges_adds_multiple_edges()
        {
            var vertexOne = new Vertex
            {
                Id = 1
            };
            var vertexTwo = new Vertex
            {
                Id = 2
            };

            var edgeOne = new Edge
            {
                Id = 1
            };
            var edgeTwo = new Edge
            {
                Id = 2
            };
            var edgeThree = new Edge
            {
                Id = 3
            };

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

            graph.AddVertices(new[] { vertexOne, vertexTwo });
            graph.AddEdges(vertexOne, vertexTwo, new[] { edgeOne });
            graph.AddEdges(vertexOne, vertexTwo, new[] { edgeTwo, edgeThree });

            Assert.Equal(0, graph.GetEdges(vertexTwo, vertexOne).Count());
            Assert.Equal(3, graph.GetEdges(vertexOne, vertexTwo).Count());
            Assert.Equal(3, graph.GetEdges(vertexOne, vertexTwo).Intersect(new[] { edgeOne, edgeTwo, edgeThree }).Count());
        }