Example #1
0
        /// <summary>Indicates whether the current object is equal to another object of the same type.</summary>
        /// <returns>true if the current object is equal to the <paramref name="other" /> parameter; otherwise, false.</returns>
        /// <param name="other">An object to compare with this object.</param>
        public bool Equals(EnumerableObject <T> other)
        {
            if (other == null)
            {
                return(false);
            }

            return(OtherProperty == other.SomeProperty);
        }
Example #2
0
        public void IEquatableHasPrecedenceOverEnumerableEquals()
        {
            var x = new EquatableWithEnumerableObject <int>(new[] { 1, 2, 3, 4, 5 }, 42);
            var y = new EnumerableObject <int>(new[] { 5, 4, 3, 2, 1 }, 42);
            var z = new EnumerableObject <int>(new[] { 1, 2, 3, 4, 5 }, 15);

            Assert.That(comparer.AreEqual(x, y, ref tolerance), Is.True);
            Assert.That(comparer.AreEqual(y, x, ref tolerance), Is.True);
            Assert.That(comparer.AreEqual(x, z, ref tolerance), Is.False);
            Assert.That(comparer.AreEqual(z, x, ref tolerance), Is.False);

            Assert.That(y, Is.EqualTo(x));
            Assert.That(x, Is.EqualTo(y));
            Assert.That(z, Is.Not.EqualTo(x));
            Assert.That(x, Is.Not.EqualTo(z));
        }
Example #3
0
        public void IEquatableIsIgnoredAndEnumerableEqualsUsedWithAsCollection()
        {
            comparer.CompareAsCollection = true;

            var x = new EquatableWithEnumerableObject <int>(new[] { 1, 2, 3, 4, 5 }, 42);
            var y = new EnumerableObject <int>(new[] { 5, 4, 3, 2, 1 }, 42);
            var z = new EnumerableObject <int>(new[] { 1, 2, 3, 4, 5 }, 15);

            Assert.That(comparer.AreEqual(x, y, ref tolerance), Is.False);
            Assert.That(comparer.AreEqual(y, x, ref tolerance), Is.False);
            Assert.That(comparer.AreEqual(x, z, ref tolerance), Is.True);
            Assert.That(comparer.AreEqual(z, x, ref tolerance), Is.True);

            Assert.That(y, Is.Not.EqualTo(x).AsCollection);
            Assert.That(x, Is.Not.EqualTo(y).AsCollection);
            Assert.That(z, Is.EqualTo(x).AsCollection);
            Assert.That(x, Is.EqualTo(z).AsCollection);
        }