public void ReadEdgePropertyFields_Creates_An_Edge(int index, int nodeCount, string[] dataFields, int[] nodeIndices, string[] dataFieldNames, Type[] dataTypes, int[] srcFieldIndices) { // simulate initialized network var net = Blob.TestSupport.Network.BasicAdjListGenerator.GenerateAdjListWithDataAttribs(nodeCount, 0, false, false, true); var builder = new Blob.TestSupport.Network.DataAttributesBuilder(); builder.AddColumns((IEdgeAttributes)net, dataTypes, dataFieldNames, false); // get actual nodes INode nodeA = net.Nodes[nodeIndices[0]]; INode nodeB = net.Nodes[nodeIndices[1]]; var reader = new VnaAdjListReader(); reader.State = VnaFileSection.EdgeData; // simulate already the populated NodeKeyToNodeIndexMap reader.NodeKeyToNodeIndexMap.Add(dataFields[0], nodeA); reader.NodeKeyToNodeIndexMap.Add(dataFields[1], nodeB); // simulate the list of HeaderField objects that have already been created in 1st pass for (int i = 0; i < dataFields.Length;i++ ) reader.EdgeDataHeaders.Add(new HeaderField("f-" + i.ToString(), VnaFileSection.EdgeData, i, null) { AttribColumnIndex = i }); Assert.Equal(0, net.EdgeCount); reader.ReadEdgeDataFields(dataFields, net, reader.EdgeDataHeaders); Assert.Equal(1, net.EdgeCount); IEdge edge = net.Edges[0]; Assert.Same(nodeA, edge.SourceNode); Assert.Same(nodeB, edge.DestinationNode); }
public void ReadEdgePropertyFields_Reads_Fields_Into_EdgeAttribs_From_StarEdgeData_Section(int index, int nodeCount, string[] dataFields, int[] nodeIndices, string[] dataFieldNames, Type[] dataTypes, int[] srcFieldIndices) { // simulate initialized network var net = Blob.TestSupport.Network.BasicAdjListGenerator.GenerateAdjListWithDataAttribs(nodeCount, 0, false, true, true); var builder = new Blob.TestSupport.Network.DataAttributesBuilder(); builder.AddColumns((IEdgeAttributes)net, dataTypes, dataFieldNames, false); var reader = new VnaAdjListReader(); reader.State = VnaFileSection.EdgeData; // simulate already the populated NodeKeyToNodeIndexMap INode nodeA = net.Nodes[nodeIndices[0]]; INode nodeB = net.Nodes[nodeIndices[1]]; reader.NodeKeyToNodeIndexMap.Add(dataFields[0], nodeA); reader.NodeKeyToNodeIndexMap.Add(dataFields[1], nodeB); // simulate the list of HeaderField objects that have already been created in 1st pass for (int i = 0; i < dataFields.Length; i++) reader.EdgeDataHeaders.Add(new HeaderField("f-" + i.ToString(), VnaFileSection.EdgeData, i, null) { AttribColumnIndex = i }); Assert.Equal(0, net.EdgeCount); reader.ReadEdgeDataFields(dataFields, net, reader.EdgeDataHeaders); IEdge owner = net.Edges[0]; for (int i = 2; i < dataTypes.Length; i++) { if (dataTypes[i] == typeof(string)) { var val = net.EdgeData.GetValue<string>(owner, i); Assert.Equal(dataFields[i], val); } else if (dataTypes[i] == typeof(int)) { var val = net.EdgeData.GetValue<int>(owner, i); Assert.Equal(Convert.ToInt32(dataFields[i]), val); } else if (dataTypes[i] == typeof(float)) { var val = net.EdgeData.GetValue<float>(owner, i); Assert.Equal(Convert.ToSingle(dataFields[i]), val); } else if (dataTypes[i] == typeof(double)) { var val = net.EdgeData.GetValue<double>(owner, i); Assert.Equal(Convert.ToDouble(dataFields[i]), val); } else { Assert.True(false); //force a fail } } }
public void ReadEdgeDataFields_Throws_If_Not_In_Required_State(VnaFileSection state) { var reader = new VnaAdjListReader(); reader.State = state; var ex = Assert.Throws<InvalidOperationException>(() => reader.ReadEdgeDataFields(new string[] { "X" }, null, null)); }