Example #1
0
        public void ReadArc_Reads_Directed_Edge_And_Maps_Weight_When_Present(string inputStr, int expectedSrcVtxNum, int expectedTargVtxNum, double expectedWeight)
        {
            //Arrange
            int srcNodeIndex = -1, targNodeIndex = -1;
            if (expectedSrcVtxNum != expectedTargVtxNum)
            {
                srcNodeIndex = 0;
                targNodeIndex = 1;
            }
            else
            {
                // self loops will have the same src/targ vertex num and the same index
                srcNodeIndex = 0;
                targNodeIndex = 0;
            }

            NetFileReader reader = new NetFileReader();
            reader.NetworkAdjList = BasicAdjListGenerator.GenerateAdjListWithDataAttribs(2, 0, false, true, true);   // num nodes created when the *Vertices header read

            reader.VertexNumberMap.Add(expectedSrcVtxNum, srcNodeIndex);
            if (expectedSrcVtxNum != expectedTargVtxNum)  // only add the 2nd node if not a self loop
                reader.VertexNumberMap.Add(expectedTargVtxNum, targNodeIndex);
            reader.EdgeWeightsColIndex = 0;

            //Act
            reader.ReadArc(inputStr);

            //Assert
            Assert.Equal(1, reader.Network.EdgeCount);

            // get the edge and check the mapped weight
            IEdge myEdge = null;
            foreach (IEdge edge in reader.NetworkAdjList.Edges)
            {
                myEdge = edge;
                break;
            }

            if (double.IsNaN(expectedWeight))
            {
                Assert.Equal(0, reader.NetworkAdjList.EdgeAttributeCount);
            }
            else
            {
                var edgeAttribs = (IEdgeAttributes)reader.NetworkAdjList;
                double mappedWeight = edgeAttribs.EdgeData.GetValue<double>(myEdge, reader.EdgeWeightsColIndex);

                Assert.Equal(expectedWeight, mappedWeight);
            }
        }
Example #2
0
        public void ReadArc_Reads_Directed_Edge_And_Vertex_Numbers_From_Input(string inputStr, int expectedSrcVtxNum, int expectedTargVtxNum)
        {
            //Arrange
            int srcNodeIndex = -1,targNodeIndex = -1;
            if (expectedSrcVtxNum != expectedTargVtxNum)
            {
                srcNodeIndex = 0;
                targNodeIndex = 1;
            }
            else
            {
                // self loops will have the same src/targ vertex num and the same index
                srcNodeIndex = 0;
                targNodeIndex = 0;
            }

            NetFileReader reader = new NetFileReader();
            reader.NetworkAdjList = BasicAdjListGenerator.GenerateAdjListWithDataAttribs(2, 0, false, true, true);    // num nodes created when the *Vertices header read

            reader.VertexNumberMap.Add(expectedSrcVtxNum, srcNodeIndex);
            if (expectedSrcVtxNum != expectedTargVtxNum)  // only add the 2nd node if not a self loop
                reader.VertexNumberMap.Add(expectedTargVtxNum, targNodeIndex);

            //Act
            reader.ReadArc(inputStr);

            //Assert
            Assert.Equal(1, reader.Network.EdgeCount);

            INode expectedSrcNode = reader.NetworkAdjList.Nodes[srcNodeIndex];
            INode expectedTargetNode = reader.NetworkAdjList.Nodes[targNodeIndex];

            foreach (IEdge edge in reader.NetworkAdjList.Edges)
            {
                Assert.Same(expectedSrcNode, edge.SourceNode);
                Assert.Same(expectedTargetNode, edge.DestinationNode);
            }
        }