本文整理汇总了C#中Matrix.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# Matrix.Equals方法的具体用法?C# Matrix.Equals怎么用?C# Matrix.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix
的用法示例。
在下文中一共展示了Matrix.Equals方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Equals
public void Equals()
{
var m = new Matrix (1, 2, 3, 4, 5, 6);
Assert.IsTrue (m.Equals (new Matrix (1, 2, 3, 4, 5, 6)));
Assert.IsFalse (m.Equals (new Matrix (0, 2, 3, 4, 5, 6)));
Assert.IsFalse (m.Equals (new Matrix (1, 0, 3, 4, 5, 6)));
Assert.IsFalse (m.Equals (new Matrix (1, 2, 0, 4, 5, 6)));
Assert.IsFalse (m.Equals (new Matrix (1, 2, 3, 0, 5, 6)));
Assert.IsFalse (m.Equals (new Matrix (1, 2, 3, 4, 0, 6)));
Assert.IsFalse (m.Equals (new Matrix (1, 2, 3, 4, 5, 0)));
Assert.IsFalse (m.Equals (0));
Assert.IsTrue (m.Equals ((object)m));
}
示例2: Equals_Test
public void Equals_Test()
{
Matrix a = new Matrix(new double[,] { { 1, 2 }, { 3, 4 } });
Matrix b = new Matrix(new double[,] { { 1, 2 }, { 3, 4 } });
Matrix c = new Matrix(new double[,] { { 1, 2 }, { 3, 4 } });
Assert.IsTrue(a.Equals(a));
Assert.IsTrue(a.Equals(b) == b.Equals(a));
Assert.IsTrue(a.Equals(b) && b.Equals(c));
Assert.IsFalse(a.Equals(null));
Assert.IsTrue(a.Equals(c));
c = new Matrix(new double[,] { { 0, 0 }, { 0, 0 } });
Assert.IsFalse(a.Equals(c));
}
示例3: TestMethodMatrix
public void TestMethodMatrix()
{
Matrix matrix1 = new Matrix(2, 3);
Assert.AreEqual(matrix1.Row, 2);
Assert.AreEqual(matrix1.Column, 3);
Matrix matrix2 = new Matrix(new double[,] { { 1, 2, 0 }, { 3, 4, 5 } });
Assert.AreEqual(matrix2.Row, 2);
Assert.AreEqual(matrix2.Column, 3);
matrix2.Resize(2, 2);
Matrix matrix3 = new Matrix(new double[,] { { 1, 2 }, { 3, 4 } });
Assert.AreEqual(matrix2.GetHashCode(), matrix3.GetHashCode());
Assert.IsTrue(matrix2.Equals(matrix3));
matrix3.AddRowToRow(0, 1, -1);
Assert.AreEqual(matrix3, new Matrix(new double[,] { { 1, 2 }, { 2, 2 } }));
matrix3.AddRowToRow(1, 0, 1);
Assert.AreEqual(matrix3, new Matrix(new double[,] { { 3, 4 }, { 2, 2 } }));
matrix3.MultiplyFactorToRow(1, 0.5);
Assert.AreEqual(matrix3, new Matrix(new double[,] { { 3, 4 }, { 1, 1 } }));
matrix3.AddNewRowToEnd(new Vector(new double[] { 5, 6 }));
Assert.AreEqual(matrix3[2, 0], 5);
Assert.AreEqual(matrix3[2, 1], 6);
Matrix matrix4 = matrix3.SubMatrix(1, 1, 2, 1);
Assert.AreEqual(matrix4, new Matrix(new double[,] { { 1 }, { 6 } }));
Assert.AreEqual(matrix3, new Matrix(new double[,] { { 3, 4 }, { 1, 1 }, { 5, 6 } }));
matrix3.DelRowFromEnd();
Assert.AreEqual(matrix3, new Matrix(new double[,] { { 3, 4 }, { 1, 1 } }));
Matrix matrix5 = new Matrix(new double[,] { { 1, 2 }, { 1, 2 } });
Assert.AreEqual(matrix3 + matrix5, new Matrix(new double[,] { { 4, 6 }, { 2, 3 } }));
Assert.AreEqual(matrix3 - matrix5, new Matrix(new double[,] { { 2, 2 }, { 0, -1 } }));
Assert.AreEqual(matrix3 * matrix5, new Matrix(new double[,] { { 7, 14 }, { 2, 4 } }));
Assert.AreEqual(matrix5 * matrix3, new Matrix(new double[,] { { 5, 6 }, { 5, 6 } }));
Assert.AreEqual(matrix3 * matrix4, new Matrix(new double[,] { { 27 }, { 7 } }));
}
示例4: GetHashCode_Equal_Test
public void GetHashCode_Equal_Test()
{
Matrix a = new Matrix(new double[,] { { 1, 2 }, { 3, 4 } });
Matrix b = new Matrix(new double[,] { { 1, 2 }, { 3, 4 } });
Assert.IsTrue(a.Equals(b));
Assert.AreEqual(a.GetHashCode(), b.GetHashCode());
}
示例5: GetHashCode_Not_Equal_Test
public void GetHashCode_Not_Equal_Test()
{
Matrix a = new Matrix(new double[,] { { 1, 2 }, { 3, 4 } });
Matrix b = new Matrix(new double[,] { { 10, 20 }, { 30, 40 } });
Assert.IsFalse(a.Equals(b));
Assert.AreNotEqual(a.GetHashCode(), b.GetHashCode());
}
示例6: CheckMatrix
static public void CheckMatrix (Matrix m, double m11, double m12, double m21, double m22, double ox, double oy, string message)
{
Assert.AreEqual (m11, m.M11, message + ".M11");
Assert.AreEqual (m12, m.M12, message + ".M12");
Assert.AreEqual (m21, m.M21, message + ".M21");
Assert.AreEqual (m22, m.M22, message + ".M22");
Assert.AreEqual (ox, m.OffsetX, message + ".OffsetX");
Assert.AreEqual (oy, m.OffsetY, message + ".OffsetY");
Assert.AreEqual (m.IsIdentity, m.Equals (Matrix.Identity), "Equals(Identity)");
}
示例7: Main
static void Main(string[] args)
{
//Creates Default_Matrix with given dimensions the matrix is empty
Matrix Default_Matrix = new Matrix(2, 2);
Console.WriteLine("Original Matrix:");
Console.WriteLine();
Default_Matrix.print();
Console.WriteLine();
double min; double max;
Point min_loc = new Point();
Point max_loc = new Point();
//Matrix to multiply,add,subtract, or test equals by.
double[,] Test_Matrix = { { 1, 2 }, { 1, 2 }};
Console.WriteLine("This is the Matrix after being multiplied by Test_Matrix:");
Console.WriteLine();
Default_Matrix.Mul(Test_Matrix);
Console.WriteLine();
Console.WriteLine("This is the Matrix after being multiplied by a scalar:");
Console.WriteLine();
Default_Matrix.scale(4);
Console.WriteLine();
Console.WriteLine("This is the Matrix that resulted from multiplying by the scalar and added to it is Test_Matrix:");
Console.WriteLine();
Default_Matrix.Add(Test_Matrix);
Console.WriteLine();
Console.WriteLine("This is the Matrix that resulted from multiplying by the scalar and then subtracting from it Test_Matrix:");
Console.WriteLine();
Default_Matrix.Sub(Test_Matrix);
Console.WriteLine();
Console.WriteLine("This is the Matrix transposed:");
Console.WriteLine();
Default_Matrix.Transpose();
Console.WriteLine();
Console.WriteLine("True or False: the matrices are equal?");
Console.WriteLine();
Default_Matrix.Equals(Test_Matrix);
Console.WriteLine();
Console.WriteLine("The current Matrix is reset to identity matrix:");
Console.WriteLine();
Default_Matrix.SetIdentity();
Console.WriteLine();
Default_Matrix.MinMax(out min, out max, out min_loc, out max_loc);
Console.WriteLine();
double j = Default_Matrix.Data;
Console.Write(j);
Default_Matrix.Data = 4;
Default_Matrix.print();
Console.Read();
}
示例8: MultiplyTest2
public void MultiplyTest2()
{
double[,] arrayA = {
{1,2},
{3,4}};
double[,] arrayB = {
{5,6},
{7,8}};
double[,] arrayExpected = {
{19,22},
{43,50}};
Matrix matrixA = new Matrix(arrayA);
Matrix matrixB = new Matrix(arrayB);
Matrix matrixExpected = new Matrix(arrayExpected);
matrixA.Scaler = 2;
matrixB.Scaler = 7;
matrixExpected.Scaler = 2 * 7;
Matrix matrixActual = matrixA.Multiply(matrixB);
Assert.IsTrue(matrixExpected.Equals(matrixActual));
}
示例9: InverseTest2
public void InverseTest2()
{
Matrix matrix = new Matrix(new double[,] {
{ 1, 3, 0 },
{ 0, -2, 1 },
{-1,0,0}});
Matrix expected = new Matrix(new double[,] {
{ 0, 0, -3 },
{ 1, 0, 1 },
{2,3,2}}, 1d / 3d);
Matrix inverse = matrix.Inverse();
Debug.WriteLine(inverse.ToString());
Assert.IsTrue(expected.Equals(inverse));
Matrix mult = matrix.Multiply(inverse);
Debug.WriteLine(mult.ToString());
}
示例10: EqualsTest2
public void EqualsTest2()
{
double[,] array1 = {
{1,2},
{3,4}};
double[,] array2 = {
{2,4},
{6,8}};
Matrix matrix1 = new Matrix(array1, 1);
Matrix matrix2 = new Matrix(array2, 1);
Matrix matrix3 = new Matrix(array1, 2);
Assert.IsFalse(matrix1.Equals(matrix2));
Assert.IsTrue(matrix2.Equals(matrix3));
}
示例11: EqualsTest
public void EqualsTest()
{
double[,] array1 = {
{1,2},
{3,4}};
double[,] sameArray1 = {
{1,2},
{3,4}};
double[,] array2 = {
{1,2},
{3,5}};
Matrix target = new Matrix(array1);
Matrix matrix2 = new Matrix(array1);
Matrix matrix3 = new Matrix(sameArray1);
Matrix matrix4 = new Matrix(array2);
Assert.IsTrue(target.Equals(target));
Assert.IsFalse(target.Equals(null));
Assert.IsFalse(target.Equals("Hello"));
Assert.IsTrue(target.Equals(matrix2));
Assert.IsTrue(target.Equals(matrix3));
Assert.IsFalse(target.Equals(matrix4));
}
示例12: Matrix_Equals_Test
public void Matrix_Equals_Test(Matrix<int> firstMatrix, Matrix<int> secondMatrix, bool result) {
Assert.AreEqual(firstMatrix.Equals(secondMatrix), result);
}
示例13: MatrixsSum_Test
public void MatrixsSum_Test(Matrix<int> firstMatrix, Matrix<int> secondMatrix, Matrix<int> resultMatrix ) {
SquareMatrix<int> result = firstMatrix.Add(secondMatrix);
Assert.AreEqual(resultMatrix.Equals(result), true);
}
示例14: Matrix_EqualsTest
public void Matrix_EqualsTest()
{
Matrix matrix1 = new Matrix(2, 2);
Matrix matrix2 = new Matrix(2, 2);
double[] matrix1Column1 = { 2, 3 };
double[] matrix1Column2 = { 4, 5 };
matrix1.SetColumn(0, matrix1Column1);
matrix1.SetColumn(1, matrix1Column2);
double[] matrix2Column1 = { 2, 3 };
double[] matrix2Column2 = { 4, 5 };
matrix2.SetColumn(0, matrix2Column1);
matrix2.SetColumn(1, matrix2Column2);
bool result = matrix1.Equals(matrix2);
result.Should().BeTrue();
}
示例15: Value_Scale
public void Value_Scale (bool refresh)
{
ScaleTransform st = new ScaleTransform ();
st.ScaleX = 2.0;
st.ScaleY = 0.5;
TransformGroup tg = new TransformGroup ();
tg.Children.Add (st);
Assert.AreEqual (1, tg.Children.Count, "Children-1");
Assert.IsFalse (tg.Value.IsIdentity, "IsIdentity-1");
Matrix expected1 = new Matrix (2.0, 0.0, 0.0, 0.5, 0.0, 0.0);
Assert.IsTrue (expected1.Equals (tg.Value), "Matrix-1");
st.ScaleY = 2.0;
if (refresh) {
Matrix expected2 = new Matrix (2.0, 0.0, 0.0, 2.0, 0.0, 0.0);
// if updated Value should be like expected2, but it's not
Assert.IsFalse (expected2.Equals (tg.Value), "Matrix-2a");
// still equals to the old computed value
Assert.IsTrue (expected1.Equals (tg.Value), "Matrix-2b");
}
ScaleTransform st2 = new ScaleTransform ();
st2.ScaleX = 0.5;
st2.ScaleY = 0.5;
tg.Children.Add (st2);
Assert.AreEqual (2, tg.Children.Count, "Children-3");
Assert.IsTrue (tg.Value.IsIdentity, "IsIdentity-3");
Assert.IsTrue (Matrix.Identity.Equals (tg.Value), "Matrix-3");
}