Example #1
0
        public void GetIncidentEdgeWithExample()
        {
            // Create two new vertices
            var vertex1 = new Vertex <int>(2);
            var vertex2 = new Vertex <int>(4);

            // Create a graph, and add the vertices to
            // the graph
            var graph = new Graph <int>(true);

            graph.AddVertex(vertex1, vertex2);

            // Add an edge from vertex1 to vertex vertex2
            graph.AddEdge(vertex1, vertex2);

            // Retrieve the incident edge from vertex1 to vertex2
            var edge = vertex1.GetIncidentEdgeWith(vertex2);

            // Which will be a valid edge
            Assert.IsNotNull(edge);

            // Incident edges are edges "touching" the
            // vertex, irrespective of direction
            edge = vertex2.GetIncidentEdgeWith(vertex1);

            // Will also be a valid edge
            Assert.IsNotNull(edge);
        }
Example #2
0
        public void Undirected()
        {
            var vertex1 = new Vertex<int>(3);
            var vertex2 = new Vertex<int>(5);
            var vertex3 = new Vertex<int>(8);

            var graph = new Graph<int>(false);
            graph.AddVertex(vertex1);
            graph.AddVertex(vertex2);

            graph.AddEdge(vertex1, vertex2);

            var edge = vertex1.GetIncidentEdgeWith(vertex2);
            Assert.AreEqual(edge.FromVertex, vertex1);
            Assert.AreEqual(edge.ToVertex, vertex2);

            edge = vertex2.GetIncidentEdgeWith(vertex1);
            Assert.AreEqual(edge.FromVertex, vertex1);
            Assert.AreEqual(edge.ToVertex, vertex2);

            Assert.IsNull(vertex1.GetIncidentEdgeWith(vertex3));
        }
        public void Directed()
        {
            var vertex1 = new Vertex <int>(3);
            var vertex2 = new Vertex <int>(5);
            var vertex3 = new Vertex <int>(8);

            var graph = new Graph <int>(true);

            graph.AddVertex(vertex1);
            graph.AddVertex(vertex2);

            graph.AddEdge(vertex1, vertex2);

            var edge = vertex1.GetIncidentEdgeWith(vertex2);

            Assert.AreEqual(edge.FromVertex, vertex1);
            Assert.AreEqual(edge.ToVertex, vertex2);

            edge = vertex2.GetIncidentEdgeWith(vertex1);
            Assert.AreEqual(edge.FromVertex, vertex1);
            Assert.AreEqual(edge.ToVertex, vertex2);

            Assert.IsNull(vertex1.GetIncidentEdgeWith(vertex3));
        }
Example #4
0
        public void GetIncidentEdgeWithExample()
        {
            // Create two new vertices
            var vertex1 = new Vertex<int>(2);
            var vertex2 = new Vertex<int>(4);

            // Create a graph, and add the vertices to
            // the graph
            var graph = new Graph<int>(true);
            graph.AddVertex(vertex1);
            graph.AddVertex(vertex2);

            // Add an edge from vertex1 to vertex vertex2
            graph.AddEdge(vertex1, vertex2);

            // Retrieve the incident edge from vertex1 to vertex2
            var edge = vertex1.GetIncidentEdgeWith(vertex2);

            // Which will be a valid edge
            Assert.IsNotNull(edge);

            // Incident edges are edges "touching" the
            // vertex, irrespective of direction
            edge = vertex2.GetIncidentEdgeWith(vertex1);

            // Will also be a valid edge
            Assert.IsNotNull(edge);
        }