本文整理汇总了C#中Complex.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# Complex.Equals方法的具体用法?C# Complex.Equals怎么用?C# Complex.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Complex
的用法示例。
在下文中一共展示了Complex.Equals方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VerifyComplexComparison
private static void VerifyComplexComparison(Complex c1, Complex c2, bool expectedResult, bool expectedResultEqual)
{
Assert.True(expectedResult == (c1 == c2), string.Format("c1:{0} == c2{1} is not '{2}' as expected", c1, c2, expectedResult));
Assert.True(expectedResult == (c2 == c1), string.Format("c2:{0} == c1{1} is not '{2}' as expected", c2, c1, expectedResult));
Assert.True(expectedResult != (c1 != c2), string.Format("c1:{0} != c2{1} is not '{2}' as expected", c1, c2, !expectedResult));
Assert.True(expectedResult != (c2 != c1), string.Format("c2:{0} != c1{1} is not '{2}' as expected", c2, c1, !expectedResult));
bool result = c1.Equals(c2);
Assert.True(expectedResultEqual == result, string.Format("c1:{0}.Equals(c2{1}) is not '{2}' as expected", c1, c2, expectedResultEqual));
if (result) // then verify Hash Code equality
{
Assert.True(c1.GetHashCode() == c2.GetHashCode(), string.Format("c1:{0}.GetHashCode() == c2:{1}.GetHashCode() is 'true' as expected", c1, c2));
}
result = c2.Equals(c1);
Assert.True(expectedResultEqual == result, string.Format("c2:{0}.Equals(c1{1}) is not '{2}' as expected", c2, c1, expectedResultEqual));
if (result) // then verify Hash Code equality
{
Assert.True(c2.GetHashCode() == c1.GetHashCode(), string.Format("Obj c2:{0}.GetHashCode() == c1:{1}.GetHashCode() is 'true' as expected", c2, c1));
}
Assert.True(expectedResult == c2.Equals((Object)c1), string.Format("c2:{0}.Equals((object) c1{1}) is not '{2}' as expected", c2, c1, expectedResult));
Assert.True(expectedResult == c1.Equals((Object)c2), string.Format("c1:{0}.Equals((object) c2{1}) is not '{2}' as expected", c1, c2, expectedResult));
}
示例2: Main
static void Main(string[] args)
{
Complex c1 = new Complex(1, 2);
Complex c2 = new Complex(1, 2);
Complex c3 = new Complex();
Console.WriteLine(c1);
Console.WriteLine(c2);
Console.WriteLine(c3);
Complex c4 = c1.Add(c2);
Console.WriteLine(c4);
Complex c5 = c2.Subtract(c1);
Console.WriteLine(c5);
Complex c6 = c1.Multiply(c2);
Console.WriteLine(c6);
if(c1.Equals(c2))
Console.WriteLine("c1 este egal cu c2");
else
Console.WriteLine("c1 nu este egal cu c2");
}
示例3: TestEqualsAndGetHashCode
public void TestEqualsAndGetHashCode()
{
Complex TestComplex1 = new Complex(real1, real2);
Complex TestComplex2 = new Complex(real1, real2);
Complex TestComplex3 = new Complex(real1, real2);
//Test GetHashCode
Assert.AreEqual(TestComplex1.GetHashCode(), TestComplex2.GetHashCode());
Assert.AreEqual(TestComplex1.GetHashCode(), TestComplex1.GetHashCode());
//Test Equals
Assert.IsTrue(TestComplex1.Equals(TestComplex1));
Assert.AreEqual(TestComplex1.Equals(TestComplex2), TestComplex2.Equals(TestComplex1));
bool firstResult = TestComplex1.Equals(TestComplex2);
bool secondResult = TestComplex2.Equals(TestComplex3);
bool thirdResult = TestComplex1.Equals(TestComplex3);
Assert.IsTrue(firstResult && secondResult && thirdResult);
}
示例4: EqualsTest
public void EqualsTest()
{
Complex cd1 = new Complex(-1.1, 2.2);
Complex cd2 = new Complex(-1.1, 2.2);
Complex cd3 = new Complex(-1, 2);
ComplexFloat cf = new ComplexFloat(-1, 2);
Assert.IsTrue(cd1 == cd2);
Assert.IsTrue(cd1.Equals(cd2));
Assert.IsTrue(cd3 == cf);
Assert.IsTrue(cd3.Equals(cf));
}
示例5: Main
static void Main(string[] args)
{
Complex c1 = new Complex(1, 3);
Complex c2 = new Complex(1.3, 3.5);
Complex c3 = c1;
Console.WriteLine("c1 + c2: {0}", (c1 + c2));
Console.WriteLine("c3 += c2: {0}", (c3 += c2));
Console.WriteLine("c1 - c2: {0}", (c1 - c2));
Console.WriteLine(c1.Equals(c2));
Complex c4 = new Complex(1, 3);
Console.WriteLine(c1.Equals(c4));
Console.WriteLine(c1 == c4);
Complex c = new Complex(1, 1);
Console.WriteLine("C++: {0} (should be: 1,1)", c++);
Console.WriteLine("C: {0} (should be: 2,2)", c);
Console.WriteLine("++C: {0} (should be: 3,3)", ++c);
Console.WriteLine("Press any Key to continue");
Console.ReadKey();
}
示例6: Equals
private static void Equals(Complex complex1, object obj, bool expected, bool expectedEquals)
{
if (obj is Complex)
{
Complex complex2 = (Complex)obj;
Assert.True(expected == (complex1 == complex2), string.Format("c1:{0} == c2{1} is not '{2}' as expected", complex1, complex2, expected));
Assert.True(expected == (complex2 == complex1), string.Format("c2:{0} == c1{1} is not '{2}' as expected", complex2, complex1, expected));
Assert.False(expected == (complex1 != complex2), string.Format("c1:{0} != c2{1} is not '{2}' as expected", complex1, complex2, !expected));
Assert.False(expected == (complex2 != complex1), string.Format("c2:{0} != c1{1} is not '{2}' as expected", complex2, complex1, !expected));
Assert.True(expectedEquals == complex1.Equals(complex2), string.Format("{0}.Equals({1}) is not '{2}' as expected", complex1, complex2, expectedEquals));
Assert.True(expectedEquals == complex2.Equals(complex1), string.Format("{0}.Equals({1}) is not '{2}' as expected", complex2, complex1, expectedEquals));
Assert.True(expectedEquals == complex1.GetHashCode().Equals(complex2.GetHashCode()),
string.Format("{0}.GetHashCode().Equals({1}.GetHashCode()) is not '{2}' as expected", complex1, complex2, expectedEquals));
}
Assert.True(expectedEquals == complex1.Equals(obj), string.Format("{0}.Equals({1}) is not '{2}' as expected", complex1, obj, expectedEquals));
}
示例7: RunTests_WithNonComplexObject
public static void RunTests_WithNonComplexObject()
{
// local variables
double real = Support.GetSmallRandomDoubleValue(false);
Complex randomComplex = new Complex(real, 0.0);
// verify with same double value
Assert.False(randomComplex.Equals((Object)real), string.Format("Obj randomComplex:{0}.Equals((object) real) is not 'false' as expected", randomComplex, real));
// verify with null
Assert.False(randomComplex.Equals((Object)null), string.Format("Obj randomComplex:{0}.Equals((object) null) is not 'false' as expected", randomComplex));
// verify with 0
Assert.False(randomComplex.Equals((Object)0), string.Format("Obj randomComplex:{0}.Equals((object) 0) is not 'false' as expected", randomComplex));
// verify with string
Assert.False(randomComplex.Equals((Object)"0"), string.Format("Obj randomComplex:{0}.Equals((object) \"0\") is not 'false' as expected", randomComplex));
}
示例8: RunTests_WithNonComplexObject
public static void RunTests_WithNonComplexObject()
{
// local variables
Double real = Support.GetSmallRandomDoubleValue(false);
Complex randomComplex = new Complex(real, 0.0);
// verify with same double value
if (randomComplex.Equals((Object)real))
{
Console.WriteLine("Error-9674Obj randomComplex:{0}.Equals((object) real) is not 'false' as expected", randomComplex, real);
Assert.True(false, "Verification Failed");
}
// verify with null
if (randomComplex.Equals((Object)null))
{
Console.WriteLine("Error-5441Obj randomComplex:{0}.Equals((object) null) is not 'false' as expected", randomComplex);
Assert.True(false, "Verification Failed");
}
// verify with 0
if (randomComplex.Equals((Object)0))
{
Console.WriteLine("Error-5441Obj randomComplex:{0}.Equals((object) 0) is not 'false' as expected", randomComplex);
Assert.True(false, "Verification Failed");
}
// verify with string
if (randomComplex.Equals((Object)"0"))
{
Console.WriteLine("Error-5441Obj randomComplex:{0}.Equals((object) \"0\") is not 'false' as expected", randomComplex);
Assert.True(false, "Verification Failed");
}
}
示例9: VerifyComplexComparison
private static void VerifyComplexComparison(Complex c1, Complex c2, bool expectedResult, bool expectedResultEqual)
{
if (expectedResult != (c1 == c2))
{
Console.WriteLine("Error-8592 c1:{0} == c2{1} is not '{2}' as expected", c1, c2, expectedResult);
Assert.True(false, "Verification Failed");
}
if (expectedResult != (c2 == c1))
{
Console.WriteLine("Error-8592-1 c2:{0} == c1{1} is not '{2}' as expected", c2, c1, expectedResult);
Assert.True(false, "Verification Failed");
}
if (expectedResult == (c1 != c2))
{
Console.WriteLine("Error-81792 c1:{0} != c2{1} is not '{2}' as expected", c1, c2, !expectedResult);
Assert.True(false, "Verification Failed");
}
if (expectedResult == (c2 != c1))
{
Console.WriteLine("Error-81792-1 c2:{0} != c1{1} is not '{2}' as expected", c2, c1, !expectedResult);
Assert.True(false, "Verification Failed");
}
bool result = c1.Equals(c2);
if (expectedResultEqual != result)
{
Console.WriteLine("Error-6172 c1:{0}.Equals(c2{1}) is not '{2}' as expected", c1, c2, expectedResultEqual);
Assert.True(false, "Verification Failed");
}
if (result) // then verify Hash Code equality
{
if (c1.GetHashCode() != c2.GetHashCode())
{
Console.WriteLine("Error-9HaSh72 c1:{0}.GetHashCode() == c2:{1}.GetHashCode() is 'true' as expected", c1, c2);
Assert.True(false, "Verification Failed");
}
}
result = c2.Equals(c1);
if (expectedResultEqual != result)
{
Console.WriteLine("Error-6172-1 c2:{0}.Equals(c1{1}) is not '{2}' as expected", c2, c1, expectedResultEqual);
Assert.True(false, "Verification Failed");
}
if (result) // then verify Hash Code equality
{
if (c2.GetHashCode() != c1.GetHashCode())
{
Console.WriteLine("Error-9HaSh72-1 c2:{0}.GetHashCode() == c1:{1}.GetHashCode() is 'true' as expected", c2, c1);
Assert.True(false, "Verification Failed");
}
}
if (expectedResult != c2.Equals((Object)c1))
{
Console.WriteLine("Error-6172Obj c2:{0}.Equals((object) c1{1}) is not '{2}' as expected", c2, c1, expectedResult);
Assert.True(false, "Verification Failed");
}
if (expectedResult != c1.Equals((Object)c2))
{
Console.WriteLine("Error-6172Obj-1 c1:{0}.Equals((object) c2{1}) is not '{2}' as expected", c1, c2, expectedResult);
Assert.True(false, "Verification Failed");
}
}