public void NullSequenceNotEqualToEmptySequence()
 {
     var comparer = EqualityCompare<int[]>.Default();
     var objectComparer = comparer as System.Collections.IEqualityComparer;
     Assert.IsFalse(comparer.Equals(null, new int[0]));
     Assert.IsFalse(objectComparer.Equals(null, new int[0]));
 }
 public void NullIsNotEqualToValue()
 {
     var comparer = EqualityCompare<int?>.Default();
     var objectComparer = comparer as System.Collections.IEqualityComparer;
     Assert.IsFalse(comparer.Equals(3, null));
     Assert.IsFalse(objectComparer.Equals(3, null));
 }
        public void SubstitutesCompareDefaultForNull()
        {
            IEqualityComparer <int> source = null;
            var comparer = source.EquateSequence();

            Assert.AreSame(EqualityCompare <int> .Default(), (comparer as SequenceEqualityComparer <int>).Source);
        }
Example #4
0
        public void SubstitutesCompareDefaultForNull()
        {
            IEqualityComparer <int> source = null;
            var comparer = source.SelectEquateFrom((Person p) => p.Priority);

            Assert.AreSame(EqualityCompare <int> .Default(), (comparer as SelectEqualityComparer <Person, int>).Source);
        }
Example #5
0
        public void SubstitutesCompareDefaultForComparerDefault()
        {
            IEqualityComparer <Person> thenByComparer = EqualityCompare <string> .Default().SelectEquateFrom((Person p) => p.FirstName);

            var comparer = EqualityComparer <Person> .Default.ThenEquateBy(thenByComparer);

            Assert.AreSame(EqualityCompare <Person> .Default(), (comparer as CompoundEqualityComparer <Person>).Source);
        }
 public void NullSequenceIsEqualToNullSequence()
 {
     var comparer = EqualityCompare<int[]>.Default();
     var objectComparer = comparer as System.Collections.IEqualityComparer;
     Assert.AreEqual(comparer.GetHashCode(null), comparer.GetHashCode(null));
     Assert.AreEqual(objectComparer.GetHashCode(null), objectComparer.GetHashCode(null));
     Assert.IsTrue(comparer.Equals(null, null));
     Assert.IsTrue(objectComparer.Equals(null, null));
 }
Example #7
0
        public void ThenByIsOnlyAppliedAsTieBreaker()
        {
            IEqualityComparer <Person> thenByComparer = new AnonymousEqualityComparer <Person>
            {
                Equals = (x, y) => { Assert.Fail(); return(false); },
            };
            var comparer = EqualityCompare <Person> .Default().ThenEquateBy(thenByComparer);

            Assert.IsFalse(comparer.Equals(AbeAbrams, CaseyJohnson));
            Assert.IsFalse(comparer.Equals(CaseyJohnson, AbeAbrams));
        }
Example #8
0
        public void ThenByIsAppliedAsTieBreaker()
        {
            IEqualityComparer <Person> thenByComparer = EqualityCompare <string> .Default().SelectEquateFrom((Person p) => p.FirstName);

            IEqualityComparer <Person> defaultComparer = EqualityCompare <Person> .Default();

            IEqualityComparer <Person> fullComparer = defaultComparer.ThenEquateBy(thenByComparer);

            Assert.IsTrue(defaultComparer.Equals(AbeAbrams, WilliamAbrams));
            Assert.AreEqual(defaultComparer.GetHashCode(AbeAbrams), defaultComparer.GetHashCode(WilliamAbrams));
            Assert.IsFalse(thenByComparer.Equals(AbeAbrams, WilliamAbrams));
            Assert.IsFalse(fullComparer.Equals(AbeAbrams, WilliamAbrams));
        }
 public void UsesSequenceEqualityComparerForSequences()
 {
     var threeA = new[] { 3 };
     var threeB = new[] { 3 };
     var five = new[] { 5 };
     var comparer = EqualityCompare<int[]>.Default();
     var objectComparer = comparer as System.Collections.IEqualityComparer;
     Assert.AreEqual(comparer.GetHashCode(threeA), comparer.GetHashCode(threeB));
     Assert.AreEqual(objectComparer.GetHashCode(threeA), objectComparer.GetHashCode(threeB));
     Assert.IsTrue(comparer.Equals(threeA, threeB));
     Assert.IsTrue(objectComparer.Equals(threeA, threeB));
     Assert.IsFalse(comparer.Equals(threeB, five));
     Assert.IsFalse(objectComparer.Equals(threeB, five));
 }
Example #10
0
        public void ThenByUsesComparer()
        {
            IEqualityComparer <Person> thenByComparer = EqualityCompare <string> .Default().SelectEquateFrom((Person p) => p.FirstName);

            var comparer = EqualityCompare <Person> .Default().ThenEquateBy(thenByComparer);

            var objectComparer = comparer as System.Collections.IEqualityComparer;

            Assert.IsFalse(comparer.Equals(AbeAbrams, JackAbrams));
            Assert.IsFalse(objectComparer.Equals(AbeAbrams, JackAbrams));
            Assert.IsTrue(comparer.Equals(JackAbrams, JackAbrams2));
            Assert.IsTrue(objectComparer.Equals(JackAbrams, JackAbrams2));
            Assert.AreEqual(comparer.GetHashCode(JackAbrams), comparer.GetHashCode(JackAbrams2));
            Assert.AreEqual(objectComparer.GetHashCode(JackAbrams), objectComparer.GetHashCode(JackAbrams2));
        }
Example #11
0
        public void IsEquivalentToEqualityComparerDefault()
        {
            var a = 3;
            var b = 3;
            var c = 5;

            var defaultComparer = EqualityCompare<int>.Default();
            var netDefaultComparer = EqualityComparer<int>.Default;
            var defaultObjectComparer = defaultComparer as System.Collections.IEqualityComparer;
            Assert.AreEqual(netDefaultComparer.GetHashCode(a), defaultComparer.GetHashCode(a));
            Assert.AreEqual(defaultComparer.GetHashCode(a), defaultObjectComparer.GetHashCode(a));
            Assert.AreEqual(netDefaultComparer.GetHashCode(b), defaultComparer.GetHashCode(b));
            Assert.AreEqual(defaultComparer.GetHashCode(b), defaultObjectComparer.GetHashCode(b));
            Assert.AreEqual(netDefaultComparer.GetHashCode(c), defaultComparer.GetHashCode(c));
            Assert.AreEqual(defaultComparer.GetHashCode(c), defaultObjectComparer.GetHashCode(c));
            Assert.AreEqual(netDefaultComparer.GetHashCode(7) == netDefaultComparer.GetHashCode(13), defaultComparer.GetHashCode(7) == defaultComparer.GetHashCode(13));
            Assert.AreEqual(defaultComparer.GetHashCode(7) == defaultComparer.GetHashCode(13), defaultObjectComparer.GetHashCode(7) == defaultObjectComparer.GetHashCode(13));
            Assert.AreEqual(netDefaultComparer.Equals(a, b), defaultComparer.Equals(a, b));
            Assert.AreEqual(defaultComparer.Equals(a, b), defaultObjectComparer.Equals(a, b));
            Assert.AreEqual(netDefaultComparer.Equals(a, c), defaultComparer.Equals(a, c));
            Assert.AreEqual(defaultComparer.Equals(a, c), defaultObjectComparer.Equals(a, c));
        }
 public void NullIsNotEqualToEmpty()
 {
     Assert.IsFalse(EqualityCompare <int> .Default().EquateSequence().Equals(null, Enumerable.Empty <int>()));
     Assert.IsFalse(EqualityCompare <int> .Default().EquateSequence().Equals(Enumerable.Empty <int>(), null));
 }
 public void EqualLengthSequencesWithUnequalElementsAreNotEqual()
 {
     Assert.IsFalse(EqualityCompare <int> .Default().EquateSequence().Equals(new[] { 3, 4 }, new[] { 3, 5 }));
     Assert.IsFalse(EqualityCompare <int> .Default().EquateSequence().Equals(new[] { 3, 4, 5 }, new[] { 3, 3, 5 }));
 }
 public void SequencesAreEqualIfElementsAreEqual()
 {
     Assert.IsTrue(EqualityCompare <int> .Default().EquateSequence().Equals(new[] { 3, 4 }, new[] { 3, 4 }));
     Assert.IsTrue(EqualityCompare <int> .Default().EquateSequence().Equals(new[] { 3, 4, 5 }, new[] { 3, 4, 5 }));
     Assert.AreEqual(EqualityCompare <int> .Default().EquateSequence().GetHashCode(new[] { 3, 4 }), Compare <int> .Default().EquateSequence().GetHashCode(new[] { 3, 4 }));
 }
 public void ShorterSequenceIsNotEqualToLongerSequenceIfElementsAreEqual()
 {
     Assert.IsFalse(EqualityCompare <int> .Default().EquateSequence().Equals(new[] { 3, 4 }, new[] { 3, 4, 5 }));
     Assert.IsFalse(EqualityCompare <int> .Default().EquateSequence().Equals(new[] { 3, 4, 5 }, new[] { 3, 4 }));
 }
        public void SubstitutesCompareDefaultForComparerDefault()
        {
            var comparer = EqualityComparer <int> .Default.EquateSequence();

            Assert.AreSame(EqualityCompare <int> .Default(), (comparer as SequenceEqualityComparer <int>).Source);
        }
Example #17
0
 public void DefaultForString_IsDefaultComparer()
 {
     // Ensure string default comparer is not a sequence comparer over chars.
     Assert.AreSame(Comparers.Util.DefaultComparer <string> .Instance, EqualityCompare <string> .Default());
 }