public AreEqual ( object x, object y, NUnit.Framework.Constraints.Tolerance &tolerance ) : bool | ||
x | object | |
y | object | |
tolerance | NUnit.Framework.Constraints.Tolerance | |
Résultat | bool |
public void CanCompareArrayContainingSelfToSelf() { object[] array = new object[1]; array[0] = array; Assert.True(comparer.AreEqual(array, array, ref tolerance)); }
public void ImplementingIEquatableDirectlyOnTheClass() { var obj1 = new EquatableObject { SomeProperty = 1 }; var obj2 = new EquatableObject { SomeProperty = 1 }; var n = new NUnitEqualityComparer(); 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 NUnitEqualityComparer(); 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 NUnitEqualityComparer(); var tolerance = Tolerance.Default; equalityComparer.ExternalComparers.Add(new DetectRecursionComparer(30)); Assert.DoesNotThrow(() => equalityComparer.AreEqual(x, y, ref tolerance)); }
public void TestToleranceDefault() { var defaultTolerance = Tolerance.Default; Assert.IsTrue(defaultTolerance.IsUnsetOrDefault); var comparer = new NUnitEqualityComparer(); Assert.IsTrue(comparer.AreEqual(2.0d, 2.1d, ref defaultTolerance)); }
public void TestToleranceExact() { var noneTolerance = Tolerance.Exact; Assert.IsFalse(noneTolerance.IsUnsetOrDefault); var comparer = new NUnitEqualityComparer(); Assert.IsFalse(comparer.AreEqual(2.0d, 2.1d, ref noneTolerance)); }
public void SelfContainedDuplicateItemsAreCompared() { var equalityComparer = new NUnitEqualityComparer(); var equalInstance1 = new[] { 1 }; var equalInstance2 = new[] { 1 }; var x = new[] { equalInstance1, equalInstance1 }; var y = new[] { equalInstance2, equalInstance2 }; Assert.True(equalityComparer.AreEqual(x, y, ref tolerance)); }
public void SelfContainedItemFoundInCollection <T>(T x, ICollection y) { var equalityComparer = new NUnitEqualityComparer(); var tolerance = Tolerance.Default; var equality = equalityComparer.AreEqual(x, y, ref tolerance); Assert.IsFalse(equality); Assert.Contains(x, y); Assert.That(y, Contains.Item(x)); 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 }; Assert.That(obj1, Is.EqualTo(obj2)); Assert.That(obj1, Is.Not.EqualTo(obj3)); Assert.That(obj1, Is.Not.EqualTo(obj4)); var n = new NUnitEqualityComparer(); 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); }
/// <summary> /// Test whether item is present in expected collection /// </summary> /// <typeparam name="TActual">Actual item type</typeparam> /// <param name="actual">Actual item</param> public override ConstraintResult ApplyTo <TActual>(TActual actual) { var tolerance = Tolerance.Default; foreach (var item in _expected) { if (_comparer.AreEqual(actual, item, ref tolerance)) { return(new ConstraintResult(this, actual, ConstraintStatus.Success)); } } return(new ConstraintResult(this, actual, ConstraintStatus.Failure)); }
public void CanHandleMultipleImplementationsOfIEquatable() { IEquatableObject obj1 = new InheritedEquatableObject { SomeProperty = 1 }; IEquatableObject obj2 = new MultipleIEquatables { SomeProperty = 1 }; var obj3 = new EquatableObject { SomeProperty = 1 }; var n = new NUnitEqualityComparer(); 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.Zero; return(comparer.AreEqual(expected, actual, ref tolerance)); }
public void EqualItems(object x, object 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> public override bool Matches(object actual) { this.actual = actual; return(comparer.AreEqual(expected, actual, 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> public override ConstraintResult ApplyTo <TActual>(TActual actual) { return(new EqualConstraintResult(this, actual, comparer.AreEqual(expected, actual, ref tolerance))); }
public override bool Equals(object x, object y) { return(_comparer.AreEqual(x, y, ref _tolerance)); }
/// <summary> /// Compares two collection members for equality /// </summary> protected bool ItemsEqual(object x, object y) { Tolerance tolerance = Tolerance.Default; return(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> public override ConstraintResult ApplyTo <TActual>(TActual actual) { AdjustArgumentIfNeeded(ref actual); return(new EqualConstraintResult(this, actual, _comparer.AreEqual(_expected, actual, ref _tolerance))); }