public void ConvertNetwork_VerifyEdges(int id, int n, int m, bool isDirected, Type expectedType) { //Arrange var converter = new MatrixToAdjListConverter(); var mtrx = BasicMatrixGenerator.GenerateMatrix(n, m, isDirected); converter.IncludeEdgeData = false; IBasicAdjList net = (IBasicAdjList)converter.ConvertNetwork(mtrx); INode srcNode = null; INode destNode = null; bool result = false; if (isDirected) { for (int i = 0; i < mtrx.NodeCount; i++) { for (int j = 0; j < mtrx.NodeCount; j++) { if (mtrx[i, j] > 0.0) { srcNode = net.Nodes[i]; destNode = net.Nodes[j]; result = net.IsEdge(srcNode, destNode); Assert.True(result, string.Format("An IEdge should exist for the entry [{0},{1}].", i, j)); } } } } else { for (int i = 0; i < mtrx.NodeCount; i++) { // upper triangle only for (int j = i; j < mtrx.NodeCount; j++) { if (mtrx[i, j] > 0.0) { srcNode = net.Nodes[i]; destNode = net.Nodes[j]; result = net.IsEdge(srcNode, destNode); Assert.True(result, string.Format("An IEdge should exist for the entry [{0},{1}].", i, j)); } } } } }
public void ToAdjList_VerifyEdgeDataAttribs(int id, int n, int m, bool isDirected, Type expectedType) { //Arrange var converter = new MatrixToAdjListConverter(); var mtrx = BasicMatrixGenerator.GenerateMatrix(n, m, isDirected); converter.IncludeEdgeData = true; var net = (IBasicAdjList)converter.ConvertNetwork(mtrx); // there should be 1 map of doubles Assert.Equal(1, net.EdgeAttributeCount); INode srcNode = null; INode destNode = null; double initVal, actualVal; int i = 0, j = 0; foreach (IEdge edge in net.Edges) { srcNode = edge.SourceNode; destNode = edge.DestinationNode; i = srcNode.Index; j = destNode.Index; initVal = mtrx[i, j]; actualVal = net.EdgeData.GetValue<double>(edge, 0); Assert.Equal(initVal, actualVal); } }