public void Equals_NullableInt() { var comparer = new NullableIntComparer(); EqualityAssert.Equals(null, null, comparer); EqualityAssert.NotEquals(null, 4, comparer); EqualityAssert.NotEquals(4, null, comparer); EqualityAssert.Equals(4, 4, comparer); EqualityAssert.NotEquals(4, 7, comparer); }
public void Compare_NullableInt() { var comparer = new NullableIntComparer(); CompareAssert.IsEqualTo(null, null, comparer); CompareAssert.IsLessThan(null, 4, comparer); CompareAssert.IsGreaterThan(4, null, comparer); CompareAssert.IsEqualTo(4, 4, comparer); CompareAssert.IsLessThan(4, 7, comparer); CompareAssert.IsGreaterThan(4, 2, comparer); }
public void GetHashCode_NullableInt() { var comparer = new NullableIntComparer(); Assert.AreEqual(0, comparer.GetHashCode(null)); var anyNonZero = new int?[] { 3, 7, 12, 45 } .Select(comparer.GetHashCode) .Any(hc => hc != 0); Assert.IsTrue(anyNonZero, allHashCodesZero); }
public void GetHashCode_NullableInt_NonGeneric() { IEqualityComparer comparer = new NullableIntComparer(); Assert.AreEqual(0, comparer.GetHashCode(null)); var anyNonZero = new int?[] { 3, 7, 12, 45 } .Select(x => comparer.GetHashCode(x)) .Any(hc => hc != 0); Assert.IsTrue(anyNonZero, allHashCodesZero); ExceptionAssert.Throws <ArgumentException>(() => comparer.GetHashCode("abc")); }
public void Equals_NullableInt_NonGeneric() { IEqualityComparer comparer = new NullableIntComparer(); Assert.IsTrue(comparer.Equals(null, null)); Assert.IsFalse(comparer.Equals(null, 4)); Assert.IsFalse(comparer.Equals(4, null)); Assert.IsTrue(comparer.Equals(4, 4)); Assert.IsFalse(comparer.Equals(4, 7)); ExceptionAssert.Throws <ArgumentException>(() => comparer.Equals(null, "abc")); ExceptionAssert.Throws <ArgumentException>(() => comparer.Equals("abc", null)); ExceptionAssert.Throws <ArgumentException>(() => comparer.Equals("abc", "abc")); ExceptionAssert.Throws <ArgumentException>(() => comparer.Equals("abc", "xyz")); }
public void Compare_NullableInt_NonGeneric() { IComparer comparer = new NullableIntComparer(); Assert.AreEqual(0, Math.Sign(comparer.Compare(null, null))); Assert.AreEqual(-1, Math.Sign(comparer.Compare(null, 4))); Assert.AreEqual(1, Math.Sign(comparer.Compare(4, null))); Assert.AreEqual(0, Math.Sign(comparer.Compare(4, 4))); Assert.AreEqual(-1, Math.Sign(comparer.Compare(4, 7))); Assert.AreEqual(1, Math.Sign(comparer.Compare(4, 2))); ExceptionAssert.Throws <ArgumentException>(() => comparer.Compare(null, "abc")); ExceptionAssert.Throws <ArgumentException>(() => comparer.Compare("abc", null)); ExceptionAssert.Throws <ArgumentException>(() => comparer.Compare("abc", "abc")); ExceptionAssert.Throws <ArgumentException>(() => comparer.Compare("abc", "xyz")); }