Esempio n. 1
0
        public void EnumerableEqualityComparerGetHashCodeReturnsDefaultHashCodeIfSequenceIsEmpty()
        {
            const int expectedHashCode = 23;

            var comparer = new EnumerableComparer <int>();

            IEnumerable <int> sequence = new List <int>();

            int result = comparer.GetHashCode(sequence);

            Assert.AreEqual(expectedHashCode, result);
        }
Esempio n. 2
0
        public void EnumerableEqualityComparerGetHashCodeReturnsZeroIfSequenceIsNull()
        {
            const int expectedHashCode = 0;

            var comparer = new EnumerableComparer <int>();

            IEnumerable <int> sequence = null;

            int result = comparer.GetHashCode(sequence);

            Assert.AreEqual(expectedHashCode, result);
        }
Esempio n. 3
0
        public void EnumerableEqualityComparerGetHashCodeReturnsSameHashCodeIfSequenceContainsNullElements()
        {
            var comparer = new EnumerableComparer <int?>();

            IEnumerable <int?> sequence = new List <int?> {
                1, 2, null, 4, 5
            };

            //get the HashCode 2000 times to confirm it is consistent for lifetime of the enumerable
            HashSet <int> hashes = new HashSet <int>();

            for (int i = 0; i < 2000; i++)
            {
                hashes.Add(comparer.GetHashCode(sequence));
            }

            Assert.AreEqual(1, hashes.Count);
        }