Exemple #1
0
        /// <summary>
        /// Compares this map with another for equality.
        /// </summary>
        /// <remarks>
        /// The order of the key/value pairs in the maps is not deemed significant in this comparison.
        /// </remarks>
        /// <param name="other">The map to compare this with.</param>
        /// <returns><c>true</c> if <paramref name="other"/> refers to an equal map; <c>false</c> otherwise.</returns>
        public bool Equals(MapField <TKey, TValue> other)
        {
            if (other == null)
            {
                return(false);
            }
            if (other == this)
            {
                return(true);
            }
            if (other.Count != this.Count)
            {
                return(false);
            }
            var valueComparer = ValueEqualityComparer;

            foreach (var pair in this)
            {
                TValue value;
                if (!other.TryGetValue(pair.Key, out value))
                {
                    return(false);
                }
                if (!valueComparer.Equals(value, pair.Value))
                {
                    return(false);
                }
            }
            return(true);
        }
        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));
        }