equals() public method

Compare the matrix to another with the specified level of precision.
public equals ( Matrix matrix, int precision ) : bool
matrix Matrix The other matrix to compare.
precision int The number of decimal places of precision to use.
return bool
Beispiel #1
0
        public void MatrixEqualsPrecision()
        {
            double[][] m1 =
            {
                new[] { 1.1234, 2.123 },
                new[] {  3.123, 4.123 }
            };

            double[][] m2 =
            {
                new[] { 1.123, 2.123 },
                new[] { 3.123, 4.123 }
            };

            var matrix1 = new Matrix(m1);
            var matrix2 = new Matrix(m2);

            Assert.IsTrue(matrix1.equals(matrix2, 3));
            Assert.IsFalse(matrix1.equals(matrix2, 4));

            double[][] m3 =
            {
                new[] { 1.1, 2.1 },
                new[] { 3.1, 4.1 }
            };

            double[][] m4 =
            {
                new[] { 1.2, 2.1 },
                new[] { 3.1, 4.1 }
            };

            var matrix3 = new Matrix(m3);
            var matrix4 = new Matrix(m4);

            Assert.IsTrue(matrix3.equals(matrix4, 0));
            Assert.IsFalse(matrix3.equals(matrix4, 1));

            try
            {
                matrix3.equals(matrix4, -1);
                Assert.IsTrue(false);
            }
            catch (MatrixError)
            {
            }

            try
            {
                matrix3.equals(matrix4, 19);
                Assert.IsTrue(false);
            }
            catch (MatrixError)
            {
            }
        }
        public void MatrixEqualsPrecision()
        {
            double[][] m1 = {
                                new[] {1.1234, 2.123},
                                new[] {3.123, 4.123}
                            };

            double[][] m2 = {
                                new[] {1.123, 2.123},
                                new[] {3.123, 4.123}
                            };

            var matrix1 = new Matrix(m1);
            var matrix2 = new Matrix(m2);

            Assert.IsTrue(matrix1.equals(matrix2, 3));
            Assert.IsFalse(matrix1.equals(matrix2, 4));

            double[][] m3 = {
                                new[] {1.1, 2.1},
                                new[] {3.1, 4.1}
                            };

            double[][] m4 = {
                                new[] {1.2, 2.1},
                                new[] {3.1, 4.1}
                            };

            var matrix3 = new Matrix(m3);
            var matrix4 = new Matrix(m4);
            Assert.IsTrue(matrix3.equals(matrix4, 0));
            Assert.IsFalse(matrix3.equals(matrix4, 1));

            try
            {
                matrix3.equals(matrix4, -1);
                Assert.IsTrue(false);
            }
            catch (MatrixError)
            {
            }

            try
            {
                matrix3.equals(matrix4, 19);
                Assert.IsTrue(false);
            }
            catch (MatrixError)
            {
            }
        }