コード例 #1
0
ファイル: MatrixService.cs プロジェクト: aleffnull/Checker
        private void CheckMultiplicationResult(string inputFilePath, string outputFilePath, Logger logger)
        {
            logger("Checking multiplication result");

            Matrix firstMatrix = new Matrix();
            Matrix secondMatrix = new Matrix();

            logger(string.Format("Loading input matrices from '{0}'.", inputFilePath));
            MatrixAlgorithmsService.LoadMatrices(inputFilePath, firstMatrix, secondMatrix);
            if (!firstMatrix.IsValid)
            {
                logger("First matrix is invalid!");
                return;
            }
            if (!secondMatrix.IsValid)
            {
                logger("Second matrix is invalid");
                return;
            }

            logger(string.Format("Loading calculated matrix from '{0}'.", outputFilePath));
            Matrix calculatedMatrix = MatrixAlgorithmsService.LoadMatrix(outputFilePath);
            if (!calculatedMatrix.IsValid)
            {
                logger("Calculated matrix is invalid");
                return;
            }

            logger("Calculating master result");
            Matrix masterMatrix = MatrixAlgorithmsService.SimpleMultiplication(firstMatrix, secondMatrix);

            logger("Checking dimensions");
            if (masterMatrix.RowCount != calculatedMatrix.RowCount || masterMatrix.ColumnCount != calculatedMatrix.ColumnCount)
            {
                logger("Dimensions of calculated and master matrix are different");
                return;
            }

            logger("Checking elements equality");
            bool equal = masterMatrix.IsEqualTo(calculatedMatrix);
            logger(equal ? "OK: matrices are equal" : "Failed: matrices are NOT equal");
        }
コード例 #2
0
ファイル: Matrix.cs プロジェクト: aleffnull/Checker
        public bool IsEqualTo(Matrix matrix)
        {
            if (RowCount != matrix.RowCount || ColumnCount != matrix.ColumnCount)
            {
                return false;
            }

            for (int rowIndex = 0; rowIndex < RowCount; rowIndex++)
            {
                for (int columnIndex = 0; columnIndex < ColumnCount; columnIndex++)
                {
                    int element = this[rowIndex, columnIndex];
                    int matrixElement = matrix[rowIndex, columnIndex];
                    if (element != matrixElement)
                    {
                        return false;
                    }
                }
            }

            return true;
        }