public void Equal_After_Change_Matrixes_Test()
 {
     Matrix a = new Matrix(2, 2, 10);
     Matrix b = new Matrix(2, 2, 10);
     Assert.IsTrue(a.Equals(b));
     b[2, 2] = 5;
     Assert.IsFalse(a.Equals(b));
     b[2, 2] = 10;
     Assert.IsTrue(a.Equals(b));
 }
예제 #2
0
 public void AreEqual()
 {
     float[] values = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
     var matrix1 = new Matrix(values);
     var matrix2 = new Matrix(values);
     Assert.IsTrue(matrix1 == matrix2);
     Assert.IsTrue(matrix1.Equals(matrix2));
     matrix2[5] = 20;
     Assert.IsTrue(matrix1 != matrix2);
     Assert.IsTrue(matrix1.Equals(values));
     values[0] = 17;
     Assert.IsFalse(matrix1.Equals(values));
     Assert.IsFalse(matrix1.Equals(Point.One));
     Assert.Throws<IndexOutOfRangeException>(() => matrix1.Equals(new float[17]));
 }
 public void EqualsTest()
 {
     Matrix a = new Matrix(2, 2, 10);
     Matrix b = new Matrix(2, 2, 10);
     Matrix c = new Matrix(2, 2, 10);
     Matrix x = new Matrix(2, 2, 5);
     // Testing Equals
     Assert.IsTrue(a.Equals(b));
     Assert.IsFalse(a.Equals(x));
     // x.Equals(x) returns true
     Assert.IsTrue(a.Equals(a));
     // x.Equals(y) returns the same value as y.Equals(x)
     Assert.AreEqual(a.Equals(b), b.Equals(a)); //both true
     Assert.AreEqual(a.Equals(x), x.Equals(a)); // both false
     // if (x.Equals(y) && y.Equals(z)) returns true, then x.Equals(z) returns true.
     Assert.IsTrue(a.Equals(b) && b.Equals(c) && a.Equals(c));
 }
예제 #4
0
        public void Matrix_EqualsTestsCorrectly()
        {
            var matrix1 = new Matrix(
                11, 12, 13, 14, 
                21, 22, 23, 24, 
                31, 32, 33, 34,
                41, 42, 43, 44);
            
            var matrix2 = new Matrix(
                11, 12, 13, 14, 
                21, 22, 23, 24, 
                31, 32, 33, 34, 
                41, 42, 43, 44);
            
            var matrix3 = Matrix.Identity;

            TheResultingValue(matrix1.Equals(matrix2)).ShouldBe(true);
            TheResultingValue(matrix1.Equals(matrix3)).ShouldBe(false);
        }
예제 #5
0
      public void TestInvert()
      {
         Matrix<Single> m = new Matrix<Single>(3, 3);
         Matrix<Single> mInvert = new Matrix<Single>(3, 3);

         m.SetIdentity();

         CvInvoke.Invert(m, mInvert, Emgu.CV.CvEnum.DecompMethod.LU);

         EmguAssert.IsTrue(m.Equals(mInvert));
      }
예제 #6
0
        public void TestConcate()
        {
            Matrix<float> mat = new Matrix<float>(30, 40);
             mat.SetRandUniform(new MCvScalar(0), new MCvScalar(255));

             Matrix<float> m1 = mat.GetSubRect(new Rectangle(0, 0, mat.Cols, 20));
             Matrix<float> m2 = mat.GetSubRect(new Rectangle(0, 20, mat.Cols, mat.Rows - 20));
             Matrix<float> mat2 = m1.ConcateVertical(m2);
             Assert.IsTrue(mat.Equals(mat2));

             Matrix<float> m3 = mat.GetSubRect(new Rectangle(0, 0, 10, mat.Rows));
             Matrix<float> m4 = mat.GetSubRect(new Rectangle(10, 0, mat.Cols - 10, mat.Rows));
             Matrix<float> mat3 = m3.ConcateHorizontal(m4);
             Assert.IsTrue(mat.Equals(mat3));

             Matrix<float> m5 = mat.GetRows(0, 5, 1);
             Matrix<float> m6 = mat.GetRows(5, 6, 1);
             Matrix<float> m7 = mat.GetRows(6, mat.Rows, 1);
             Assert.IsTrue(mat.RemoveRows(5, 6).Equals(m5.ConcateVertical(m7)));
             Assert.IsTrue(mat.RemoveRows(0, 1).Equals(mat.GetRows(1, mat.Rows, 1)));
             Assert.IsTrue(mat.RemoveRows(mat.Rows - 1, mat.Rows).Equals(mat.GetRows(0, mat.Rows - 1, 1)));
        }
예제 #7
0
        public void Simple()
        {
            var matrixA = new Matrix(5, 5);

            //      // [ 2,  1,  1,  3,  2 ]
            //      // [ 1,  2,  2,  1,  1 ]
            //      // [ 1,  2,  9,  1,  5 ]
            //      // [ 3,  1,  1,  7,  1 ]
            //      // [ 2,  1,  5,  1,  8 ]

            matrixA[0, 0] = 2;
            matrixA[0, 1] = 1;
            matrixA[0, 2] = 1;
            matrixA[0, 3] = 3;
            matrixA[0, 4] = 2;

            matrixA[1, 0] = 1;
            matrixA[1, 1] = 2;
            matrixA[1, 2] = 2;
            matrixA[1, 3] = 1;
            matrixA[1, 4] = 1;

            matrixA[2, 0] = 1;
            matrixA[2, 1] = 2;
            matrixA[2, 2] = 9;
            matrixA[2, 3] = 1;
            matrixA[2, 4] = 5;

            matrixA[3, 0] = 3;
            matrixA[3, 1] = 1;
            matrixA[3, 2] = 1;
            matrixA[3, 3] = 7;
            matrixA[3, 4] = 1;

            matrixA[4, 0] = 2;
            matrixA[4, 1] = 1;
            matrixA[4, 2] = 5;
            matrixA[4, 3] = 1;
            matrixA[4, 4] = 8;

            var decomposition = new CholeskyDecomposition(matrixA);

            var AA = decomposition.LeftFactorMatrix * decomposition.RightFactorMatrix;

            Assert.AreEqual(AA.Rows, 5);
            Assert.AreEqual(AA.Columns, 5);

            Assert.IsTrue(matrixA.Equals(AA, DoubleExtensions.DefaultPrecision));
        }
예제 #8
0
 public void EqualsTest()
 {
     double[,] data = null; // TODO: инициализация подходящего значения
     Matrix target = new Matrix(data); // TODO: инициализация подходящего значения
     object obj = null; // TODO: инициализация подходящего значения
     bool expected = false; // TODO: инициализация подходящего значения
     bool actual;
     actual = target.Equals(obj);
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Проверьте правильность этого метода теста.");
 }
예제 #9
0
      public void TestXmlSerializeAndDeserialize()
      {
         using (Matrix<Byte> mat = new Matrix<byte>(50, 60))
         {
            mat.SetRandUniform(new MCvScalar(0), new MCvScalar(255));

#if !WINDOWS_PHONE_APP
            XDocument doc = Toolbox.XmlSerialize<Matrix<Byte>>(mat);
            //Trace.WriteLine(doc.OuterXml);

            using (Matrix<Byte> mat2 = Toolbox.XmlDeserialize<Matrix<Byte>>(doc))
               EmguAssert.IsTrue(mat.Equals(mat2));
#endif
         }
      }
        public void MatrixCreate()
        {
            double[][] a = { new double[] { 1, 2 }, new double[] { 2, 3 } };
            Matrix ma = new Matrix(a);
            double[][] b = { new double[] { 1.0, 2.0 }, new double[] { 2.0, 3.0 } };
            Matrix mb = Matrix.Create(b);

            Assert.That(ma, Is.EqualTo(mb));
            Assert.That(ma.Equals(mb), Is.True);
            Assert.That(ma.AlmostEquals(mb), Is.True);
        }
예제 #11
0
        public void transformWorld(Matrix rotationX, Matrix rotationY, Matrix rotationZ, Matrix scaleXYZ, 
            Matrix translateXYZ)
        {
            Matrices.worldTransMtx = Matrix.Identity;

            if (!rotationZ.Equals(Matrix.Zero)) Matrices.worldTransMtx = Matrix.Multiply(Matrices.worldTransMtx, rotationZ);
            if (!rotationY.Equals(Matrix.Zero)) Matrices.worldTransMtx = Matrix.Multiply(Matrices.worldTransMtx, rotationY);
            if (!rotationX.Equals(Matrix.Zero)) Matrices.worldTransMtx = Matrix.Multiply(Matrices.worldTransMtx, rotationX);
            if (!scaleXYZ.Equals(Matrix.Zero)) Matrices.worldTransMtx = Matrix.Multiply(Matrices.worldTransMtx, scaleXYZ);
            if (!translateXYZ.Equals(Matrix.Zero)) Matrices.worldTransMtx = Matrix.Multiply(Matrices.worldTransMtx, translateXYZ);
        }
예제 #12
0
      public void TestMultiChannelMatrix()
      {
         Matrix<float> m = new Matrix<float>(10, 20, 2);
         m.SetRandUniform(new MCvScalar(), new MCvScalar(255, 255));
         EmguAssert.AreEqual(10, m.Rows);
         EmguAssert.AreEqual(20, m.Cols);
         EmguAssert.AreEqual(2, m.NumberOfChannels);

#if !WINDOWS_PHONE_APP
         XDocument xDoc = Toolbox.XmlSerialize<Matrix<float>>(m);
         Matrix<float> m2 = Toolbox.XmlDeserialize<Matrix<float>>(xDoc);
         EmguAssert.IsTrue(m.Equals(m2));
#endif
      }
 public void Equal_Parameter_Null_Test()
 {
     Matrix a = new Matrix(2, 2, 1);
     Assert.IsFalse(a.Equals(null));
     Matrix b = null;
     Assert.IsFalse(a.Equals(b));
     Assert.IsFalse(a == b);
 }
예제 #14
0
        public void EqualsAndHashCode()
        {
            Matrix matrix1 = new Matrix(new double[][] { new double[] { 1.0, 2.0 }, new double[] { 3.0, 4.0 } });
            Matrix matrix2 = new Matrix(new double[][] { new double[] { 1.0, 2.0 }, new double[] { 3.0, 4.0 } });
            Matrix matrix3 = new Matrix(new double[][] { new double[] { 1.0, 2.0 }, new double[] { 3.0, 5.0 } });
            Matrix matrix4 = new Matrix(new double[][] { new double[] { 1.0, 2.0, 3.0 }, new double[] { 3.0, 4.0, 5.0 } });
            Matrix matrix5 = new Matrix(new double[][] { new double[] { 1.0, 2.0 }, new double[] { 3.0, 4.0 }, new double[] { 5.0, 6.0 } });

            Assert.IsTrue(matrix1.Equals(matrix2));
            Assert.IsTrue(matrix2.Equals(matrix1));

            Assert.AreEqual(matrix2.GetHashCode(), matrix1.GetHashCode());

            Assert.IsFalse(matrix1.Equals(matrix3));
            Assert.IsFalse(matrix1.Equals(matrix4));
            Assert.IsFalse(matrix1.Equals(matrix5));
            Assert.IsFalse(matrix3.Equals(matrix1));
            Assert.IsFalse(matrix4.Equals(matrix1));
            Assert.IsFalse(matrix5.Equals(matrix1));

            Assert.IsFalse(matrix1.Equals(null));
            Assert.IsFalse(matrix1.Equals(42));
            Assert.IsFalse(matrix1.Equals("foo"));
        }
예제 #15
0
      public void TestRuntimeSerialize3()
      {
         MCvPoint3D32f[] data = new MCvPoint3D32f[] { new MCvPoint3D32f() };

         GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);

         Matrix<float> mat = new Matrix<float>(data.GetLength(0), 1, 3, handle.AddrOfPinnedObject(), sizeof(float) * 3);

         System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
             formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

         Byte[] bytes;
         using (MemoryStream ms = new MemoryStream())
         {
            formatter.Serialize(ms, mat);
            bytes = ms.GetBuffer();
         }
         using (MemoryStream ms2 = new MemoryStream(bytes))
         {
            Matrix<float> mat2 = (Matrix<float>) formatter.Deserialize(ms2);
            EmguAssert.IsTrue(mat.Equals(mat2));
         }
         handle.Free();
      }
예제 #16
0
        public void op_Equals_object_whenTrue()
        {
            var matrix = new Matrix<decimal>(1, 1);
            matrix[0, 0] = decimal.One;

            var comparand = new Matrix<decimal>(1, 1);
            comparand[0, 0] = decimal.One;

            Assert.True(matrix.Equals(comparand as object));
        }
예제 #17
0
      public void TestVectorOfMat()
      {
         Matrix<double> m1 = new Matrix<double>(3, 3);
         m1.SetRandNormal(new MCvScalar(0.0), new MCvScalar(1.0));
         Matrix<int> m2 = new Matrix<int>(4, 4);
         m2.SetRandNormal(new MCvScalar(2), new MCvScalar(2));

         VectorOfMat vec = new VectorOfMat(m1.Mat, m2.Mat);

         Mat tmp1 = vec[0];
         Mat tmp2 = vec[1];
         Matrix<double> n1 = new Matrix<double>(tmp1.Size);
         Matrix<int> n2 = new Matrix<int>(tmp2.Size);
         tmp1.CopyTo(n1, null);
         tmp2.CopyTo(n2, null);

         EmguAssert.IsTrue(m1.Equals(n1));
         EmguAssert.IsTrue(m2.Equals(n2));
      }
예제 #18
0
        public void op_Equals_object_whenDifferentType()
        {
            var matrix = new Matrix<decimal>();

            var comparand = new Matrix<int>();

            Assert.False(matrix.Equals(comparand));
        }
예제 #19
0
        public void op_Equals_objectSame()
        {
            var matrix = new Matrix<decimal>();

            // ReSharper disable EqualExpressionComparison
            Assert.True(matrix.Equals(matrix as object));

            // ReSharper restore EqualExpressionComparison
        }
예제 #20
0
        public void op_Equals_MatrixOfT_whenFalse()
        {
            var matrix = new Matrix<decimal>(1, 1);
            matrix[0, 0] = decimal.One;

            var comparand = new Matrix<decimal>(1, 1);
            comparand[0, 0] = decimal.MinusOne;

            Assert.False(matrix.Equals(comparand));
        }
예제 #21
0
      public void TestRuntimeSerialize1()
      {
         Matrix<Byte> mat = new Matrix<Byte>(100, 80, 2);
         mat.SetRandNormal(new MCvScalar(100, 100, 100), new MCvScalar(50, 50, 50));

         System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
             formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

         Byte[] bytes;
         using (MemoryStream ms = new MemoryStream())
         {
            formatter.Serialize(ms, mat);
            bytes = ms.GetBuffer();
         }
         using (MemoryStream ms2 = new MemoryStream(bytes))
         {
            Matrix<Byte> mat2 = (Matrix<Byte>) formatter.Deserialize(ms2);
            EmguAssert.IsTrue(mat.Equals(mat2));
         }
      }
예제 #22
0
        public void Equals_against_null()
        {
            var matrix = new Matrix();

            Assert.IsFalse(matrix.Equals(null));
        }
예제 #23
0
      public void TestRuntimeSerialize2()
      {
         Random r = new Random();
         double[,,] data = new double[100, 80, 2];
         for (int i = 0; i < data.GetLength(0); i++)
            for (int j = 0; j < data.GetLength(1); j++)
               for (int k = 0; k < data.GetLength(2); k++)
                  data[i, j, k] = r.NextDouble();

         GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);

         Matrix<Double> mat = new Matrix<Double>(data.GetLength(0), data.GetLength(1), data.GetLength(2), handle.AddrOfPinnedObject(), sizeof(double) * data.GetLength(1) * data.GetLength(2));

         System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
             formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

         Byte[] bytes;
         using (MemoryStream ms = new MemoryStream())
         {
            formatter.Serialize(ms, mat);
            bytes = ms.GetBuffer();
         }
         using (MemoryStream ms2 = new MemoryStream(bytes))
         {
            Matrix<Double> mat2 = (Matrix<double>) formatter.Deserialize(ms2);
            EmguAssert.IsTrue(mat.Equals(mat2));
         }
         handle.Free();
      }
예제 #24
0
        public void TestInvert()
        {
            Matrix<Single> m = new Matrix<Single>(3, 3);
             Matrix<Single> mInvert = new Matrix<Single>(3, 3);

             m.SetIdentity();

             CvInvoke.cvInvert(m, mInvert, Emgu.CV.CvEnum.INVERT_METHOD.CV_LU);

             Assert.IsTrue(m.Equals(mInvert));
        }
예제 #25
0
        public void Equals_for_two_matrices()
        {
            var matrix1 = new Matrix(
                11, 12, 13, 14,
                21, 22, 23, 24,
                31, 32, 33, 34,
                41, 42, 43, 44);

            var matrix2 = new Matrix(
                11, 12, 13, 14,
                21, 22, 23, 24,
                31, 32, 33, 34,
                41, 42, 43, 44);

            Assert.IsTrue(matrix1.Equals(matrix2));
        }
예제 #26
0
        public void TestXmlSerializeAndDeserialize()
        {
            using (Matrix<Byte> mat = new Matrix<byte>(50, 60))
             {
            mat.SetRandUniform((ulong)DateTime.Now.Ticks, new MCvScalar(0), new MCvScalar(255));
            XmlDocument doc = Toolbox.XmlSerialize<Matrix<Byte>>(mat);
            //Trace.WriteLine(doc.OuterXml);

            using (Matrix<Byte> mat2 = Toolbox.XmlDeserialize<Matrix<Byte>>(doc))
               Assert.IsTrue(mat.Equals(mat2));

             }
        }
예제 #27
0
        public void Transpose_TranslatedValueAsExpected()
        {
            var m = new Matrix(new[] {
                new [] { 1d, 2, 3},
                new [] { 4d, 5, 6}
            });

            var mc = new Matrix(new[] {
                new [] { 1d, 4},
                new [] { 2d, 5},
                new [] { 3d, 6}
            });

            var m2 = m.Transpose();

            Assert.That(mc.Equals(m2));
        }
 public void Equal_Different_Size_Matrixes_Test()
 {
     Matrix a = new Matrix(2, 2, 1);
     Matrix b = new Matrix(3, 3, 1);
     Assert.IsFalse(a.Equals(b));
     Assert.IsFalse(a == b);
     Assert.IsTrue(a != b);
 }
예제 #29
0
		public static void IEquatableEquals (int times)
		{
			var value1 = new Matrix (
				0f, 0f, 0f, 0f,
				0f, 0f, 0f, 0f,
				0f, 0f, 0f, 0f,
				0f, 0f, 0f, 1f
			);
			var value2 = new Matrix (
				0f, 0f, 0f, 0f,
				0f, 0f, 0f, 0f,
				0f, 0f, 0f, 0f,
				0f, 0f, 0f, -1f
			);
			bool result;
			
			for (int i = 0; i < times; i++) {
				result = value1.Equals (value2);
			}
		}
예제 #30
0
        public void Equals_against_different_type()
        {
            var matrix = new Matrix();

            Assert.IsFalse(matrix.Equals("some other type"));
        }