当前位置: 首页>>代码示例>>C#>>正文


C# Complex.GetHashCode方法代码示例

本文整理汇总了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));
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:26,代码来源:operation_ComparisonHashCode.cs

示例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);
        }
开发者ID:WilliamRobertMontgomery,项目名称:asp-dot-net-training-project,代码行数:19,代码来源:Test.cs

示例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));
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:19,代码来源:ComplexTests.cs

示例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());
		}
开发者ID:Altaxo,项目名称:Altaxo,代码行数:9,代码来源:ComplexDoubleTest.cs

示例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");
            }
        }
开发者ID:gitter-badger,项目名称:corefx,代码行数:71,代码来源:operation_ComparisonHashCode.cs


注:本文中的Complex.GetHashCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。