make check for distinct hashcode optional
diff --git a/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs b/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs
index 129923b..b3863a4 100644
--- a/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs
+++ b/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs
@@ -750,7 +750,8 @@
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));
diff --git a/csharp/src/Google.Protobuf.Test/EqualityTester.cs b/csharp/src/Google.Protobuf.Test/EqualityTester.cs
index a669bab..d4b3c13 100644
--- a/csharp/src/Google.Protobuf.Test/EqualityTester.cs
+++ b/csharp/src/Google.Protobuf.Test/EqualityTester.cs
@@ -49,13 +49,14 @@
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());
}