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));
        }
        public void EqualityHandlesNullValues()
        {
            var map1 = new MapField <string, ForeignMessage>();

            map1.Add("a", new ForeignMessage {
                C = 10
            });
            map1.Add("b", null);

            var map2 = new MapField <string, ForeignMessage>();

            map2.Add("a", new ForeignMessage {
                C = 10
            });
            map2.Add("b", null);

            EqualityTester.AssertEquality(map1, map2);
            // Check the null value isn't ignored entirely...
            Assert.IsTrue(map1.Remove("b"));
            EqualityTester.AssertInequality(map1, map2);
            map1.Add("b", new ForeignMessage());
            EqualityTester.AssertInequality(map1, map2);
            map1["b"] = null;
            EqualityTester.AssertEquality(map1, map2);
        }
        public void Equality_Simple()
        {
            var map = new MapField <string, string>();

            EqualityTester.AssertEquality(map, map);
            EqualityTester.AssertInequality(map, null);
            Assert.IsFalse(map.Equals(new object()));
        }
        public void EqualityIsKeySensitive()
        {
            var map1 = new MapField <string, string>();

            map1.Add("first key", "v1");
            map1.Add("second key", "v2");

            var map2 = new MapField <string, string>();

            map2.Add("third key", "v1");
            map2.Add("fourth key", "v2");

            EqualityTester.AssertInequality(map1, map2);
        }
Example #5
0
        public void NaNComparisons()
        {
            var message1 = new TestWellKnownTypes {
                DoubleField = SampleNaNs.Regular
            };
            var message2 = new TestWellKnownTypes {
                DoubleField = SampleNaNs.PayloadFlipped
            };
            var message3 = new TestWellKnownTypes {
                DoubleField = SampleNaNs.Regular
            };

            EqualityTester.AssertInequality(message1, message2);
            EqualityTester.AssertEquality(message1, message3);
        }
        public void EqualityIsValueSensitive()
        {
            // Note: Without some care, it's a little easier than one might
            // hope to see hash collisions, but only in some environments...
            var map1 = new MapField <string, string>();

            map1.Add("a", "first value");
            map1.Add("b", "second value");

            var map2 = new MapField <string, string>();

            map2.Add("a", "third value");
            map2.Add("b", "fourth value");

            EqualityTester.AssertInequality(map1, map2);
        }
Example #7
0
        public void EqualityIsKeySensitive()
        {
            var map1 = new MapField <string, string>
            {
                { "first key", "v1" },
                { "second key", "v2" }
            };

            var map2 = new MapField <string, string>
            {
                { "third key", "v1" },
                { "fourth key", "v2" }
            };

            EqualityTester.AssertInequality(map1, map2);
        }
Example #8
0
        public void NaNValuesComparedBitwise()
        {
            var list1 = new RepeatedField <double> {
                SampleNaNs.Regular, SampleNaNs.SignallingFlipped
            };
            var list2 = new RepeatedField <double> {
                SampleNaNs.Regular, SampleNaNs.PayloadFlipped
            };
            var list3 = new RepeatedField <double> {
                SampleNaNs.Regular, SampleNaNs.SignallingFlipped
            };

            EqualityTester.AssertInequality(list1, list2);
            EqualityTester.AssertEquality(list1, list3);
            Assert.True(list1.Contains(SampleNaNs.SignallingFlipped));
            Assert.False(list2.Contains(SampleNaNs.SignallingFlipped));
        }
        public void NaNValuesComparedBitwise()
        {
            var list1 = new RepeatedField <double> {
                SampleNaNs.Regular, SampleNaNs.SignallingFlipped
            };
            var list2 = new RepeatedField <double> {
                SampleNaNs.Regular, SampleNaNs.PayloadFlipped
            };
            var list3 = new RepeatedField <double> {
                SampleNaNs.Regular, SampleNaNs.SignallingFlipped
            };

            // 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));
        }