예제 #1
0
        public void GetHashCode_ReturnsUniqueOrderedValue()
        {
            IDictionary <int, SDate> hashes = new Dictionary <int, SDate>();
            int lastHash = int.MinValue;

            for (int year = 1; year <= 4; year++)
            {
                foreach (string season in SDateTests.ValidSeasons)
                {
                    foreach (int day in SDateTests.ValidDays)
                    {
                        SDate date = new SDate(day, season, year);
                        int   hash = date.GetHashCode();
                        if (hashes.TryGetValue(hash, out SDate otherDate))
                        {
                            Assert.Fail($"Received identical hash code {hash} for dates {otherDate} and {date}.");
                        }
                        if (hash < lastHash)
                        {
                            Assert.Fail($"Received smaller hash code for date {date} ({hash}) relative to {hashes[lastHash]} ({lastHash}).");
                        }

                        lastHash     = hash;
                        hashes[hash] = date;
                    }
                }
            }
        }