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 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 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)); }
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)); }
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 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); }
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); }
private bool ItemsEqual(object expected, object actual) { Tolerance tolerance = Tolerance.Default; return(_comparer.AreEqual(expected, actual, ref tolerance)); }
// [TestCase((char)4, 4)] // [TestCase(4, (char)4)] public void EqualItems <T, U>(T x, U y) { Assert.That(comparer.AreEqual(x, y, ref tolerance)); }
/// <summary> /// Test whether the constraint is satisfied by a given value /// </summary> /// <param name="actual">The value to be tested</param> /// <returns>True for success, false for failure</returns> protected override ConstraintResult ApplyConstraint <T>(T actual) { return(new EqualConstraintResult <TExpected>(this, actual, _comparer.AreEqual(ExpectedValue, actual, ref _tolerance))); }
/// <summary> /// Compares two collection members for equality /// </summary> protected bool ItemsEqual(object x, object y) { Tolerance tolerance = Tolerance.Exact; return(_comparer.AreEqual(x, y, ref tolerance)); }