Exemplo n.º 1
0
        public void ConvertToFrame_From_Directed_Matrix_Random_Tests(int nodeCount, int edgeCount, bool directed, bool selfLoops)
        {
            Console.WriteLine(
                string.Format("nodes: {0}, edges:{1}, directed:{2}, self-loops:{3}",
                     nodeCount, edgeCount, directed, selfLoops));
            //Arrange
            BasicMatrixGenerator.AllowSelfLoops = selfLoops;
            IMatrix<double> net = BasicMatrixGenerator.GenerateMatrix(Guid.NewGuid(), nodeCount, edgeCount, directed);

            var converter = new MatrixToFrameConverter();

            //Act
            IFrame frame = converter.ConvertToFrame(net) as IFrame;

            //Assert
            Assert.NotNull(frame);
            Assert.Equal(net.NodeCount, frame.RowCount);
            Assert.Equal(net.NodeCount, frame.ColumnCount);

            double initVal = 0.0;
            double copiedVal = 0.0;
            for (int i = 0; i < frame.RowCount; i++)
            {
                for (int j = 0; j < frame.ColumnCount; j++)
                {
                    initVal = net[i, j];
                    copiedVal = (double)frame[i,j];
                    Assert.Equal(initVal, copiedVal);
                    j++;
                }
            }
        }
Exemplo n.º 2
0
        public void ConvertToFrame_From_Directed_Matrix(int testId, bool directed, double[] row0, double[] row1, double[] row2)
        {
            //Arrange
            int nodeCount = row0.Length;
            BasicMatrixGenerator.AllowSelfLoops = true;
            IMatrix<double> net = BasicMatrixGenerator.GenerateMatrix(Guid.NewGuid(), nodeCount, 0, directed);

            for (int i = 0; i < nodeCount; i++)
            {
                if (i == 0)
                    for (int j = 0; j < nodeCount; j++)
                        net[i, j] = row0[j];
                else if (i == 1)
                    for (int j = 0; j < nodeCount; j++)
                        net[i, j] = row1[j];
                else
                    for (int j = 0; j < nodeCount; j++)
                        net[i, j] = row2[j];
            }

            var converter = new MatrixToFrameConverter();

            //Act
            IFrame frame = converter.ConvertToFrame(net) as IFrame;

            //Assert
            Assert.NotNull(frame);
            Assert.Equal(net.NodeCount, frame.RowCount);
            Assert.Equal(net.NodeCount, frame.ColumnCount);

            double initVal = 0.0;
            double copiedVal = 0.0;

            for (int i = 0; i < frame.RowCount; i++)
            {
                for (int j = 0; j < frame.ColumnCount; j++ )
                {
                    initVal = net[i, j];
                    copiedVal = (double)frame[i,j];
                    Assert.Equal(initVal, copiedVal);
                    j++;
                }
            }
        }