Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UnorientedGraphEdge"/> class.
        /// </summary>
        /// <param name="from">The node from which the edge starts.</param>
        /// <param name="to">The node where the edge ends.</param>
        public UnorientedGraphEdge(GraphNode from, GraphNode to)
            : base(from, to)
        {
            Contract.Requires(from != null);
            Contract.Requires(to != null);

            from.AddIncomingEdge(this);
            to.AddOutgoingEdge(this);
        }
Example #2
0
        public void AddOutgoingEdge_success()
        {
            var node = new GraphNode();
            var toNode = new GraphNode();
            var edge = Mock.Create<GraphEdge>();
            edge.Arrange(e => e.To).Returns(toNode);
            node.AddOutgoingEdge(edge);

            Assert.AreEqual(0, node.IncomingEdges.Count);
            Assert.AreEqual(1, node.OutgoingEdges.Count);
            Assert.AreEqual(edge, node.OutgoingEdges.First());
            Assert.AreEqual(1, node.ConnectedEdges.Count);
            Assert.AreEqual(edge, node.ConnectedEdges.First());

            Assert.AreEqual(1, node.ConnectedNodes.Count);
            Assert.AreEqual(toNode, node.ConnectedNodes.First());
        }
Example #3
0
 public void ToString_success()
 {
     var node = new GraphNode<int> { Value = 3 };
     var toString = node.ToString();
     Assert.AreEqual("{3}", toString);
 }
Example #4
0
 /// <summary>
 /// Creates an edge between two nodes.
 /// </summary>
 /// <param name="from">The starting node.</param>
 /// <param name="to">The ending node.</param>
 /// <returns>
 /// The new edge.
 /// </returns>
 protected virtual GraphEdge CreateEdge(GraphNode from, GraphNode to)
 {
     return new GraphEdge(from, to);
 }