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 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");
            }
        }
        public void Convert_WithNodeDataAttributes_WhenIncludeNodeDataIsFalse(int numNodes, int numEdges, bool isDirected, int[] intVals, double[] doubleVals, bool[] boolVals, string[] stringVals)
        {
            ISimpleAdjList src = SimpleAdjListGenerator.GenerateAdjList(numNodes, numEdges, isDirected);
            SimpleAdjListAttributeListDataBuilder builder = new SimpleAdjListAttributeListDataBuilder(AttributeListType.Edge);
            builder.AddList<int>(src, intVals);
            builder.AddList<double>(src, doubleVals);
            builder.AddList<bool>(src, boolVals);
            builder.AddList<string>(src, stringVals);

            _Converter.IncludeNodeData = false;
            INetworkAdjList net = (INetworkAdjList)_Converter.Convert(src);

            Assert.AreEqual(0, net.NodeMapCount, "net.NodeMapCount should match expected");
        }
        public void Convert_WithNodeDataAttributes(int numNodes, int numEdges, bool isDirected, int[] intVals, double[] doubleVals, bool[] boolVals, string[] stringVals)
        {
            ISimpleAdjList src = SimpleAdjListGenerator.GenerateAdjList(numNodes, numEdges, isDirected);
            SimpleAdjListAttributeListDataBuilder builder = new SimpleAdjListAttributeListDataBuilder(AttributeListType.Node);
            builder.AddList<int>(src, intVals, "list0");
            builder.AddList<double>(src, doubleVals, "list1");
            builder.AddList<bool>(src, boolVals, "list2");
            builder.AddList<string>(src, stringVals, "list3");

            _Converter.IncludeNodeData = true;
            INetworkAdjList net = (INetworkAdjList)_Converter.Convert(src);

            Assert.IsNotNull(net, "net should not be null");
            Assert.AreEqual<int>(net.NodeCount, src.NodeCount, "Nodecount should match");
            Assert.AreEqual<int>(net.Nodes.Count, src.NodeCount, "Nodecount should match");
            Assert.AreEqual<int>(net.EdgeCount, src.EdgeCount, "Nodecount should match");
            Assert.AreEqual<bool>(net.IsDirected, src.IsDirected, "IsDirected should match");
            Assert.AreEqual<string>(net.Name, src.Name, "Name should match");
            Assert.AreNotEqual<Guid>(net.Id, src.Id, "Id should not match");

            IAttributeListMgr mgr = ((INodeAttributes)src).NodeAttributeMgr;
            Assert.AreEqual(mgr.Count, net.NodeMapCount, "NodeMapCount should match");

            INodeMap[] maps = net.NodeMaps;
            Assert.IsNotNull(maps, "targetMaps is not null");

            for (int i = 0; i < maps.Length; i++)
            {
                Assert.AreEqual(mgr[i].DataType, LayerDataTypeConverter.ToType(maps[i].DataType), "DataType should match");
                Assert.AreEqual(mgr[i].Name, maps[i].Name, "Name should match");
            }

            object objVal = null;

            int ctr = 0;
            //-- ints
            INodeIntMap map0 = maps[0] as INodeIntMap;
            int intVal = -1;
            foreach (INode node in net.NodeEnumerator)
            {
                objVal = map0[node];
                Assert.IsNotNull(objVal, "objVal should not be null");
                Assert.IsInstanceOfType(typeof(int), objVal, "objVal should match expected type");
                intVal = (int)objVal;
                Assert.AreEqual(intVals[ctr++], intVal, "val should match expected");
            }

            //-- doubles
            ctr = 0;
            INodeDoubleMap map1 = maps[1] as INodeDoubleMap;
            double doubleVal = -1.1;
            foreach (INode node in net.NodeEnumerator)
            {
                objVal = map1[node];
                Assert.IsNotNull(objVal, "objVal should not be null");
                Assert.IsInstanceOfType(typeof(double), objVal, "objVal should match expected type");
                doubleVal = (double)objVal;
                Assert.AreEqual(doubleVals[ctr++], doubleVal, "val should match expected");
            }

            //-- bools
            ctr = 0;
            INodeBoolMap map2 = maps[2] as INodeBoolMap;
            bool boolVal = false;
            foreach (INode node in net.NodeEnumerator)
            {
                objVal = map2[node];
                Assert.IsNotNull(objVal, "objVal should not be null");
                Assert.IsInstanceOfType(typeof(bool), objVal, "objVal should match expected type");
                boolVal = (bool)objVal;
                Assert.AreEqual(boolVals[ctr++], boolVal, "val should match expected");
            }

            //-- strings
            ctr = 0;
            INodeStringMap map3 = maps[3] as INodeStringMap;
            string stringVal = null;
            foreach (INode node in net.NodeEnumerator)
            {
                objVal = map3[node];
                Assert.IsNotNull(objVal, "objVal should not be null");
                Assert.IsInstanceOfType(typeof(string), objVal, "objVal should match expected type");
                stringVal = (string)objVal;
                Assert.AreEqual(stringVals[ctr++], stringVal, "val should match expected");
            }
        }
예제 #6
0
        public void RemoveNode_WhenNodeDataMapIsPresent(int testId, int[] indicesToRemove, Type dataType, object defaultVal, int nodeCount, int edgeCount, bool directed, bool selfLoops, bool multiEdges)
        {
            ISimpleAdjList net = SimpleAdjListGenerator.GenerateAdjList(nodeCount, edgeCount, directed, selfLoops, multiEdges);
            SimpleAdjListAttributeListDataBuilder builder = new SimpleAdjListAttributeListDataBuilder(AttributeListType.Node);
            builder.AddList(net, dataType);

            SimpleAdjListEditor editor = new SimpleAdjListEditor();

            int removed = editor.RemoveNode(net, indicesToRemove[0]);

            Assert.IsNotNull(net, "Outputnet should not be null");

            int check = net.NodeCount + removed;
            Assert.AreEqual(nodeCount, check, "Check of removed should match expected");
            Assert.AreEqual(nodeCount - removed, net.NodeCount, "new node count should match expected");

            // re-verify new indices
            INode node = null;
            for (int i = 0; i < net.NodeCount; i++)
            {
                node = net.Nodes[i];
                Assert.IsNotNull(node, "New node indexed should not be null");
            }
        }