public void DefaultComparerReturnsFalseIfObjectsAreNotSame() { var comparer = ObjectReferenceComparer <ObjRefComparerTestStub> .Default; var x = new ObjRefComparerTestStub(1); var y = new ObjRefComparerTestStub(2); bool result = comparer.Equals(x, y); Assert.IsFalse(result); }
public void DefaultComparerReturnsTrueIfOjectsAreSameInstance() { var comparer = ObjectReferenceComparer <ObjRefComparerTestStub> .Default; var x = new ObjRefComparerTestStub(1); var y = x; bool result = comparer.Equals(x, y); Assert.IsTrue(result); }
public void ComparerReturnsFalseIfObjectsAreNotSameInstanceIgnoringEquatableImplementation() { var comparer = new ObjectReferenceComparer <ObjRefComparerTestStub>(); var x = new ObjRefComparerTestStub(1); var y = new ObjRefComparerTestStub(1); bool comparerResult = comparer.Equals(x, y); bool equalsResult = x.Equals(y); Assert.IsFalse(comparerResult); Assert.IsTrue(equalsResult); }
public void DefaultComparerReturnsFalseIfObjectsAreNotSameInstanceIgnoringEqualsOverride() { var comparer = ObjectReferenceComparer <ObjRefComparerTestStub> .Default; var x = new ObjRefComparerTestStub(1); var y = new ObjRefComparerTestStub(1); bool comparerResult = comparer.Equals(x, y); bool equalsResult = x.Equals((object)y); Assert.IsFalse(comparerResult); Assert.IsTrue(equalsResult); }
public void ObjectReferenceComparerGetHashCodeReturnsSameHashCodeForObject() { var comparer = ObjectReferenceComparer <IEquatable <ObjRefComparerTestStub> > .Default; IEquatable <ObjRefComparerTestStub> obj = new ObjRefComparerTestStub(2); //get the HashCode 2000 times to confirm it is consistent for lifetime of the object HashSet <int> hashes = new HashSet <int>(); for (int i = 0; i < 2000; i++) { hashes.Add(comparer.GetHashCode(obj)); } Assert.AreEqual(1, hashes.Count); }