public bool PosTest1() { bool retVal = true; TestFramework.BeginScenario("PosTest1: RuntimeHelpers.GetHashCode() on two non-reference-equals objects returns non-equal codes"); Object a, b; try { a = new ClassWithEquivalence(10, 20); b = new ClassWithEquivalence(10, 20); if (!(a.Equals(b) && (a.GetHashCode() == b.GetHashCode())) || (Object.ReferenceEquals(a, b))) { // Log: setup failed return(false); } if (RuntimeHelpers.GetHashCode(a) == RuntimeHelpers.GetHashCode(b)) { // Log: RTH.GHC should have returned different hash codes since the // objects are not reference-equals. TestFramework.LogError("001", "a and b are not reference equal, and yet RuntimeHelpers.GetHashCode returned same value for each"); retVal = false; } } catch (Exception e) { TestFramework.LogError("002", "Unexpected exception: " + e); retVal = false; } return(retVal); }
public bool PosTest1() { bool retVal = true; TestFramework.BeginScenario("PosTest1: RuntimeHelpers.GetHashCode() on two non-reference-equals objects returns non-equal codes"); Object a, b; try { a = new ClassWithEquivalence(10, 20); b = new ClassWithEquivalence(10, 20); if (!(a.Equals(b) && (a.GetHashCode() == b.GetHashCode())) || (Object.ReferenceEquals(a, b))) { // Log: setup failed return false; } if (RuntimeHelpers.GetHashCode(a) == RuntimeHelpers.GetHashCode(b)) { // Log: RTH.GHC should have returned different hash codes since the // objects are not reference-equals. TestFramework.LogError("001", "a and b are not reference equal, and yet RuntimeHelpers.GetHashCode returned same value for each"); retVal = false; } } catch (Exception e) { TestFramework.LogError("002", "Unexpected exception: " + e); retVal = false; } return retVal; }
public override bool Equals(object b) { ClassWithEquivalence bProper = b as ClassWithEquivalence; if (bProper != null) { return((x == bProper.x) && (y == bProper.y)); } else { return(false); } }