Exemple #1
0
        public void RemoveNode_With_2_Nodes_And_1_Edge()
        {
            //Arrange
            var net = new BasicAdjList(Guid.NewGuid());
            BasicNode nodeA = net.CreateNode() as BasicNode;
            BasicNode nodeB = net.CreateNode() as BasicNode;
            IEdge edge = net.CreateEdge(nodeA, nodeB);

            Assert.Equal(2, net.NodeCount);
            Assert.Equal(2, net.Nodes.Count);
            Assert.Equal(1, net.EdgeCount);
            Assert.Equal(1, net.Edges.Count);

            Assert.Equal(1, nodeA.EdgeList.Count);
            Assert.Equal(1, nodeA.Degree);
            Assert.Equal(0, nodeA.InDegree);
            Assert.Equal(1, nodeA.OutDegree);
            Assert.Equal(1, nodeB.EdgeList.Count);
            Assert.Equal(1, nodeB.Degree);
            Assert.Equal(1, nodeB.InDegree);
            Assert.Equal(0, nodeB.OutDegree);

            net.RemoveNode(nodeA);

            Assert.Equal(1, net.NodeCount);
            Assert.Equal(1, net.Nodes.Count);
            Assert.Equal(0, net.EdgeCount);
            Assert.Equal(0, net.Edges.Count);

            Assert.Equal(0, nodeA.EdgeList.Count);
            Assert.Equal(0, nodeA.Degree);
            Assert.Equal(0, nodeA.InDegree);
            Assert.Equal(0, nodeA.OutDegree);
            Assert.Equal(0, nodeB.EdgeList.Count);
            Assert.Equal(0, nodeB.Degree);
            Assert.Equal(0, nodeB.InDegree);
            Assert.Equal(0, nodeB.OutDegree);
        }
Exemple #2
0
        public void RemoveNode_WithSelfLoop()
        {
            //Arrange
            var net = new BasicAdjList(Guid.NewGuid());
            INode nodeA = net.CreateNode();
            INode nodeB = net.CreateNode();
            INode nodeC = net.CreateNode();
            IEdge edge0 = net.CreateEdge(nodeB, nodeC);
            IEdge edge1 = 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.RemoveNode(nodeA);

            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);
        }
Exemple #3
0
        public void RemoveNode_With_2_Nodes()
        {
            //Arrange
            var net = new BasicAdjList(Guid.NewGuid());
            INode nodeA = net.CreateNode();
            INode nodeB = net.CreateNode();

            Assert.Equal(2, net.NodeCount);
            Assert.Equal(2, net.Nodes.Count);
            Assert.Equal(0, net.EdgeCount);
            Assert.Equal(0, net.Edges.Count);

            net.RemoveNode(nodeB);

            Assert.Equal(1, net.NodeCount);
            Assert.Equal(1, net.Nodes.Count);
            Assert.Equal(0, net.EdgeCount);
            Assert.Equal(0, net.Edges.Count);
        }
Exemple #4
0
 public void RemoveNode_Throws_When_Invalid_Type_Passed_In_For_Dest_Node()
 {
     //Arrange
     var net = new BasicAdjList(Guid.NewGuid());
     var ex = Assert.Throws<ArgumentException>(() => net.RemoveNode(new DummyBasicNode()));
 }
Exemple #5
0
 public void RemoveNode_Throws_When_Null_Passed_In()
 {
     //Arrange
     var net = new BasicAdjList(Guid.NewGuid());
     var ex = Assert.Throws<ArgumentNullException>(() => net.RemoveNode(null));
 }
Exemple #6
0
        public void RemoveNode_Fuzz3(int targetNodeIndex, int initDegree, int initPredCount, int initSuccCount, int expectedNodeCount, int expectedEdgeCount)
        {
            //Arrange
            var net = new BasicAdjList(Guid.NewGuid());
            INode nodeA = net.CreateNode();
            INode nodeB = net.CreateNode();
            INode nodeC = net.CreateNode();
            INode nodeD = net.CreateNode();
            INode nodeE = net.CreateNode();
            INode nodeF = net.CreateNode();

            IEdge e0 = net.CreateEdge(nodeA, nodeA);
            IEdge e1 = net.CreateEdge(nodeC, nodeA);
            IEdge e2 = net.CreateEdge(nodeE, nodeC);
            IEdge e3 = net.CreateEdge(nodeE, nodeE);
            IEdge e4 = net.CreateEdge(nodeD, nodeB);

            INode targetNode = net.Nodes[targetNodeIndex];

            Assert.NotNull(targetNode.Network);
            Assert.Equal(initDegree, targetNode.Degree);
            Assert.Equal(initPredCount, targetNode.PredecessorList.Count);
            Assert.Equal(initSuccCount, targetNode.SuccessorList.Count);

            net.RemoveNode(targetNode);

            Assert.Null(targetNode.Network);
            Assert.Equal(0, targetNode.Degree);
            Assert.Equal(0, targetNode.PredecessorList.Count);
            Assert.Equal(0, targetNode.SuccessorList.Count);
            Assert.Equal(0, ((BasicNode)targetNode).EdgeList.Count);

            Assert.Equal(expectedNodeCount, net.NodeCount);
            Assert.Equal(expectedEdgeCount, net.EdgeCount);
        }
Exemple #7
0
        public void RemoveNode_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();

            var ex = Assert.Throws<ArgumentException>(() => net.RemoveNode(node0));
        }
Exemple #8
0
        public void RemoveNode_Fuzz()
        {
            //Arrange
            var net = new BasicAdjList(Guid.NewGuid());
            INode nodeA = net.CreateNode();
            INode nodeB = net.CreateNode();
            INode nodeC = net.CreateNode();
            INode nodeD = net.CreateNode();
            INode nodeE = net.CreateNode();

            IEdge e0 = net.CreateEdge(nodeA, nodeB);
            IEdge e1 = net.CreateEdge(nodeC, nodeB);
            IEdge e2 = net.CreateEdge(nodeC, nodeD);
            IEdge e3 = net.CreateEdge(nodeE, nodeE);

            Assert.NotNull(nodeB.Network);
            Assert.Equal(1, nodeA.Degree);
            Assert.Equal(2, nodeB.Degree);
            Assert.Equal(2, nodeC.Degree);
            Assert.Equal(1, nodeD.Degree);
            Assert.Equal(2, nodeE.Degree);

            Assert.Equal(0, nodeA.PredecessorList.Count);
            Assert.Equal(2, nodeB.PredecessorList.Count);
            Assert.Equal(0, nodeC.PredecessorList.Count);
            Assert.Equal(1, nodeD.PredecessorList.Count);
            Assert.Equal(1, nodeE.PredecessorList.Count);
            Assert.Equal(1, nodeA.SuccessorList.Count);
            Assert.Equal(0, nodeB.SuccessorList.Count);
            Assert.Equal(2, nodeC.SuccessorList.Count);
            Assert.Equal(0, nodeD.SuccessorList.Count);
            Assert.Equal(1, nodeE.SuccessorList.Count);

            net.RemoveNode(nodeB);

            Assert.Equal(0, nodeA.Degree);
            //
            Assert.Equal(1, nodeC.Degree);
            Assert.Equal(1, nodeD.Degree);
            Assert.Equal(2, nodeE.Degree);

            Assert.Equal(0, nodeA.PredecessorList.Count);
            //
            Assert.Equal(0, nodeC.PredecessorList.Count);
            Assert.Equal(1, nodeD.PredecessorList.Count);
            Assert.Equal(1, nodeE.PredecessorList.Count);
            Assert.Equal(0, nodeA.SuccessorList.Count);
            //
            Assert.Equal(1, nodeC.SuccessorList.Count);
            Assert.Equal(0, nodeD.SuccessorList.Count);
            Assert.Equal(1, nodeE.SuccessorList.Count);

            Assert.Null(nodeB.Network);
            Assert.Equal(0, nodeB.Degree);
            Assert.Equal(0, ((BasicNode)nodeB).EdgeList.Count);
            Assert.Equal(0, nodeB.PredecessorList.Count);
            Assert.Equal(0, nodeB.SuccessorList.Count);

            Assert.Null(e0.Network);
            Assert.Null(e0.SourceNode);
            Assert.Null(e0.DestinationNode);

            Assert.Null(e1.Network);
            Assert.Null(e1.SourceNode);
            Assert.Null(e1.DestinationNode);
        }
Exemple #9
0
        public void RemoveNode_DoesNotAffectNodeAccessorAndPredecessorLists()
        {
            //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.RemoveNode(nodeB);

            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 RemoveNode_Removes_Row_With_Matching_Key_In_NodeData(int nodeCount, int [] removalIndices)
        {
            var net = new BasicAdjList(Guid.NewGuid());
            var table = new DataAttributeTable<INode>();
            table.Network = net;
            net.NodeData = table;

            IList<INode> nodes = new List<INode>();
            for (int i = 0; i < nodeCount; i++)
            {
                nodes.Add(net.CreateNode());
                Assert.Equal((i + 1), net.NodeCount);
                Assert.Equal((i + 1), table.RowCount);
                Assert.True(table.RowOwnerMap.ContainsKey(nodes[i]));
            }

            INode nodeToRemove = null;
            int ctr = 0;
            var count = net.NodeCount;
            for (int i = 0; i < removalIndices.Length; i++)
            {
                ctr++;
                nodeToRemove = nodes[removalIndices[i]];
                net.RemoveNode(nodeToRemove);
                Assert.Equal((count - ctr), net.NodeCount);
                Assert.Equal((count - ctr), table.RowCount);
                Assert.False(table.RowOwnerMap.ContainsKey(nodeToRemove));
            }
        }
        public void ChangeEventsEnabled_When_False_Prevents_NetworkChanged_Fired_When_RemoveNode_Is_Called(int nodeCount, int removeCount)
        {
            //Arrange
            var net = new BasicAdjList(Guid.NewGuid());
            for (int i = 0; i < nodeCount; i++)
                net.CreateNode();
            //---------------------

            var helper = new NetworkChangedEventsTestHelper();
            net.NetworkChanged += new NetworkChangedEventHandler<INetwork, NetworkChangedEventArgs>(helper.NetworkChanged_DummyHandler);

            net.ChangeEventsEnabled = false;
            for (int i = 0; i < removeCount; i++)
            {
                net.RemoveNode(net.Nodes[0]);
            }

            Assert.Equal(0, helper.NetworkChanged_TimesCalled);
        }
        public void NetworkChanged_Args_Contains_Node_After_RemoveNode_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();

            helper.Reset();
            net.RemoveNode(nodeB);

            var argItem = helper.LastArgumentRecieved.NodeRemoved;
            Assert.Same(argItem, nodeB);
        }