public void RemoveEdge_Throws_When_Null_Passed_In() { //Arrange var net = new BasicAdjList(Guid.NewGuid()); //Act, Assert var ex = Assert.Throws<ArgumentNullException>(() => net.RemoveEdge(null)); }
public void RemoveEdge_With_Self_Loop() { //Arrange var net = new BasicAdjList(Guid.NewGuid()); Type expectedType = typeof(BasicEdge); INode nodeA = net.CreateNode(); IEdge edge = net.CreateEdge(nodeA, nodeA); bool result = nodeA.SuccessorList.Contains(nodeA); Assert.True(result); result = nodeA.PredecessorList.Contains(nodeA); Assert.True(result); Assert.Equal(1, nodeA.SuccessorList.Count); Assert.Equal(1, nodeA.PredecessorList.Count); net.RemoveEdge(edge); result = nodeA.SuccessorList.Contains(nodeA); Assert.False(result); result = nodeA.PredecessorList.Contains(nodeA); Assert.False(result); Assert.Equal(0, nodeA.SuccessorList.Count); Assert.Equal(0, nodeA.PredecessorList.Count); }
public void RemoveEdge_Throws_Ex_If_Edge_DNE_In_Network() { //Arrange var net = new BasicAdjList(Guid.NewGuid()); INode nodeA = net.CreateNode(); INode nodeB = net.CreateNode(); IEdge edge0 = net.CreateEdge(nodeA, nodeB); var net2 = new BasicAdjList(Guid.NewGuid()); INode node0 = net2.CreateNode(); INode node1 = net2.CreateNode(); IEdge edge1 = net2.CreateEdge(node0, node1); //Act, Assert var ex = Assert.Throws<ArgumentException>(() => net.RemoveEdge(edge1)); }
public void RemoveEdge_Throws_When_Invalid_Type_Passed_In_For_Dest_Node() { //Arrange var net = new BasicAdjList(Guid.NewGuid()); //Act, Assert var ex = Assert.Throws<ArgumentException>(() => net.RemoveEdge(new DummyBasicEdge())); }
public void RemoveEdge_Does_Not_Affect_Node_Accessor_And_Predecessor_Lists() { //Arrange var net = new BasicAdjList(Guid.NewGuid()); Type expectedType = typeof(BasicEdge); INode nodeA = net.CreateNode(); INode nodeB = net.CreateNode(); IEdge edge = net.CreateEdge(nodeA, nodeB); bool result = nodeA.SuccessorList.Contains(nodeB); Assert.True(result); result = nodeA.PredecessorList.Contains(nodeB); Assert.False(result); result = nodeB.PredecessorList.Contains(nodeA); Assert.True(result); result = nodeB.SuccessorList.Contains(nodeA); Assert.False(result); net.RemoveEdge(edge); result = nodeA.SuccessorList.Contains(nodeB); Assert.False(result); result = nodeA.PredecessorList.Contains(nodeB); Assert.False(result); result = nodeB.PredecessorList.Contains(nodeA); Assert.False(result); result = nodeB.SuccessorList.Contains(nodeA); Assert.False(result); }
public void RemoveEdge() { //Arrange var net = new BasicAdjList(Guid.NewGuid()); INode nodeA = net.CreateNode(); INode nodeB = net.CreateNode(); IEdge edge = net.CreateEdge(nodeA, nodeB); Assert.Equal(1, net.EdgeCount); Assert.Equal(1, net.Edges.Count); net.RemoveEdge(edge); Assert.Equal(0, net.EdgeCount); Assert.Equal(0, net.Edges.Count); }
public void RemoveEdges_Removes_Row_With_Matching_Key_In_EdgeData(int nodeCount, int edgeCount, int[] removalIndices) { Random rand = new Random(); var net = new BasicAdjList(Guid.NewGuid()); var table = new DataAttributeTable<IEdge>(); table.Network = net; net.EdgeData = table; for (int i = 0; i < nodeCount; i++) net.CreateNode(); IList<IEdge> edges = new List<IEdge>(); for (int i = 0; i < edgeCount; i++) { edges.Add( net.CreateEdge(net.Nodes[rand.Next(nodeCount)], net.Nodes[rand.Next(nodeCount)])); } IEdge edgeToRemove = null; int ctr = 0; var count = net.NodeCount; for (int i = 0; i < removalIndices.Length; i++) { ctr++; edgeToRemove = edges[removalIndices[i]]; net.RemoveEdge(edgeToRemove); Assert.Equal((count - ctr), net.EdgeCount); Assert.Equal((count - ctr), table.RowCount); Assert.False(table.RowOwnerMap.ContainsKey(edgeToRemove)); } }
public void ChangeEventsEnabled_When_False_Prevents_NetworkChanged_Fired_When_RemoveEdge_Is_Called(int nodeCount, int edgeCount, int edgesToRemove) { //Arrange var net = new BasicAdjList(Guid.NewGuid()); Random rand = new Random(); for (int i = 0; i < nodeCount; i++) net.CreateNode(); INode nodeA = null; INode nodeB = null; IEdge[] edges = new IEdge[edgeCount]; for (int i = 0; i < edgeCount; i++) { nodeA = net.Nodes[rand.Next(nodeCount)]; nodeB = net.Nodes[rand.Next(nodeCount)]; edges[i] = net.CreateEdge(nodeA, nodeB); } //--------------------- var helper = new NetworkChangedEventsTestHelper(); net.NetworkChanged += new NetworkChangedEventHandler<INetwork, NetworkChangedEventArgs>(helper.NetworkChanged_DummyHandler); net.ChangeEventsEnabled = false; for (int i = 0; i < edges.Length; i++) { net.RemoveEdge(edges[i]); } Assert.Equal(0, helper.NetworkChanged_TimesCalled); }
public void NetworkChanged_Args_Contains_Edge_After_RemoveEdge_Is_Called() { //Arrange var net = new BasicAdjList(Guid.NewGuid()); var helper = new NetworkChangedEventsTestHelper(); net.NetworkChanged += new NetworkChangedEventHandler<INetwork, NetworkChangedEventArgs>(helper.NetworkChanged_DummyHandler); var nodeA = net.CreateNode(); var nodeB = net.CreateNode(); var nodeC = net.CreateNode(); var edgeA = net.CreateEdge(nodeA, nodeB); var edgeB = net.CreateEdge(nodeA, nodeB); helper.Reset(); net.RemoveEdge(edgeB); var argItem = helper.LastArgumentRecieved.EdgeRemoved; Assert.Same(argItem, edgeB); }