Ejemplo n.º 1
0
        public void MassiveCallToGetHashCodeOfLargeBytesArray()
        {
            var items = new ReadonlyBytes(Enumerable.Repeat((byte)6, 100000).ToArray());
            var hash  = items.GetHashCode();

            for (int i = 0; i < 100000; i++)
            {
                Assert.AreEqual(hash, items.GetHashCode());
            }
        }
Ejemplo n.º 2
0
        public void EqualityAndHashCode()
        {
            var data1 = new ReadonlyBytes(new byte[] { 1, 2, 3 });
            var data2 = new ReadonlyBytes(new byte[] { 1, 2, 3 });
            var data3 = new ReadonlyBytes(new byte[] { 1, 2, 3, 4 });

            Assert.AreEqual(data1.GetHashCode(), data2.GetHashCode());
            Assert.AreNotEqual(data1.GetHashCode(), data3.GetHashCode());
            Assert.AreEqual(data1, data2);
            Assert.AreNotEqual(data1, data3);
            Assert.AreNotEqual(data2, data3);
        }
Ejemplo n.º 3
0
        public void HashCode()
        {
            Assert.AreEqual(new ReadonlyBytes().GetHashCode(), new ReadonlyBytes().GetHashCode());
            Assert.AreEqual(new ReadonlyBytes(1, 2, 3).GetHashCode(), new ReadonlyBytes(1, 2, 3).GetHashCode());
            Assert.AreNotEqual(new ReadonlyBytes(1, 2, 3).GetHashCode(), new ReadonlyBytes(1, 2, 3, 4).GetHashCode());
            Assert.AreNotEqual(new ReadonlyBytes(1, 2, 3).GetHashCode(), new ReadonlyBytes(1, 2, 4).GetHashCode());
            Assert.AreNotEqual(new ReadonlyBytes(1, 2, 3).GetHashCode(), new ReadonlyBytes(1, 2).GetHashCode());
            Assert.AreNotEqual(new ReadonlyBytes(1, 2, 3).GetHashCode(), new ReadonlyBytes(3, 2, 1).GetHashCode());
            Assert.AreNotEqual(new ReadonlyBytes(1, 0).GetHashCode(), new ReadonlyBytes(0, 31).GetHashCode());

            var items = new ReadonlyBytes(4, 2, 67, 1);

            Assert.AreEqual(items.GetHashCode(), items.GetHashCode());
        }