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)); }
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)); }
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)); }
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)); }
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)); }
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); }
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); }
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); }
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); }
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()); }
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)); }
public void Network_With_Invalid_Node_Type_Passed_In() { var node = new BasicNode(); var ex = Assert.Throws<ArgumentException>(() => node.Network = new DummyBasicAdjList(Guid.NewGuid())); }
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); }
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); }
public void Network_With_Null_Passed_In() { var node = new BasicNode(); var ex = Assert.Throws<ArgumentNullException>(() => node.Network = null); }
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); }
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); }
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); }
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); }
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; }
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); }