Exemplo n.º 1
0
        public void AddEdge_Throws_Ex_If_Edge_Is_Invalid_Type()
        {
            var net =new BasicAdjList(Guid.NewGuid());
            BasicNode node0 = new BasicNode(net);

            DummyBasicEdge edge0 = new DummyBasicEdge();
            var ex = Assert.Throws<ArgumentException>(() => node0.AddEdge(edge0));
        }
Exemplo n.º 2
0
        public void AddEdge_Throws_Ex_If_Edge_Is_Null()
        {
            var net =new BasicAdjList(Guid.NewGuid());
            BasicNode node0 = new BasicNode(net);

            BasicEdge edge0 = null;
            var ex = Assert.Throws<ArgumentNullException>(() => node0.AddEdge(edge0));
        }
Exemplo n.º 3
0
 public void Ctor_With_Different_Network_Parent_Than_Source_Node()
 {
     //Arrange
     var net = new BasicAdjList(Guid.NewGuid());
     BasicAdjList net2 = new BasicAdjList(Guid.NewGuid());
     var nodeA = new BasicNode(net2);
     var nodeB = new BasicNode(net);
     var ex = Assert.Throws<ArgumentException>(() => new BasicEdge(net, nodeA, nodeB));
 }
Exemplo n.º 4
0
        public void Ctor_Throws_Ex_With_Null_Passed_InAsSourceNode()
        {
            //Arrange
            var net = new BasicAdjList(Guid.NewGuid());
            IBasicNode nodeA = null;
            var nodeB = new BasicNode(net);

            //Act, Assert
            var ex = Assert.Throws<ArgumentException>(() => new BasicEdge(net, nodeA, nodeB));
        }
Exemplo n.º 5
0
        public void Ctor_Throws_Ex_With_Null_Passed_In_As_Network()
        {
            //Assign
            IBasicAdjList net = new BasicAdjList(Guid.NewGuid());
            var nodeA = new BasicNode(net);
            var nodeB = new BasicNode(net);

            //Act, Assert
            var ex = Assert.Throws<ArgumentNullException>(() => new BasicEdge(null, nodeA, nodeB));
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
        public void Index_ByCtor()
        {
            var net =new BasicAdjList(Guid.NewGuid());
            BasicNode node0 = new BasicNode(net, 0);
            int index = node0.Index;
            Assert.Equal(0, index);

            BasicNode node1 = new BasicNode(net, 1);
            index = node1.Index;
            Assert.Equal(1, index);

            BasicNode node2 = new BasicNode(net, 2);
            index = node2.Index;
            Assert.Equal(2, index);
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
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());
        }
Exemplo n.º 11
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);
        }
        public void AddRow_Appends_New_Row_And_Updates_Map()
        {
            //Arrange
            var net = new BasicAdjList(Guid.NewGuid());
            var table = new DataAttributeTable<INode>();
            table.Network = net;

            var node = new BasicNode();

            //Act
             table.AddRow(node);

            //Assert
            Assert.Equal(table.Rows.Count, 1);

            Assert.Equal(table.RowOwnerMap.Count, 1);
            Assert.True(table.RowOwnerMap.ContainsKey(node));
        }
Exemplo n.º 13
0
 public void Network_With_Invalid_Node_Type_Passed_In()
 {
     var node = new BasicNode();
     var ex = Assert.Throws<ArgumentException>(() => node.Network = new DummyBasicAdjList(Guid.NewGuid()));
 }
Exemplo n.º 14
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);
        }
Exemplo n.º 15
0
        public void Id_MatchesNodeIndexInNetwork()
        {
            var net =new BasicAdjList(Guid.NewGuid());
            BasicNode node0 = new BasicNode(net);
            int index = node0.Index;
            Assert.Equal(node0.Index, node0.Id);

            BasicNode node1 = new BasicNode(net);
            index = node1.Index;
            Assert.Equal(node1.Index, node1.Id);

            BasicNode node2 = new BasicNode(net);
            index = node2.Index;
            Assert.Equal(node2.Index, node2.Id);
        }
Exemplo n.º 16
0
 public void Network_With_Null_Passed_In()
 {
     var node = new BasicNode();
     var ex = Assert.Throws<ArgumentNullException>(() => node.Network = null);
 }
Exemplo n.º 17
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);
        }
Exemplo n.º 18
0
        public void Detatch_DetachtesEdgeFromAll_ForNodeWithSelfLoop()
        {
            var net =new BasicAdjList(Guid.NewGuid());
            BasicNode nodeA = new BasicNode(net);
            BasicNode nodeB = new BasicNode(net);
            BasicNode nodeC = new BasicNode(net);
            BasicNode nodeD = new BasicNode(net);
            BasicNode nodeE = new BasicNode(net);
            IEdge e0 = net.CreateEdge(nodeA, nodeB);
            IEdge e1 = net.CreateEdge(nodeC, nodeB);
            IEdge e2 = net.CreateEdge(nodeC, nodeD);
            IEdge e3 = net.CreateEdge(nodeB, nodeB);

            ((BasicNode)nodeB).Detatch();

            Assert.Null(nodeB.Network);
            Assert.Equal(0, nodeA.Degree);
            Assert.Equal(0, nodeB.Degree);
            Assert.Equal(1, nodeC.Degree);
            Assert.Equal(1, nodeD.Degree);
            Assert.Equal(0, nodeE.Degree);

            Assert.Equal(0, nodeA.PredecessorList.Count);
            Assert.Equal(0, nodeB.PredecessorList.Count);
            Assert.Equal(0, nodeC.PredecessorList.Count);
            Assert.Equal(1, nodeD.PredecessorList.Count);
            Assert.Equal(0, nodeE.PredecessorList.Count);
            Assert.Equal(0, nodeA.SuccessorList.Count);
            Assert.Equal(0, nodeB.SuccessorList.Count);
            Assert.Equal(1, nodeC.SuccessorList.Count);
            Assert.Equal(0, nodeD.SuccessorList.Count);
            Assert.Equal(0, nodeE.SuccessorList.Count);
        }
Exemplo n.º 19
0
        public void Index_SetManually()
        {
            var net =new BasicAdjList(Guid.NewGuid());
            BasicNode node0 = new BasicNode(net);
            node0.Index = 33;
            int index = node0.Index;
            Assert.Equal(33, index);

            BasicNode node1 = new BasicNode(net);
            node1.Index = 7;
            index = node1.Index;
            Assert.Equal(7, index);
        }
Exemplo n.º 20
0
 public void Ctor_With_Index()
 {
     var net = new BasicAdjList(Guid.NewGuid());
     var node = new BasicNode(net, 3);
     Assert.NotNull(node);
     Assert.Equal(3, node.Index);
 }
Exemplo n.º 21
0
        public INode CreateNode()
        {
            IBasicNode node = new BasicNode(this, NextAvailableNodeIndex++);
            if (node == null)
                throw new InvalidOperationException("The node constructor returned null, no new node was created.");
            AddNewNode(node);

            return node;
        }
Exemplo n.º 22
0
        public void Network()
        {
            var net =new BasicAdjList(Guid.NewGuid());

            var node = new BasicNode();
            node.Network = net;

            Assert.NotNull(node.Network);
            Assert.Same(net, node.Network);
        }