本文整理汇总了C#中Brunet.Util.MemBlock.GetHashCode方法的典型用法代码示例。如果您正苦于以下问题:C# MemBlock.GetHashCode方法的具体用法?C# MemBlock.GetHashCode怎么用?C# MemBlock.GetHashCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Brunet.Util.MemBlock
的用法示例。
在下文中一共展示了MemBlock.GetHashCode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test
public void Test() {
System.Random r = new System.Random();
byte[] data;
for(int i = 0; i < 100; i++) {
data = new byte[ r.Next(1024) ];
r.NextBytes(data);
int offset = r.Next(data.Length);
MemBlock mb1 = new MemBlock(data, 0, data.Length);
MemBlock mb1a = MemBlock.Copy(data, 0, data.Length);
Assert.IsTrue(mb1.Equals(mb1a), "MemBlock.Copy");
Assert.IsTrue(mb1.Equals(data), "MemBlock == byte[]");
MemBlock mb2 = new MemBlock(data, offset, data.Length - offset);
MemBlock mb2a = mb1.Slice(offset);
MemBlock mb3 = new MemBlock(data, 0, offset);
MemBlock mb3a = mb1.Slice(0, offset);
Assert.IsTrue(mb3.Equals( mb3a ), "mb3.Equals(mb3a)");
Assert.IsTrue(mb3a.Equals( mb3 ), "mb3a.Equals(mb3)");
Assert.IsTrue(mb3.CompareTo(mb2) + mb2.CompareTo(mb3) == 0, "CompareTo");
Assert.IsTrue(mb2.Equals( mb2a ), "mb2.Equals(mb2a)");
Assert.IsTrue(mb2a.Equals( mb2 ), "mb2a.Equals(mb2)");
MemBlock cat = MemBlock.Concat(mb3, mb2);
MemBlock cata = MemBlock.Concat(mb3a, mb2a);
Assert.IsTrue(cat.Equals(cata), "Concat Equals");
Assert.IsTrue(cata.Equals(cat), "Concat a Equals");
Assert.IsTrue(mb1.Equals(cat), "Concat Equals Original");
if( offset != 0 ) {
//These should not be equal
Assert.IsFalse(mb2.Equals(mb1), "mb2 != mb1");
}
int mb2a_l = mb2a.Length;
byte[] tmp_data = new byte[mb2a_l];
mb2a.CopyTo(tmp_data, 0);
MemBlock mb2b = new MemBlock(tmp_data, 0, tmp_data.Length);
Assert.IsTrue(mb2a.Equals(mb2b), "mb2a.Equals(mb2b)");
Assert.IsTrue(mb2b.Equals(mb2a), "mb2b.Equals(mb2a)");
//Check the Hash:
Assert.IsTrue(mb2b.GetHashCode() == mb2a.GetHashCode(), "GetHashCode");
//Here are some manual equality testing using the indexer
bool all_equals = true;
int j = 0;
while( all_equals && (j < mb1.Length) ) {
all_equals = (mb1[ j ] == cat[ j ]);
j++;
}
Assert.IsTrue(all_equals, "Manual equality test mb1");
all_equals = true;
j = 0;
while( all_equals && (j < mb2.Length) ) {
all_equals = (mb2[ j ] == mb2a[ j ]);
j++;
}
Assert.IsTrue(all_equals, "Manual equality test mb2");
all_equals = true;
j = 0;
while( all_equals && (j < mb2.Length) ) {
all_equals = (mb2[ j ] == mb2b[ j ]);
j++;
}
Assert.IsTrue(all_equals, "Manual equality test mb2b");
}
}