Example #1
0
        public void ReadNodeDataFields_Reads_Fields_Into_NodeAttribs_From_StarNodeData_Section(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;
            INode owner = net.Nodes[targetNodeIndex];
            reader.ReadNodeDataFields(dataFields, net, targetNodeIndex, reader.NodeDataHeaders);

            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
                }
            }
        }
Example #2
0
 public void ReadNodeDataFields_Throws_If_Not_In_Required_State(VnaFileSection state)
 {
     var reader = new VnaAdjListReader();
     reader.State = state;
     var ex = Assert.Throws<InvalidOperationException>(() => reader.ReadNodeDataFields(new string[] { "X" }, null, 0, null));
 }
Example #3
0
        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]]);
        }