Ejemplo n.º 1
0
        private static void TestMatrixInitWithAnotherMatrix()
        {
            double[,] arr = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
            MyMatrix matrix    = new MyMatrix(arr);
            MyMatrix newMatrix = new MyMatrix(matrix);

            matrix[1, 1] = 13;

            Console.WriteLine(newMatrix);


            if (matrix.GetHeight() == newMatrix.GetHeight() && matrix.GetWidth() == newMatrix.GetWidth())
            {
                Console.WriteLine("TestMatrixInitWithAnotherMatrix PASSED");
            }
            else
            {
                Console.WriteLine("TestMatrixInitWithAnotherMatrix FAILED");
            }
        }
Ejemplo n.º 2
0
        private static void TestAddMatrix()
        {
            MyMatrix matrix1 = new MyMatrix(new double[, ] {
                { 4, 2, 3 }, { 4, 5, 6 }
            });
            MyMatrix matrix2 = new MyMatrix(new double[, ] {
                { 1, 3, 5 }, { 2, 7, 10 }
            });
            MyMatrix matrix3  = matrix1 + matrix2;
            bool     isFailed = false;

            for (int i = 0; i < matrix1.GetHeight(); i++)
            {
                if (isFailed)
                {
                    break;
                }

                for (int j = 0; j < matrix1.GetWidth(); j++)
                {
                    if (!IsTwoDoubleEqual(matrix3[i, j], matrix1[i, j] + matrix2[i, j]))
                    {
                        isFailed = true;
                        break;
                    }
                }
            }

            if (isFailed)
            {
                Console.WriteLine("TestAddSameMatrix FAILED");
            }
            else
            {
                Console.WriteLine("TestAddSameMatrix PASSED");
            }
        }