public void AddingEdges_Adds_Row_With_Matching_Key_In_EdgeData(int nodeCount, int edgeCount)
        {
            Random rand = new Random();
            var net = new BasicAdjList(Guid.NewGuid());
            var table = new DataAttributeTable<IEdge>();
            table.Network = net;
            net.EdgeData = table;

            for (int i = 0; i < nodeCount; i++)
            {
                var node = net.CreateNode();
            }

            INode nodeA = null;
            INode nodeB = null;
            IEdge edge = null;
            for (int i = 0; i < edgeCount; i++)
            {
                nodeA = net.Nodes[rand.Next(nodeCount)];
                nodeB = net.Nodes[rand.Next(nodeCount)];
                edge = net.CreateEdge(nodeA, nodeB);
                Assert.Equal((i + 1), net.EdgeCount);
                Assert.Equal((i + 1), table.RowCount);
                Assert.True(table.RowOwnerMap.ContainsKey(edge));
            }
        }
        public void AddColumn_Adds_New_Column_When_Cols_And_Rows_Do_Exist(string colName, Type colType, string[] colNames, Type[] colTypes)
        {
            //Arrange
            int rowCount = 2;
            var mockNet = new Moq.Mock<INetwork>();
            var table = new DataAttributeTable<IEdge>();
            table.Network = mockNet.Object;
            for (int i = 0; i < colNames.Length; i++)
                table.Columns.Add(colNames[i], colTypes[i]);

            DataRow row = table.NewRow();
            table.Rows.Add(row);
            row = table.NewRow();
            table.Rows.Add(row);

            Assert.Equal(table.Columns.Count, colNames.Length);

            int index = colNames.Length;

            //Act
            table.AddColumn(colName, colType);

            //Assert
            Assert.Equal(table.Columns.Count, colNames.Length + 1);
            Assert.Equal(table.Columns[index].ColumnName, colName);
            Assert.Equal(table.Columns[index].DataType, colType);
            Assert.Equal(table.Rows.Count, rowCount);
        }
        public void CreateEdgeDataTable_Assigns_Table_To_Network_As_EdgeData()
        {
            var net = BasicAdjListGenerator.GenerateAdjList(0, 0, false) as BasicAdjList;
            var fac = new DataAttributeTableFactory();

            _table = fac.CreateEdgeDataTable(net);
            Assert.AreSame(net.EdgeData, _table, "Table and EdgeData ref should match");
        }
 public void AddColumn_Does_Not_Throw_Ex_If_Name_Is_Null(string colName, Type colType)
 {
     // gives it a default name
     var mockNet = new Mock<INetwork>();
     _table = new DataAttributeTable(mockNet.Object);
     _table.AddColumn(colName, colType);
     Assert.AreEqual(_table.Columns.Count, 1, "Col count should match expected");
     Assert.AreEqual(_table.Columns[0].DataType, colType, "Col type should match expected");
 }
        public void AddColumn_Adds_New_Column_When_No_Cols_Exist(string colName, Type colType)
        {
            var mockNet = new Mock<INetwork>();
            _table = new DataAttributeTable(mockNet.Object);
            Assert.AreEqual(_table.Columns.Count, 0, "Col Count should be 0");

            _table.AddColumn(colName, colType);
            Assert.AreEqual(_table.Columns.Count, 1, "Col count should match expected");
            Assert.AreEqual(_table.Columns[0].ColumnName, colName, "Col names should match expected");
            Assert.AreEqual(_table.Columns[0].DataType, colType, "Col type should match expected");
        }
 public void CreateEdgeDataTable_Creates_EdgeData_With_Primary_Key_Of_Edge_Index(int nodeCount, int edgeCount)
 {
     IBasicAdjList net = BasicAdjListGenerator.GenerateAdjList(nodeCount, edgeCount, false);
     var fac = new DataAttributeTableFactory();
     _table = fac.CreateEdgeDataTable(net);
     Assert.IsNotNull(_table, "Table should not be null");
     Assert.IsNotNull(_table.Network, "Network is not null");
     Assert.AreSame(_table.Network, net, "Network ref should match expected");
     Assert.AreEqual(_table.Columns.Count, 1, "column count should match expected");
     Assert.AreEqual(_table.Columns["Index"].DataType, typeof(int), "Datatype of keys col should match expected");
     Assert.AreEqual(_table.Rows.Count, edgeCount, "Rowcount should match expected");
 }
예제 #7
0
        /// <summary>
        /// Creates and attatches to <see cref="ParentNetwork"/>  a DataAttributeTable
        /// for storing edge data attributes.
        /// </summary>
        /// <returns>DataAttributeTable</returns>
        public DataAttributeTable<IEdge> CreateEdgeDataTable()
        {
            if (this.ParentNetwork == null)
                throw new ArgumentNullException("ParentNetwork", "parent ParentNetwork must not be null");
            var table = new DataAttributeTable<IEdge> { Network = ParentNetwork, AutoAcceptChanges = false };

            LoadRowsAndMap(table);

            table.AcceptChanges();
            table.AutoAcceptChanges = true;
            HookEdgeDataToNetwork(ParentNetwork, table);
            return table;
        }
        public void AddingNodes_Adds_Row_With_Matching_Key_In_NodeData(int nodeCount)
        {
            var net = new BasicAdjList(Guid.NewGuid());
            var table = new DataAttributeTable<INode>();
            table.Network = net;
            net.NodeData = table;

            for(int i=0; i<nodeCount; i++)
            {
                var node = net.CreateNode();
                Assert.Equal((i+1), net.NodeCount);
                Assert.Equal((i+1), table.RowCount);
                Assert.True(table.RowOwnerMap.ContainsKey(node));
            }
        }
        public void AddColumn_Adds_New_Column_When_Cols_Do_Exist(string colName, Type colType, string[] colNames, Type[] colTypes)
        {
            var mockNet = new Mock<INetwork>();
            _table = new DataAttributeTable(mockNet.Object);
            for (int i = 0; i < colNames.Length; i++)
                _table.Columns.Add(colNames[i], colTypes[i]);

            Assert.AreEqual(_table.Columns.Count, colNames.Length, "Col Count should match expected");

            int index = colNames.Length;
            _table.AddColumn(colName, colType);
            Assert.AreEqual(_table.Columns.Count, colNames.Length+1, "Col count should match expected");
            Assert.AreEqual(_table.Columns[index].ColumnName, colName, "Col names should match expected");
            Assert.AreEqual(_table.Columns[index].DataType, colType, "Col type should match expected");
        }
        public void AddColumn_Adds_New_Column_When_No_Cols_Exist(string colName, Type colType)
        {
            //Arrange
            var mockNet = new Moq.Mock<INetwork>();
            var table = new DataAttributeTable<INode>();
            table.Network = mockNet.Object;

            //Act
            table.AddColumn(colName, colType);

            //Assert
            Assert.Equal(table.Columns.Count, 1);
            Assert.Equal(table.Columns[0].ColumnName, colName);
            Assert.Equal(table.Columns[0].DataType, colType);
        }
        /// <summary>
        /// Creates and attatches to <paramref name="network"/> a DataAttributeTable
        /// for storing edge data attributes.
        /// </summary>
        /// <param name="network">The parent network.</param>
        /// <returns>DataAttributeTable</returns>
        public DataAttributeTable CreateEdgeDataTable(IAdjList network)
        {
            if (network == null)
                throw new ArgumentNullException("network", "network must not be null");
            var table = new DataAttributeTable(network);
            table.AutoAcceptChanges = false;
            var primaryKeyCol = table.Columns.Add("Index", typeof(int));
            table.PrimaryKey = new DataColumn[] { primaryKeyCol };

            foreach (IEdge edge in network.Edges)
            {
                table.Rows.Add(new object[] { edge.Index });
            }
            table.AcceptChanges();
            table.AutoAcceptChanges = true;
            HookEdgeDataToNetwork(network, table);
            return table;
        }
        public void CreateEdgeDataTable_Creates_EdgeData_With_Primary_Key_Of_Edge_Index(int nodeCount, int edgeCount, string[] colNames, Type[] colTypes)
        {
            IBasicAdjList net = BasicAdjListGenerator.GenerateAdjList(nodeCount, edgeCount, false);
            var fac = new DataAttributeTableFactory();
            _table = fac.CreateEdgeDataTable(net, colNames, colTypes);
            Assert.IsNotNull(_table, "Table should not be null");
            Assert.IsNotNull(_table.Network, "Network is not null");
            Assert.AreSame(_table.Network, net, "Network ref should match expected");
            Assert.AreEqual(_table.Columns.Count, colNames.Length+1, "column count should match expected");
            Assert.AreEqual(_table.Columns["Index"].DataType, typeof(int), "Datatype of keys col should match expected");
            Assert.AreEqual(_table.Rows.Count, edgeCount, "Rowcount should match expected");

            DataColumn col = null;
            for (int i = 1; i < _table.Columns.Count; i++)
            {
                col = _table.Columns[i];
                Assert.AreEqual(col.ColumnName, colNames[i - 1], string.Format("Col name {0} should match expected", i));
                Assert.AreEqual(col.DataType, colTypes[i - 1], string.Format("Col type {0} should match expected", i));
            }
        }
        public void ItemGetter_Returns_Cell_Val_By_RowIndex_And_ColIndex()
        {
            //Arrange
            var net = new BasicAdjList(Guid.NewGuid());

            var table = new DataAttributeTable<IEdge>();
            table.Network = net;

            table.Columns.Add(new DataColumn("X", typeof(string)));

            var nodeA = net.CreateNode();
            var nodeB = net.CreateNode();
            var nodeC = net.CreateNode();

            var edgeA = net.CreateEdge(nodeB, nodeC);
            var edgeB = net.CreateEdge(nodeA, nodeC);

            table.AddRow(edgeA);
            table.AddRow(edgeB);

            table.SetValue<string>(edgeA, 0, "valA");
            table.SetValue<string>(edgeB, 0, "valB");

            //Act
            string val0 = (string)table[0, 0];
            string val1 = (string)table[1, 0];
            // verify primary keys

            //Assert
            Assert.Equal(val0, "valA");
            Assert.Equal(val1, "valB");
        }
        public void AddRow_Appends_New_Row_And_Updates_Map()
        {
            //Arrange
            var net = new BasicAdjList(Guid.NewGuid());
            var table = new DataAttributeTable<IEdge>();
            table.Network = net;

            var nodeA = net.CreateNode();
            var nodeB = net.CreateNode();
            var edge = net.CreateEdge(nodeA, nodeB);

            //Act
            table.AddRow(edge);

            //Assert
            Assert.Equal(table.Rows.Count, 1);

            Assert.Equal(table.RowOwnerMap.Count, 1);
            Assert.True(table.RowOwnerMap.ContainsKey(edge));
        }
        public void ClearColumn_Sets_Row_Vals_To_Defaults(string[] colNames, Type[] colTypes, object[] defaultVals)
        {
            //Arrange
            var mockNet = new Moq.Mock<INetwork>();
            var table = new DataAttributeTable<IEdge>();
            table.Network = mockNet.Object;
            for (int i = 0; i < colNames.Length; i++)
                table.Columns.Add(colNames[i], colTypes[i]).DefaultValue = defaultVals[i];
            Assert.Equal(table.Columns.Count, colNames.Length);

            table.Rows.Add(new object[] { "ABC", -33.1 });
            table.Rows.Add(new object[] { "efg", -44.2 });

            //Act
            table.ClearColumn("b");

            //Assert
            Assert.Equal(table.Rows[0][1], table.Columns["b"].DefaultValue);
            Assert.Equal(table.Rows[1][1], table.Columns["b"].DefaultValue);
        }
 public void CreateNodeDataTable_With_4_Params_Throws_Ex_If_Any_Param_Array_Is_Null_But_Not_DefaultVals_Array(string[] colNames, Type[] colTypes, object[] defaultVals)
 {
     var mockNet = new Mock<IAdjList>();
     var fac = new DataAttributeTableFactory();
     _table = fac.CreateNodeDataTable(mockNet.Object, colNames, colTypes, defaultVals);
 }
        public void AddColumn_With_Default_Val_Throws_Ex_When_Col_Name_Is_In_Use(string colName, Type colType, object defaultVal, string[] colNames, Type[] colTypes)
        {
            //Arrange
            var mockNet = new Moq.Mock<INetwork>();
            var table = new DataAttributeTable<IEdge>();
            table.Network = mockNet.Object;
            for (int i = 0; i < colNames.Length; i++)
                table.Columns.Add(colNames[i], colTypes[i]);

            //Act, Assert
            var ex = Assert.Throws<DuplicateNameException>(() => table.AddColumn(colName, colType, defaultVal));
        }
        public DataAttributeTable CreateEdgeDataTable(IAdjList network, string[] columnNames, Type[] columnTypes, object[] defaultValues)
        {
            if (network == null)
                throw new ArgumentNullException("network", "network must not be null");
            if (columnNames == null)
                throw new ArgumentNullException("columnNames", "columnNames array must not be null");
            if (columnTypes == null)
                throw new ArgumentNullException("columnTypes", "columnTypes array must not be null");
            if (columnNames.Length != columnTypes.Length)
                throw new ArgumentException(string.Format("columnNames has length = {0} while columnTypes has length = {1}, the lengths must match", columnNames.Length, columnTypes.Length));
            if (defaultValues != null && defaultValues.Length != columnNames.Length)
                throw new ArgumentException(string.Format("defaulValues has length = {0} while columnNames has length = {1}, the lengths must match", defaultValues.Length, columnNames.Length));

            var table = new DataAttributeTable(network);
            table.AutoAcceptChanges = false;
            var primaryKeyCol = table.Columns.Add("Index", typeof(int));
            table.PrimaryKey = new DataColumn[] { primaryKeyCol };

            DataColumn col = null;
            for (int i = 0; i < columnNames.Length; i++)
            {
                col = table.Columns.Add(columnNames[i], columnTypes[i]);
                if (defaultValues != null)
                    col.DefaultValue = defaultValues[i];
            }

            foreach (IEdge edge in network.Edges)
            {
                table.Rows.Add(new object[] { edge.Index });
            }
            table.AcceptChanges();
            table.AutoAcceptChanges = true;
            HookEdgeDataToNetwork(network, table);
            return table;
        }
        public void AddColumn_With_Default_Val_Adds_New_Column_When_Cols_Do_Exist(string colName, Type colType, object defaultVal, string[] colNames, Type[] colTypes)
        {
            //Arrange
            var mockNet = new Moq.Mock<INetwork>();
            var table = new DataAttributeTable<IEdge>();
            table.Network = mockNet.Object;
            for (int i = 0; i < colNames.Length; i++)
                table.Columns.Add(colNames[i], colTypes[i]);
            Assert.Equal(table.Columns.Count, colNames.Length);

            int index = colNames.Length;

            //Act
            table.AddColumn(colName, colType, defaultVal);

            //Assert
            Assert.Equal(table.Columns.Count, colNames.Length + 1);
            Assert.Equal(table.Columns[index].ColumnName, colName);
            Assert.Equal(table.Columns[index].DataType, colType);
            Assert.Equal(table.Columns[index].DefaultValue, defaultVal);
        }
 public void CreateNodeDataTable_With_4_Params_Throws_Ex_If_Lengths_Do_Not_Match(string[] colNames, Type[] colTypes, object[] defaultVals)
 {
     var mockNet = new Mock<IAdjList>();
     var fac = new DataAttributeTableFactory();
     _table = fac.CreateNodeDataTable(mockNet.Object, colNames, colTypes, defaultVals);
 }
        public void CreateNodeDataTable_With_4_Params_Throws_Ex_If_Network_Is_Null()
        {
            var fac = new DataAttributeTableFactory();

            _table = fac.CreateNodeDataTable(null, new string[] { "a" }, new Type[] { typeof(int) }, new object[] {-3});
        }
        public void SetValue_Of_T_Assigns_Object_To_Cell_Val_By_Owner_And_ColIndex()
        {
            //Arrange
            var net = new BasicAdjList(Guid.NewGuid());

            var table = new DataAttributeTable<IEdge>();
            table.Network = net;

            table.Columns.Add(new DataColumn("X", typeof (string)));

            var nodeA = net.CreateNode();
            var nodeB = net.CreateNode();
            var nodeC = net.CreateNode();

            var edgeA = net.CreateEdge(nodeB, nodeC);
            var edgeB = net.CreateEdge(nodeA, nodeC);

            table.AddRow(edgeA);
            table.AddRow(edgeB);

            //Act
            table.SetValue<string>(edgeA, 0, "valA");
            table.SetValue<string>(edgeB, 0, "valB");

            string val0 = (string)table.Rows[0][0];
            string val1 = (string)table.Rows[1][0];
            // verify primary keys

            //Assert
            Assert.Equal(val0, "valA");
            Assert.Equal(val1, "valB");
        }
        public void RemoveColumn_Removes_Col_In_Table_With_Rows_And_Vals(string colName)
        {
            //Arrange
            var mockNet = new Moq.Mock<INetwork>();
            var table = new DataAttributeTable<IEdge>();
            table.Network = mockNet.Object;
            table.Columns.Add("A", typeof(string));
            table.Columns.Add("B", typeof(int));

            table.Rows.Add(new object[] {"ABC", -33});
            table.Rows.Add(new object[] {"efg", -44});

            //Act
            table.RemoveColumn(colName);

            //Assert
            Assert.Equal(table.Columns.Count, 1);
        }
        public void RemoveColumnAt_Removes_Col_In_Table_With_Rows(int colIndex)
        {
            //Arrange
            var mockNet = new Moq.Mock<INetwork>();
            var table = new DataAttributeTable<IEdge>();
            table.Network = mockNet.Object;
            table.Columns.Add("A", typeof(int));
            table.Columns.Add("B", typeof(int));

            //Act
            table.RemoveColumnAt(colIndex);

            //Assert
            Assert.Equal(table.Columns.Count, 1);
        }
        public void RemoveColumn_Removes_Col_In_Table_With_Rows(string colName)
        {
            //Arrange
            var mockNet = new Moq.Mock<INetwork>();
            var table = new DataAttributeTable<IEdge>();
            table.Network = mockNet.Object;
            table.Columns.Add("A", typeof(int));
            table.Columns.Add("B", typeof(int));

            DataRow row = table.NewRow();
            table.Rows.Add(row);
            row = table.NewRow();
            table.Rows.Add(row);

            //Act
            table.RemoveColumn(colName);

            //Assert
            Assert.Equal(table.Columns.Count, 1);
        }
        public void CreateEdgeDataTable_Throws_Ex_If_Network_Is_Null()
        {
            var fac = new DataAttributeTableFactory();

            _table = fac.CreateEdgeDataTable(null);
        }
        public void RemoveRow_Deletes_Row_For_Specified_Node_And_Updates_Map()
        {
            //Arrange
            var net = new BasicAdjList(Guid.NewGuid());

            var nodeA = net.CreateNode();
            var nodeB = net.CreateNode();
            var nodeC = net.CreateNode();

            var edgeA = net.CreateEdge(nodeB, nodeC);
            var edgeB = net.CreateEdge(nodeA, nodeC);

            var table = new DataAttributeTable<IEdge>();
            table.Network = net;

            table.AddRow(edgeA);
            table.AddRow(edgeB);

            Assert.Equal(table.Rows.Count, 2);
            Assert.Equal(table.RowOwnerMap.Count, 2);

            //Act
            table.RemoveRow(edgeB);

            //Assert
            Assert.Equal(table.Rows.Count, 1);
            Assert.Equal(table.RowOwnerMap.Count, 1);

            Assert.False(table.RowOwnerMap.ContainsKey(edgeB));
        }
 internal void HookEdgeDataToNetwork(IAdjList network, DataAttributeTable edgeData)
 {
     if (network is BasicAdjList)
     {
         var net = network as BasicAdjList;
     //    net.EdgeData = edgeData;
     }
 }
        public void AddColumn_Does_Not_Throw_Ex_If_Name_Is_Null(string colName, Type colType)
        {
            //Arrange
            // gives it a default name
            var mockNet = new Moq.Mock<INetwork>();
            var table = new DataAttributeTable<IEdge>();

            //Act
            table.AddColumn(colName, colType);

            //Assert
            Assert.Equal(table.Columns.Count, 1);
            Assert.Equal(table.Columns[0].DataType, colType);
        }
 internal void HookNodeDataToNetwork(IAdjList network, DataAttributeTable nodeData)
 {
     if(network is BasicAdjList)
     {
         var net = network as BasicAdjList;
      //       net.NodeData = nodeData;
     }
 }