Created
May 27, 2014 04:32
-
-
Save JayBazuzi/ffb7daa9450b2a647302 to your computer and use it in GitHub Desktop.
Asserts that this type correctly implements "value" equality semantics.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static class ValueTypeAssertions | |
{ | |
class C | |
{ | |
} | |
/// <summary> | |
/// Asserts that this type correctly implements "value" equality semantics. | |
/// </summary> | |
/// <param name="a">An example of T</param> | |
/// <param name="aPrime">Another T which should be the "same" as a</param> | |
/// <param name="b">Another T which should be different from a</param> | |
public static void HasValueEquality<T>(T a, T aPrime, T b) | |
{ | |
Assert.IsTrue(a.Equals(aPrime)); | |
Assert.IsTrue(a.GetHashCode().Equals(aPrime.GetHashCode())); | |
Assert.IsFalse(a.Equals(b)); | |
Assert.IsFalse(a.GetHashCode().Equals(b.GetHashCode())); | |
Assert.IsFalse(a.Equals(null)); | |
Assert.IsFalse(a.Equals(new C())); | |
Assert.AreEqual(a, aPrime); | |
Assert.AreNotEqual(a, b); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@bgeihsgt and @dennisdoomen: Here's another iteration. I split out equality from inequality, so you can deal with case-insensitive stuff:
https://gist.github.com/JayBazuzi/74e5fc153c44b550e956