Exemple #1
0
        public void EqualityTestsWork()
        {
            var pair            = new TestOrderedPair <int, string>(1, "2");
            var matchingPair    = new TestOrderedPair <int, string>(1, "2");
            var nonMatchingPair = new TestOrderedPair <int, string>(3, "4");
            var reversedPair    = new TestOrderedPair <string, int>("2", 1);

            Assert.IsFalse(pair.Equals(null));
            Assert.IsTrue(pair.Equals(matchingPair));
            Assert.IsFalse(pair.Equals(nonMatchingPair));
            Assert.IsFalse(pair.Equals(reversedPair));

            var matchingTypePair         = new TestOrderedPair <int, int>(1, 2);
            var matchingTypeReversedPair = new TestOrderedPair <int, int>(2, 1);

            Assert.IsFalse(matchingTypePair.Equals(matchingTypeReversedPair));
        }
Exemple #2
0
        // Just has to not throw.
        public void GetHashCodeRespectsEquality()
        {
            var pairHash         = new TestOrderedPair <int, string>(1, "2").GetHashCode();
            var matchingPairHash = new TestOrderedPair <int, string>(1, "2").GetHashCode();

            Assert.IsTrue(pairHash.Equals(matchingPairHash));
            //Don't need to assert anything about the other cases, since inequality doesn't demand unequal hashes.

            var pairHash2         = new TestOrderedPair <int, int>(1, 2).GetHashCode();
            var matchingPairHash2 = new TestOrderedPair <int, int>(1, 2).GetHashCode();

            Assert.IsTrue(pairHash2.Equals(matchingPairHash2));
            //Don't need to assert anything about the other cases, since inequality doesn't demand unequal hashes.

            var pairHash3         = new TestOrderedPair <int, string>(14254, "2v5gws45£Q$T5tyw").GetHashCode();
            var matchingPairHash3 = new TestOrderedPair <int, string>(14254, "2v5gws45£Q$T5tyw").GetHashCode();

            Assert.IsTrue(pairHash3.Equals(matchingPairHash3));
            //Don't need to assert anything about the other cases, since inequality doesn't demand unequal hashes.
        }