public void InheritingAndOverridingIEquatable()
        {
            var obj1 = new InheritingEquatableObject {
                SomeProperty = 1, OtherProperty = 2
            };
            var obj2 = new InheritingEquatableObject {
                SomeProperty = 1, OtherProperty = 2
            };
            var obj3 = new InheritingEquatableObject {
                SomeProperty = 1, OtherProperty = 3
            };
            var obj4 = new InheritingEquatableObject {
                SomeProperty = 4, OtherProperty = 2
            };

            // TODO: Reinstate
            //Assert.That(obj1, Is.EqualTo(obj2));
            Assert.That(obj1, Is.Not.EqualTo(obj3));
            Assert.That(obj1, Is.Not.EqualTo(obj4));

            var n         = new TCLiteEqualityComparer();
            var tolerance = Tolerance.Exact;

            Assert.That(n.AreEqual(obj1, obj2, ref tolerance), Is.True);
            Assert.That(n.AreEqual(obj2, obj1, ref tolerance), Is.True);
            Assert.That(n.AreEqual(obj1, obj3, ref tolerance), Is.False);
            Assert.That(n.AreEqual(obj3, obj1, ref tolerance), Is.False);
            Assert.That(n.AreEqual(obj1, obj4, ref tolerance), Is.False);
            Assert.That(n.AreEqual(obj4, obj1, ref tolerance), Is.False);
        }
Exemple #2
0
        /// <summary>Construct a CollectionTally object from a comparer and a collection.</summary>
        /// <param name="comparer">The comparer to use for equality.</param>
        /// <param name="c">The expected collection to compare against.</param>
        public CollectionTally(TCLiteEqualityComparer comparer, IEnumerable c)
        {
            _comparer = comparer;

            foreach (object o in c)
            {
                _missingItems.Add(o);
            }
        }
        public void SelfContainedItemDoesntRecurseForever <T>(T x, ICollection y)
        {
            var equalityComparer = new TCLiteEqualityComparer();
            var tolerance        = Tolerance.Default;

            equalityComparer.ExternalComparers.Add(new DetectRecursionComparer(30));

            Assert.DoesNotThrow(() => equalityComparer.AreEqual(x, y, ref tolerance));
        }
Exemple #4
0
        public void TestToleranceExact()
        {
            var noneTolerance = Tolerance.Exact;

            Assert.IsFalse(noneTolerance.IsDefault);

            var comparer = new TCLiteEqualityComparer();

            Assert.IsFalse(comparer.AreEqual(2.0d, 2.1d, ref noneTolerance));
        }
Exemple #5
0
        public void TestToleranceDefault()
        {
            var defaultTolerance = Tolerance.Default;

            Assert.IsTrue(defaultTolerance.IsDefault);

            var comparer = new TCLiteEqualityComparer();

            Assert.IsTrue(comparer.AreEqual(2.0d, 2.1d, ref defaultTolerance));
        }
        public void SelfContainedDuplicateItemsAreCompared()
        {
            var equalityComparer = new TCLiteEqualityComparer();
            var equalInstance1   = new[] { 1 };
            var equalInstance2   = new[] { 1 };

            var x = new[] { equalInstance1, equalInstance1 };
            var y = new[] { equalInstance2, equalInstance2 };

            Assert.IsTrue(equalityComparer.AreEqual(x, y, ref tolerance));
        }
        public void SelfContainedItemFoundInCollection <T>(T x, ICollection y)
        {
            var equalityComparer = new TCLiteEqualityComparer();
            var tolerance        = Tolerance.Default;
            var equality         = equalityComparer.AreEqual(x, y, ref tolerance);

            Assert.IsFalse(equality);
            // NYI: Assert.Contains(x, y);
            // NYI: Assert.That(y, Contains.Item(x));
            // NYI: Assert.That(y, Does.Contain(x));
        }
        public void ImplementingIEquatableOnABaseClassOrInterfaceThroughInterface()
        {
            IEquatableObject obj1 = new InheritedEquatableObject {
                SomeProperty = 1
            };
            IEquatableObject obj2 = new InheritedEquatableObject {
                SomeProperty = 1
            };

            var n         = new TCLiteEqualityComparer();
            var tolerance = Tolerance.Exact;

            Assert.That(n.AreEqual(obj1, obj2, ref tolerance), Is.True);
            Assert.That(n.AreEqual(obj2, obj1, ref tolerance), Is.True);
        }
        public void ImplementingIEquatableDirectlyOnTheClass()
        {
            var obj1 = new EquatableObject {
                SomeProperty = 1
            };
            var obj2 = new EquatableObject {
                SomeProperty = 1
            };

            var n         = new TCLiteEqualityComparer();
            var tolerance = Tolerance.Exact;

            Assert.That(n.AreEqual(obj1, obj2, ref tolerance), Is.True);
            Assert.That(n.AreEqual(obj2, obj1, ref tolerance), Is.True);
        }
        public void CanHandleMultipleImplementationsOfIEquatable()
        {
            IEquatableObject obj1 = new InheritedEquatableObject {
                SomeProperty = 1
            };
            IEquatableObject obj2 = new MultipleIEquatables {
                SomeProperty = 1
            };
            var obj3 = new EquatableObject {
                SomeProperty = 1
            };

            var n         = new TCLiteEqualityComparer();
            var tolerance = Tolerance.Exact;

            Assert.That(n.AreEqual(obj1, obj2, ref tolerance), Is.True);
            Assert.That(n.AreEqual(obj2, obj1, ref tolerance), Is.True);
            Assert.That(n.AreEqual(obj1, obj3, ref tolerance), Is.False);
            Assert.That(n.AreEqual(obj3, obj1, ref tolerance), Is.False);
            Assert.That(n.AreEqual(obj2, obj3, ref tolerance), Is.True);
            Assert.That(n.AreEqual(obj3, obj2, ref tolerance), Is.True);
        }