public void SymmetricMatrixTestIndexator1()
        {
            DynSymmetricMatrix matrix = new DynSymmetricMatrix(5, 0);

            matrix[1, 1] = 2;

            Assert.True(matrix[1, 1] == 2);
        }
        public void SymmetricMatrixTestIndexator()
        {
            DynSymmetricMatrix matrix = new DynSymmetricMatrix(5, 9);

            matrix[3, 4] = 10;

            Assert.True(matrix[4, 3] == matrix[3, 4]);
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Parameters"></param>
        /// <param name="Dim"></param>
        /// <param name="DimObjs"></param>
        /// <exception cref="ArgumentException">If <paramref name="Parameters"/> is not initialized.</exception>
        protected virtual void Init(FWParams Parameters, int Dim, int DimObjs)
        {
            if (!Parameters.IsParamsInit)
            {
                throw new ArgumentException("The parameters were created by the default constructor and have invalid values. You need to create parameters with a custom constructor.", nameof(Parameters));
            }

            _parameters = Parameters;

            _minDebrisCount = _parameters.Smin;
            _maxDebrisCount = _parameters.Smax;

            if (_coordNumbers == null)
            {
                _coordNumbers = new int[Dim];
            }
            else if (_coordNumbers.Length != Dim)
            {
                _coordNumbers = new int[Dim];
            }

            if (_chargePoints == null)
            {
                _chargePoints = new List <Agent>(_parameters.NP);
            }
            else
            {
                _chargePoints.Clear();
                _chargePoints.Capacity = _parameters.NP;
            }

            if (_debris == null)
            {
                InitDebris();
            }
            else if (_debris.Length != this.Parameters.NP)
            {
                InitDebris();
            }

            int newSizeMatrix = checked (_parameters.NP - 1 + _parameters.NP * _minDebrisCount);

            _weightedAgents = new List <WeightOfAgent>(newSizeMatrix);

            _pool = new AgentPool(_parameters.NP * _maxDebrisCount / 2, new AgenCreator(Dim, DimObjs));

            if (_matrixOfDistances == null)
            {
                _matrixOfDistances = new DynSymmetricMatrix(newSizeMatrix);
            }
        }
        public void SymmetricMatrixTestConstr1()
        {
            DynSymmetricMatrix matrix = new DynSymmetricMatrix(3, 5);

            bool error = false;

            for (int i = 0; i < matrix.RowCount; i++)
            {
                for (int j = 0; j < matrix.ColumnCount; j++)
                {
                    if (matrix[i, j] != 5)
                    {
                        error = true;
                    }
                }
            }

            Assert.False(error);
        }
        public void SymmetrixMatrixDynResizeTest(int NewSize)
        {
            double[,] values =
            {
                { 1, 2, 3 },
                { 2, 5, 6 },
                { 3, 6, 9 }
            };

            DynSymmetricMatrix matrix = new DynSymmetricMatrix(values);

            bool isError = false;

            matrix.ColumnCount = NewSize;

            int rowCount    = Math.Min(matrix.RowCount, values.GetLength(0));
            int columnCount = rowCount;

            for (int i = 0; i < rowCount; i++)
            {
                for (int j = 0; j < columnCount; j++)
                {
                    if (matrix[i, j] != values[i, j])
                    {
                        isError = true;
                    }
                }
            }

            if (matrix.RowCount > rowCount)
            {
                for (int i = 0; i < matrix.RowCount; i++)
                {
                    if (matrix[matrix.RowCount - 1, i] != 0.0)
                    {
                        isError = true;
                    }
                }
            }

            Assert.False(isError || matrix.ColumnCount != NewSize);
        }
        public void SymmetricMatrixTestConstr2()
        {
            double[,] array = { { 1, 2, 4 }, { 2, 7, 8 }, { 4, 8, 9 } };

            DynSymmetricMatrix matrix = new DynSymmetricMatrix(array);

            bool error = false;

            for (int i = 0; i < matrix.RowCount; i++)
            {
                for (int j = 0; j < matrix.ColumnCount; j++)
                {
                    if (array[i, j] != matrix[i, j])
                    {
                        error = true;
                    }
                }
            }

            Assert.False(error);
        }
        public void SymmetricMatrixTestToArray()
        {
            double[,] array = { { 1, 2 }, { 2, 8 } };

            DynSymmetricMatrix martix = new DynSymmetricMatrix(array);

            double[,] arrayRes = martix.ToArray();

            bool error = false;

            for (int i = 0; i < array.GetLength(0); i++)
            {
                for (int j = 0; j < array.GetLength(1); j++)
                {
                    if (array[i, j] != arrayRes[i, j])
                    {
                        error = true;
                    }
                }
            }

            Assert.False(error);
        }
        public void SymmetrixMatrixDynResizeWrongNewSizeTest(int NewSize)
        {
            DynSymmetricMatrix matrix = new DynSymmetricMatrix(2, 0.0);

            Assert.Throws <ArgumentException>(() => matrix.ColumnCount = NewSize);
        }
        public void SymmetricMatrixTestConstr()
        {
            DynSymmetricMatrix matrix = new DynSymmetricMatrix(4);

            Assert.True(matrix.RowCount == matrix.ColumnCount && matrix.RowCount == 4);
        }