public void ReadNodePropertyFields_Reads_Fields_Into_NodeAttribs_From_StarNodeData_Section(int index, string[] dataFields, string[] dataFieldNames, Type[] dataTypes, int[] srcFieldIndices) { int nodeCount = 3; // simulate initialized network var net = Blob.TestSupport.Network.BasicAdjListGenerator.GenerateAdjListWithDataAttribs(nodeCount, 0, false, true, false); var builder = new Blob.TestSupport.Network.DataAttributesBuilder(); builder.AddColumns((INodeAttributes)net, dataTypes, dataFieldNames, false); var reader = new VnaAdjListReader(); reader.State = VnaFileSection.NodeProperties; // simulate the list of HeaderField objects that would have been created in 1st pass for (int i = 0; i < dataFields.Length; i++) reader.NodePropertyHeaders.Add(new HeaderField(dataFieldNames[i], VnaFileSection.NodeProperties, srcFieldIndices[i], null) { AttribColumnIndex = srcFieldIndices[i] }); int targetNodeIndex = 1; INode owner = net.Nodes[targetNodeIndex]; reader.ReadNodePropertyFields(dataFields, net, targetNodeIndex, reader.NodePropertyHeaders); for (int i = 0; i < dataTypes.Length; i++) { if (dataTypes[i] == typeof(string)) { var val = net.NodeData.GetValue<string>(owner, i); Assert.Equal(dataFields[i], val); } else if (dataTypes[i] == typeof(int)) { var val = net.NodeData.GetValue<int>(owner, i); Assert.Equal(Convert.ToInt32(dataFields[i]), val); } else if (dataTypes[i] == typeof(float)) { var val = net.NodeData.GetValue<float>(owner, i); Assert.Equal(Convert.ToSingle(dataFields[i]), val); } else if (dataTypes[i] == typeof(double)) { var val = net.NodeData.GetValue<double>(owner, i); Assert.Equal(Convert.ToDouble(dataFields[i]), val); } else { Assert.True(false); //force a fail } } }
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 ReadNodeDataFields_Maps_First_Field_As_Key_To_Node(int index, string[] dataFields, string[] dataFieldNames, Type[] dataTypes, int[] srcFieldIndices) { // simulate initialized network var net = Blob.TestSupport.Network.BasicAdjListGenerator.GenerateAdjListWithDataAttribs(3, 0, false, true, false); var builder = new Blob.TestSupport.Network.DataAttributesBuilder(); builder.AddColumns((INodeAttributes)net, dataTypes, dataFieldNames, false); var reader = new VnaAdjListReader(); reader.State = VnaFileSection.NodeData; // simulate the list of HeaderField objects that have already been created in 1st pass for (int i = 0; i < dataFields.Length; i++) reader.NodeDataHeaders.Add(new HeaderField(dataFieldNames[i], VnaFileSection.NodeData, srcFieldIndices[i], null) { AttribColumnIndex = srcFieldIndices[i] }); int targetNodeIndex = 1; reader.ReadNodeDataFields(dataFields, net, targetNodeIndex, reader.NodeDataHeaders); Assert.Equal(1, reader.NodeKeyToNodeIndexMap.Count); INode node = net.Nodes[targetNodeIndex]; Assert.True(reader.NodeKeyToNodeIndexMap.ContainsKey(dataFields[0])); Assert.Equal(node, reader.NodeKeyToNodeIndexMap[dataFields[0]]); }
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); }