コード例 #1
0
        private static void TestMatrixInitWithEmptyArray()
        {
            try
            {
                double[,] arr = { };
                MyMatrix matrix = new MyMatrix(arr);
            }
            catch (MyMatrixException ex)
            {
                Console.WriteLine("TestMatrixInitWithEmptyArray PASSED");
                return;
            }

            Console.WriteLine("TestMatrixInitWithEmptyArray FAILED");
        }
コード例 #2
0
        private static void TestMatrixCorrectInit()
        {
            try
            {
                double[,] arr = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
                MyMatrix matrix = new MyMatrix(arr);
            }
            catch (MyMatrixException ex)
            {
                Console.WriteLine("TestMatrixCorrectInit FAILED");
                return;
            }

            Console.WriteLine("TestMatrixCorrectInit PASSED");
        }
コード例 #3
0
        private static void TestMatrixInitWithCorrectString()
        {
            try
            {
                String   str    = "3\t4\t5\n3\t4\t5";
                MyMatrix matrix = new MyMatrix(str);
            }
            catch (MyMatrixException ex)
            {
                Console.WriteLine("TestMatrixInitWithCorrectString FAILED");
                return;
            }

            Console.WriteLine("TestMatrixInitWithCorrectString PASSED");
        }
コード例 #4
0
        private static void TestMatrixInitWithCorrectStringArray()
        {
            try
            {
                String[] arr    = new[] { "1\t2\t3\t4,12\t-20", "5\t6\t7\t8,0\t3" };
                MyMatrix matrix = new MyMatrix(arr);
            }
            catch (MyMatrixException ex)
            {
                Console.WriteLine("TestMatrixInitWithCorrectStringArray FAILED");
                return;
            }

            Console.WriteLine("TestMatrixInitWithCorrectStringArray PASSED");
        }
コード例 #5
0
        private static void TestMatrixInitWithCorrectJuggedArray()
        {
            try
            {
                double[][] arr = new double[2][];
                arr[0] = new[] { 1.2, 2, 34 };
                arr[1] = new[] { 1.2, 2, 2 };
                MyMatrix matrix = new MyMatrix(arr);
            }
            catch (MyMatrixException ex)
            {
                Console.WriteLine("TestMatrixInitWithCorrectJuggedArray FAILED");
                return;
            }

            Console.WriteLine("TestMatrixInitWithCorrectJuggedArray PASSED");
        }
コード例 #6
0
        private static void TestTransposeMe()
        {
            MyMatrix actual = new MyMatrix(new double[, ] {
                { 1, 2 }, { 3, 4 }
            }).TransposeMe();
            MyMatrix expected = new MyMatrix(new double[, ] {
                { 1, 3 }, { 2, 4 }
            });

            if (actual.ToString().Equals(expected.ToString()))
            {
                Console.WriteLine("TestTransposeMe PASSED");
            }
            else
            {
                Console.WriteLine("TestTransposeMe FAILED");
            }
        }
コード例 #7
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");
            }
        }
コード例 #8
0
        private static void TestMultiplyMatrix()
        {
            MyMatrix matrix1 = new MyMatrix(new double[, ] {
                { 4, 2 }, { 4, 5 }
            });
            MyMatrix matrix2 = new MyMatrix(new double[, ] {
                { 1, 3, 5 }, { 2, 7, 10 }
            });
            MyMatrix matrix3 = matrix1 * matrix2;
            MyMatrix result  = new MyMatrix(new double[, ] {
                { 8, 26, 40 }, { 14, 47, 70 }
            });

            if (matrix3.ToString().Equals(result.ToString()))
            {
                Console.WriteLine("TestMultiplyMatrix PASSED");
            }
            else
            {
                Console.WriteLine("TestMultiplyMatrix FAILED");
            }
        }
コード例 #9
0
 private static void TestMatrixInitWithAnotherMatrixToStringMethod()
 {
     try
     {
         MyMatrix matrix = new MyMatrix(new double[, ] {
             { 4, 2, 3 }, { 4, 5, 6 }
         });
         MyMatrix newMatrix = new MyMatrix(matrix.ToString());
         if (newMatrix.ToString().Equals(matrix.ToString()))
         {
             Console.WriteLine("TestMatrixInitWithAnotherMatrixToStringMethod PASSED");
         }
         else
         {
             Console.WriteLine("TestMatrixInitWithAnotherMatrixToStringMethod FAILED");
         }
     }
     catch (MyMatrixException ex)
     {
         Console.WriteLine("TestMatrixInitWithAnotherMatrixToStringMethod FAILED");
     }
 }
コード例 #10
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");
            }
        }
コード例 #11
0
 public MyMatrix(MyMatrix matrix)
 {
     elements = (double[, ])matrix.elements.Clone();
     width    = matrix.width;
     height   = matrix.height;
 }