public void ToDataTable_MatchesNodeIndexToRowIndex(int testId, int numNodes, int numEdges, bool isDirected, bool selfLoops, bool multiEdges, int[] dataVals, int targetIndex)
        {
            // *** targetIndex is the node index for which the row value of the column will be set to -7
            // so the row index of the resulting table should match the node index

            ISimpleAdjList net = SimpleAdjListGenerator.GenerateAdjList(numNodes, numEdges, isDirected);
            SimpleAdjListAttributeListDataBuilder builder = new SimpleAdjListAttributeListDataBuilder(AttributeListType.Node);
            builder.AddList<int>(net, dataVals);

            SimpleAdjListNodeAttributeExtractor xtor = new SimpleAdjListNodeAttributeExtractor();

            DataTable table = xtor.ToDataTable(net);
            Assert.IsNotNull(table, "table should not be null");

            Assert.AreEqual(1, table.Columns.Count, "Columns.Count should match expected");
            Assert.AreEqual(numNodes, table.Rows.Count, "table.Rows.Count should match expected");

            DataColumn col = table.Columns[0];
            Assert.IsNotNull(col, "col should not be null");
            Assert.AreEqual(typeof(int), col.DataType, "Columns.DataType should match expected");

            // get the value of the table at row[targetIndex]
            int result = (int)table.Rows[targetIndex][0];

            Assert.AreEqual(-7, result, "The val should match expected");
        }
        public void ToDataTable_ThrowsIfNetworkIsNull()
        {
            ISimpleAdjList net = null;

            SimpleAdjListNodeAttributeExtractor xtor = new SimpleAdjListNodeAttributeExtractor();

            DataTable table = xtor.ToDataTable(net);
        }
        public void ToDataTable_ThrowsIfNetworkIsIncorrectType()
        {
            INetwork net = new BlueSpider.Blob.TestSupport.Network.Dummies.DummySimpleAdjList();

            SimpleAdjListNodeAttributeExtractor xtor = new SimpleAdjListNodeAttributeExtractor();

            DataTable table = xtor.ToDataTable(net);
        }
 public void ToDataTable_ThrowsIfNodeAttribMgrIsNull()
 {
     SimpleAdjList net = SimpleAdjListGenerator.GenerateAdjList(0, 0, true) as SimpleAdjList;
     net.NodeAttributeMgr = null;
     SimpleAdjListNodeAttributeExtractor xtor = new SimpleAdjListNodeAttributeExtractor();
     DataTable table = xtor.ToDataTable(net);
 }
        public void ToFrame_WithZeroLists(int numNodes, int numEdges, bool isDirected)
        {
            ISimpleAdjList net = SimpleAdjListGenerator.GenerateAdjList(numNodes, numEdges, isDirected);

            SimpleAdjListNodeAttributeExtractor xtor = new SimpleAdjListNodeAttributeExtractor();

            SimpleFrame table = xtor.ToFrame(net) as SimpleFrame;
            Assert.IsNotNull(table, "table should not be null");

            Assert.AreEqual(0, table.Columns.Count, "Columns.Count should match expected");
            Assert.AreEqual(0, table.Rows.Count, "table.Rows.Count should match expected");
        }
        public void ToFrame_WithOneList(int testId, int numNodes, int numEdges, bool isDirected, int[] dataVals)
        {
            ISimpleAdjList net = SimpleAdjListGenerator.GenerateAdjList(numNodes, numEdges, isDirected);
            SimpleAdjListAttributeListDataBuilder builder = new SimpleAdjListAttributeListDataBuilder(AttributeListType.Node);
            builder.AddList<int>(net, dataVals);

            SimpleAdjListNodeAttributeExtractor xtor = new SimpleAdjListNodeAttributeExtractor();

            SimpleFrame table = xtor.ToFrame(net) as SimpleFrame;
            Assert.IsNotNull(table, "table should not be null");

            Assert.AreEqual(1, table.Columns.Count, "Columns.Count should match expected");
            Assert.AreEqual(numNodes, table.Rows.Count, "table.Rows.Count should match expected");

            DataColumn col = table.Columns[0];
            Assert.IsNotNull(col, "col should not be null");
            Assert.AreEqual(typeof(int), col.DataType, "Columns.DataType should match expected");

            string colName = col.ColumnName;

            object objVal = null;
            int val = -1;
            for (int i = 0; i < table.Rows.Count; i++)
            {
                objVal = table.Rows[i][colName];
                Assert.IsNotNull(objVal, "objVal should not be null");
                Assert.IsInstanceOfType(typeof(int), objVal, "objVal should match expected type");
                val = (int)objVal;
                Assert.AreEqual(dataVals[i], val, "val should match expected");
            }
        }
        public void ToFrame_WithMultipleListsWithIdenticalNames(int testId, int numNodes, int numEdges, bool isDirected, int[] intVals, double[] doubleVals, bool[] boolVals, string[] stringVals)
        {
            ISimpleAdjList net = SimpleAdjListGenerator.GenerateAdjList(numNodes, numEdges, isDirected);
            SimpleAdjListAttributeListDataBuilder builder = new SimpleAdjListAttributeListDataBuilder(AttributeListType.Node);
            builder.AddList<int>(net, intVals, "list");
            builder.AddList<double>(net, doubleVals, "list");
            builder.AddList<bool>(net, boolVals, "list");
            builder.AddList<string>(net, stringVals, "list");

            SimpleAdjListNodeAttributeExtractor xtor = new SimpleAdjListNodeAttributeExtractor();

            SimpleFrame table = xtor.ToFrame(net) as SimpleFrame;
            Assert.IsNotNull(table, "table should not be null");

            Assert.AreEqual(4, table.Columns.Count, "Columns.Count should match expected");
            Assert.AreEqual(numNodes, table.Rows.Count, "table.Rows.Count should match expected");

            //--
            DataColumn intCol = table.Columns[0];
            Assert.IsNotNull(intCol, "col should not be null");
            Assert.AreEqual(typeof(int), intCol.DataType, "Columns.DataType should match expected");
            string intColName = intCol.ColumnName;

            //--
            DataColumn doubleCol = table.Columns[1];
            Assert.IsNotNull(doubleCol, "col should not be null");
            Assert.AreEqual(typeof(double), doubleCol.DataType, "Columns.DataType should match expected");
            string doubleColName = doubleCol.ColumnName;

            //--
            DataColumn boolCol = table.Columns[2];
            Assert.IsNotNull(boolCol, "col should not be null");
            Assert.AreEqual(typeof(bool), boolCol.DataType, "Columns.DataType should match expected");
            string boolColName = boolCol.ColumnName;

            //--
            DataColumn stringCol = table.Columns[3];
            Assert.IsNotNull(stringCol, "col should not be null");
            Assert.AreEqual(typeof(string), stringCol.DataType, "Columns.DataType should match expected");
            string stringColName = stringCol.ColumnName;

            object objVal = null;

            //-- ints
            int intVal = -1;
            for (int i = 0; i < table.Rows.Count; i++)
            {
                objVal = table.Rows[i][intColName];
                Assert.IsNotNull(objVal, "objVal should not be null");
                Assert.IsInstanceOfType(typeof(int), objVal, "objVal should match expected type");
                intVal = (int)objVal;
                Assert.AreEqual(intVals[i], intVal, "val should match expected");
            }

            //-- doubles
            double doubleVal = -1.1;
            for (int i = 0; i < table.Rows.Count; i++)
            {
                objVal = table.Rows[i][doubleColName];
                Assert.IsNotNull(objVal, "objVal should not be null");
                Assert.IsInstanceOfType(typeof(double), objVal, "objVal should match expected type");
                doubleVal = (double)objVal;
                Assert.AreEqual(doubleVals[i], doubleVal, "val should match expected");
            }

            //-- bools
            bool boolVal = false;
            for (int i = 0; i < table.Rows.Count; i++)
            {
                objVal = table.Rows[i][boolColName];
                Assert.IsNotNull(objVal, "objVal should not be null");
                Assert.IsInstanceOfType(typeof(bool), objVal, "objVal should match expected type");
                boolVal = (bool)objVal;
                Assert.AreEqual(boolVals[i], boolVal, "val should match expected");
            }

            //-- strings
            string stringVal = null;
            for (int i = 0; i < table.Rows.Count; i++)
            {
                objVal = table.Rows[i][stringColName];
                Assert.IsNotNull(objVal, "objVal should not be null");
                Assert.IsInstanceOfType(typeof(string), objVal, "objVal should match expected type");
                stringVal = (string)objVal;
                Assert.AreEqual(stringVals[i], stringVal, "val should match expected");
            }
        }
예제 #8
0
 internal INodeDataExtractor _CreateNodeDataExtractor(INetwork network)
 {
     INodeDataExtractor tool = null;
     if (network != null)
     {
         if (network is BlueSpider.Blob.Regular.Network.AdjList.SimpleAdjList)
         {
             tool = new SimpleAdjListNodeAttributeExtractor();
         }
     }
     return tool;
 }