本文整理汇总了C#中Complex.GetHashCode方法的典型用法代码示例。如果您正苦于以下问题:C# Complex.GetHashCode方法的具体用法?C# Complex.GetHashCode怎么用?C# Complex.GetHashCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Complex
的用法示例。
在下文中一共展示了Complex.GetHashCode方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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);
}
示例3: 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));
}
示例4: HashTest
public void HashTest()
{
Complex cd1 = new Complex(1.1, 2.2);
Complex cd2 = new Complex(1.1, 3.3);
Complex cd3 = new Complex(0.1, 2.2);
Assert.AreNotEqual(cd1.GetHashCode(), cd2.GetHashCode());
Assert.AreNotEqual(cd1.GetHashCode(), cd3.GetHashCode());
Assert.AreNotEqual(cd2.GetHashCode(), cd3.GetHashCode());
}
示例5: 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");
}
}