public void TestEquatable() { BinaryValue less = new BinaryValue(BitConverter.GetBytes(1)); BinaryValue same = new BinaryValue(BitConverter.GetBytes(1)); BinaryValue greater = new BinaryValue(BitConverter.GetBytes(2)); Assert.AreEqual <int>(less.GetHashCode(), same.GetHashCode()); Assert.IsFalse(less.Equals(greater)); Assert.IsTrue(less.Equals(same)); Assert.IsFalse(greater.Equals(less)); Assert.IsFalse(less.Equals((object)greater)); Assert.IsTrue(less.Equals((object)same)); Assert.IsFalse(greater.Equals((object)less)); }
public void TestHashcode() { string[] testStrings = { "", "A", "One", "D'oh", "Duff", "pneumonoultramicroscopicsilicovolcanoconiosis" }; foreach (string test in testStrings) { BinaryValue target = new BinaryValue(Encoding.UTF8.GetBytes(test)); BinaryValue same = new BinaryValue(Encoding.UTF8.GetBytes(test)); BinaryValue different = new BinaryValue(Encoding.UTF8.GetBytes(test + "different")); Assert.AreEqual <int>(target.GetHashCode(), same.GetHashCode()); Assert.IsTrue(target.Equals(same)); if (target.GetHashCode() != different.GetHashCode()) { Assert.IsFalse(target.Equals(different)); } } }
public void EmptyBufferHashcode() { BinaryValue target = new BinaryValue(new byte[0]); Assert.AreEqual <int>(0, target.GetHashCode()); }