Bläddra i källkod

make check for distinct hashcode optional

Jan Tattermusch 6 år sedan
förälder
incheckning
60a889e048

+ 2 - 1
csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs

@@ -750,7 +750,8 @@ namespace Google.Protobuf.Collections
             var list2 = new RepeatedField<double> { SampleNaNs.Regular, SampleNaNs.PayloadFlipped };
             var list3 = new RepeatedField<double> { SampleNaNs.Regular, SampleNaNs.SignallingFlipped };
 
-            EqualityTester.AssertInequality(list1, list2);
+            // All SampleNaNs have the same hashcode under certain targets (e.g. netcoreapp2.1)
+            EqualityTester.AssertInequality(list1, list2, checkHashcode: false);
             EqualityTester.AssertEquality(list1, list3);
             Assert.True(list1.Contains(SampleNaNs.SignallingFlipped));
             Assert.False(list2.Contains(SampleNaNs.SignallingFlipped));

+ 3 - 2
csharp/src/Google.Protobuf.Test/EqualityTester.cs

@@ -49,13 +49,14 @@ namespace Google.Protobuf
             Assert.AreEqual(first.GetHashCode(), second.GetHashCode());
         }
 
-        public static void AssertInequality<T>(T first, T second) where T : IEquatable<T>
+        public static void AssertInequality<T>(T first, T second, bool checkHashcode = true) where T : IEquatable<T>
         {
             Assert.IsFalse(first.Equals(second));
             Assert.IsFalse(first.Equals((object) second));
             // While this isn't a requirement, the chances of this test failing due to
             // coincidence rather than a bug are very small.
-            if (first != null && second != null)
+            // For such rare cases, an argument can be used to disable the check.
+            if (checkHashcode && first != null && second != null)
             {
                 Assert.AreNotEqual(first.GetHashCode(), second.GetHashCode());
             }