aboutsummaryrefslogtreecommitdiffhomepage
path: root/csharp/src/Google.Protobuf.Test/Collections/MapFieldTest.cs
diff options
context:
space:
mode:
Diffstat (limited to 'csharp/src/Google.Protobuf.Test/Collections/MapFieldTest.cs')
-rw-r--r--csharp/src/Google.Protobuf.Test/Collections/MapFieldTest.cs75
1 files changed, 75 insertions, 0 deletions
diff --git a/csharp/src/Google.Protobuf.Test/Collections/MapFieldTest.cs b/csharp/src/Google.Protobuf.Test/Collections/MapFieldTest.cs
index 9c845907..8791dffc 100644
--- a/csharp/src/Google.Protobuf.Test/Collections/MapFieldTest.cs
+++ b/csharp/src/Google.Protobuf.Test/Collections/MapFieldTest.cs
@@ -499,6 +499,14 @@ namespace Google.Protobuf.Collections
}
[Test]
+ public void KeysCopyTo()
+ {
+ var map = new MapField<string, string> { { "foo", "bar" }, { "x", "y" } };
+ var keys = map.Keys.ToArray(); // Uses CopyTo internally
+ CollectionAssert.AreEquivalent(new[] { "foo", "x" }, keys);
+ }
+
+ [Test]
public void ValuesContains()
{
var map = new MapField<string, string> { { "foo", "bar" }, { "x", "y" } };
@@ -511,6 +519,14 @@ namespace Google.Protobuf.Collections
}
[Test]
+ public void ValuesCopyTo()
+ {
+ var map = new MapField<string, string> { { "foo", "bar" }, { "x", "y" } };
+ var values = map.Values.ToArray(); // Uses CopyTo internally
+ CollectionAssert.AreEquivalent(new[] { "bar", "y" }, values);
+ }
+
+ [Test]
public void ToString_StringToString()
{
var map = new MapField<string, string> { { "foo", "bar" }, { "x", "y" } };
@@ -524,6 +540,65 @@ namespace Google.Protobuf.Collections
Assert.Throws<ArgumentException>(() => map.ToString());
}
+ [Test]
+ public void NaNValuesComparedBitwise()
+ {
+ var map1 = new MapField<string, double>
+ {
+ { "x", SampleNaNs.Regular },
+ { "y", SampleNaNs.SignallingFlipped }
+ };
+
+ var map2 = new MapField<string, double>
+ {
+ { "x", SampleNaNs.Regular },
+ { "y", SampleNaNs.PayloadFlipped }
+ };
+
+ var map3 = new MapField<string, double>
+ {
+ { "x", SampleNaNs.Regular },
+ { "y", SampleNaNs.SignallingFlipped }
+ };
+
+ EqualityTester.AssertInequality(map1, map2);
+ EqualityTester.AssertEquality(map1, map3);
+ Assert.True(map1.Values.Contains(SampleNaNs.SignallingFlipped));
+ Assert.False(map2.Values.Contains(SampleNaNs.SignallingFlipped));
+ }
+
+ // This wouldn't usually happen, as protos can't use doubles as map keys,
+ // but let's be consistent.
+ [Test]
+ public void NaNKeysComparedBitwise()
+ {
+ var map = new MapField<double, string>
+ {
+ { SampleNaNs.Regular, "x" },
+ { SampleNaNs.SignallingFlipped, "y" }
+ };
+ Assert.AreEqual("x", map[SampleNaNs.Regular]);
+ Assert.AreEqual("y", map[SampleNaNs.SignallingFlipped]);
+ string ignored;
+ Assert.False(map.TryGetValue(SampleNaNs.PayloadFlipped, out ignored));
+ }
+
+#if !NET35
+ [Test]
+ public void IDictionaryKeys_Equals_IReadOnlyDictionaryKeys()
+ {
+ var map = new MapField<string, string> { { "foo", "bar" }, { "x", "y" } };
+ CollectionAssert.AreEquivalent(((IDictionary<string, string>)map).Keys, ((IReadOnlyDictionary<string, string>)map).Keys);
+ }
+
+ [Test]
+ public void IDictionaryValues_Equals_IReadOnlyDictionaryValues()
+ {
+ var map = new MapField<string, string> { { "foo", "bar" }, { "x", "y" } };
+ CollectionAssert.AreEquivalent(((IDictionary<string, string>)map).Values, ((IReadOnlyDictionary<string, string>)map).Values);
+ }
+#endif
+
private static KeyValuePair<TKey, TValue> NewKeyValuePair<TKey, TValue>(TKey key, TValue value)
{
return new KeyValuePair<TKey, TValue>(key, value);