Esempio n. 1
0
        public void AddEdge_IncrementsDegree_ForSelfLoop()
        {
            var net =new BasicAdjList(Guid.NewGuid());
            BasicNode node0 = new BasicNode(net);
            BasicNode node1 = new BasicNode(net);

            BasicEdge edge0 = new BasicEdge(net, node0, node0);

            int degree = node0.Degree;
            Assert.Equal(0, degree);
            node0.AddEdge(edge0);
            degree = node0.Degree;
            Assert.Equal(2, degree);
        }
Esempio n. 2
0
        public void Ctor()
        {
            //Arrange
            var net = new BasicAdjList(Guid.NewGuid());
            var nodeA = new BasicNode(net);
            var nodeB = new BasicNode(net);
            var edge= new BasicEdge(net, nodeA, nodeB);

            Assert.NotNull(edge);
            Assert.NotNull(edge.Network);
            Assert.NotNull(edge.SourceNode);
            Assert.NotNull(edge.DestinationNode);
            Assert.Same(net, edge.Network);
            Assert.Same(nodeA, edge.SourceNode);
            Assert.Same(nodeB, edge.DestinationNode);
        }
Esempio n. 3
0
        public IEdge CreateEdge(INode source, INode destination)
        {
            IBasicEdge edge = new BasicEdge(this, source, destination, NextAvailableEdgeIndex++);
            ((IBasicNode)source).AddEdge(edge);
            ((IBasicNode)destination).AddEdge(edge);
            _edges.Add(edge);

            if (EdgeData != null)
                EdgeData.AddRow(edge);
            if(ChangeEventsEnabled)
            {
                var arg = new NetworkChangedEventArgs();
                arg.EdgeAdded = edge;
                OnNetworkChanged(arg);
            }
            return edge;
        }
Esempio n. 4
0
        public void DestinationNode()
        {
            //Arrange
            var net = new BasicAdjList(Guid.NewGuid());
            var nodeA = new BasicNode(net);
            var nodeB = new BasicNode(net);
            BasicNode nodeC = new BasicNode(net);
            var edge= new BasicEdge(net, nodeA, nodeB);

            //Act
            edge.DestinationNode = nodeC;

            //Assert
            Assert.NotNull(edge.DestinationNode);
            Assert.Same(nodeC, edge.DestinationNode);
        }
Esempio n. 5
0
        public void SourceNode_Throws_Ex_When_Null_Is_Assigned()
        {
            //Arrange
            var net = new BasicAdjList(Guid.NewGuid());
            var nodeA = new BasicNode(net);
            var nodeB = new BasicNode(net);
            BasicNode nodeC = new BasicNode(net);
            var edge= new BasicEdge(net, nodeA, nodeB);

            //Act, Assert
            var ex = Assert.Throws<ArgumentNullException>(() => edge.SourceNode = null);
        }
Esempio n. 6
0
        public void SourceNode_Throws_Ex_When_Invalid_Node_Type_Passed_In()
        {
            //Arrange
            var net = new BasicAdjList(Guid.NewGuid());
            var nodeA = new BasicNode(net);
            var nodeB = new BasicNode(net);
            BasicNode nodeC = new BasicNode(net);
            var edge= new BasicEdge(net, nodeA, nodeB);

            //Act, Assert
            var ex = Assert.Throws<ArgumentException>(() => edge.SourceNode = new DummyBasicNode());
        }
Esempio n. 7
0
 public void Network_With_Null_Passed_In()
 {
     var edge= new BasicEdge();
     var ex = Assert.Throws<ArgumentNullException>(() => edge.Network = null);
 }
Esempio n. 8
0
 public void Network_With_Invalid_Node_Type_Passed_In()
 {
     var edge= new BasicEdge();
     var ex = Assert.Throws<ArgumentException>(() => edge.Network = new DummyBasicAdjList(Guid.NewGuid()));
 }
Esempio n. 9
0
        public void Network()
        {
            //Arrange
            var net = new BasicAdjList(Guid.NewGuid());

            var edge= new BasicEdge();
            edge.Network = net;

            Assert.NotNull(edge.Network);
            Assert.Same(net, edge.Network);
        }
Esempio n. 10
0
        public void Detatch_DetachtesEdgeFromAll()
        {
            //Arrange
            var net = new BasicAdjList(Guid.NewGuid());
            var nodeA = new BasicNode(net);
            var nodeB = new BasicNode(net);
            var edge= new BasicEdge(net, nodeA, nodeB);

            Assert.NotNull(edge.Network);
            Assert.NotNull(edge.SourceNode);
            Assert.NotNull(edge.DestinationNode);

            edge.Detatch();

            Assert.Null(edge.Network);
            Assert.Null(edge.SourceNode);
            Assert.Null(edge.DestinationNode);
        }
Esempio n. 11
0
        public void RemoveEdge_DecrementsDegree()
        {
            var net =new BasicAdjList(Guid.NewGuid());
            BasicNode node0 = new BasicNode(net);
            BasicNode node1 = new BasicNode(net);

            BasicEdge edge0 = new BasicEdge(net, node0, node1);

            node0.AddEdge(edge0);
            Assert.Equal(1, node0.Degree);

            node0.RemoveEdge(edge0);
            Assert.Equal(0, node0.Degree);
        }