Пример #1
0
        public void ReadArcList_Reads_Multiple_Edges_From_A_List_Including_Vertex_Numbers(string inputStr, int expectedSrcVtxNum, int[] expectedTargVtxNums, int expectedArcCount)
        {
            //Arrange
            int srcNodeIndex = 0;
            IList<int> targNodeIndeces = new List<int>();

            NetFileReader reader = new NetFileReader();
            reader.NetworkAdjList = BasicAdjListGenerator.GenerateAdjList(5, 0, false);    // assume 5 nodes were created when *Network header read

            reader.VertexNumberMap.Add(expectedSrcVtxNum, srcNodeIndex);
            for (int i = 0; i < expectedTargVtxNums.Length; i++)
            {
                int index = i + 1;  // cant be 0, that is srcNodeIndex
                if (!reader.VertexNumberMap.ContainsKey(expectedTargVtxNums[i]))
                {
                    targNodeIndeces.Add(index);
                    reader.VertexNumberMap.Add(expectedTargVtxNums[i], index);
                }
            }

            //Act
            reader.ReadArcList(inputStr);

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

            INode srcNode = reader.NetworkAdjList.Nodes[srcNodeIndex];
            INode targetNode = null;
            bool verified = true;
            for (int i = 0; i < expectedTargVtxNums.Length; i++)
            {
                // get each src and targ node
                int targNodeIndex = reader.VertexNumberMap[expectedTargVtxNums[i]];
                targetNode = reader.NetworkAdjList.Nodes[targNodeIndex];

                bool found = false;
                // check each edge for the src and targ node
                foreach (IEdge edge in reader.NetworkAdjList.Edges)
                {
                    if (edge.SourceNode == srcNode && edge.DestinationNode == targetNode)
                    {
                        found = true;
                        break;
                    }
                }

                verified &= found;
            }

            Assert.True(verified);
        }