示例#1
0
        public void Convert_WithNodeDataAttributes_WhenIncludeNodeDataIsFalse(int numNodes, int numEdges, bool isDirected, int[] intVals, double[] doubleVals, bool[] boolVals, string[] stringVals)
        {
            INetworkAdjList src = NetGenerator.GenerateAdjList(numNodes, numEdges, isDirected);

            AdjListNodeDataBuilder dataBuilder = new AdjListNodeDataBuilder();
            dataBuilder.SetIntValues(src, 0, intVals);
            dataBuilder.SetDoubleValues(src, 1, doubleVals);
            dataBuilder.SetBoolValues(src, 2, boolVals);
            dataBuilder.SetStringValues(src, 3, stringVals);

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

            IAttributeListMgr mgr = ((INodeAttributes)net).NodeAttributeMgr;
            Assert.AreEqual(0, mgr.Count, "mgr.Count should match");
        }
示例#2
0
        public void Convert_WithNodeDataAttributes(int testId, int numNodes, int numEdges, bool isDirected, bool selfLoops, bool multiEdges, int[] intVals, double[] doubleVals, bool[] boolVals, string[] stringVals)
        {
            INetworkAdjList src = NetGenerator.GenerateAdjList(numNodes, numEdges, isDirected, selfLoops, true, multiEdges);

            AdjListNodeDataBuilder dataBuilder = new AdjListNodeDataBuilder();
            dataBuilder.SetIntValues(src, 0, intVals);
            dataBuilder.SetDoubleValues(src, 1, doubleVals);
            dataBuilder.SetBoolValues(src, 2, boolVals);
            dataBuilder.SetStringValues(src, 3, stringVals);

            ISimpleAdjList net = (ISimpleAdjList)_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<int>(net.Edges.Count, 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)net).NodeAttributeMgr;

            Assert.IsNotNull(mgr, "mgr should not be null");
            Assert.AreEqual(4, mgr.Count, "mgr.Count should match expected");
            Assert.AreEqual(numNodes, mgr.Capacity, "mgr.Capacity should match expected");

            //--
            IAttributeList list = mgr[0];
            Assert.IsNotNull(list, "list should not be null");
            Assert.AreEqual(typeof(int), list.DataType, "list.DataType should match expected");
            string intColName = list.Name;

            //--
            list = mgr[1];
            Assert.IsNotNull(list, "list should not be null");
            Assert.AreEqual(typeof(double), list.DataType, "list.DataType should match expected");
            string doubleColName = list.Name;

            //--
            list = mgr[2];
            Assert.IsNotNull(list, "list should not be null");
            Assert.AreEqual(typeof(bool), list.DataType, "list.DataType should match expected");
            string boolColName = list.Name;

            //--
            list = mgr[3];
            Assert.IsNotNull(list, "list should not be null");
            Assert.AreEqual(typeof(string), list.DataType, "list.DataType should match expected");
            string stringColName = list.Name;

            object objVal = null;

            //-- ints
            list = mgr[0];
            int intVal = -1;
            for (int i = 0; i < list.Count; i++)
            {
                objVal = list[i];
                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
            list = mgr[1];
            double doubleVal = -1.1;
            for (int i = 0; i < list.Count; i++)
            {
                objVal = list[i];
                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
            list = mgr[2];
            bool boolVal = false;
            for (int i = 0; i < list.Count; i++)
            {
                objVal = list[i];
                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
            list = mgr[3];
            string stringVal = null;
            for (int i = 0; i < list.Count; i++)
            {
                objVal = list[i];
                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");
            }
        }