Example #1
0
        public void Creation()
        {
            var data = new ReadonlyBytes(new byte[] { 1, 2, 3 });

            Assert.AreEqual(3, data.Length);
            Assert.AreEqual(1, data[0]);
        }
Example #2
0
        public void Indexer()
        {
            var items = new ReadonlyBytes(4, 1, 2);

            Assert.AreEqual(4, items[0]);
            Assert.AreEqual(1, items[1]);
            Assert.AreEqual(2, items[2]);
        }
Example #3
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());
            }
        }
Example #4
0
        public void EqualOnSameBytes()
        {
            // ReSharper disable EqualExpressionComparison
            Assert.IsTrue(new ReadonlyBytes(new byte[0]).Equals(new ReadonlyBytes(new byte[0])));
            Assert.IsTrue(new ReadonlyBytes(100).Equals(new ReadonlyBytes(100)));
            Assert.IsTrue(new ReadonlyBytes(1, 2, 3).Equals(new ReadonlyBytes(1, 2, 3)));
            var items = new ReadonlyBytes(4, 2, 67, 1);

            Assert.IsTrue(items.Equals(items));
            // ReSharper restore EqualExpressionComparison
        }
Example #5
0
        public void IndexOutOfRangeException()
        {
            var items = new ReadonlyBytes(4, 1, 2);

            // Обращение к индексу за границами исходного массива должно приводить
            // к исключению типа IndexOutOfRangeException
            Assert.Throws <IndexOutOfRangeException>(() =>
            {
                var z = items[100500];
            });
        }
Example #6
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);
        }
Example #7
0
        public void Enumeration()
        {
            var data = new ReadonlyBytes(1, 2, 3);

            var list = new List <byte>();

            foreach (var x in data)
            {
                list.Add(x);
            }

            Assert.AreEqual(new byte[] { 1, 2, 3 }, list);
        }
Example #8
0
        private bool Equals(ReadonlyBytes other)
        {
            var isItemsEqual = true;
            var count        = 0;

            while (isItemsEqual && count < Length)
            {
                isItemsEqual = this[count] == other[count];
                ++count;
            }

            return(isItemsEqual);
        }
Example #9
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());
        }
Example #10
0
 bool Equals(ReadonlyBytes other)
 {
     if (other == null || Length != other.Length)
     {
         return(false);
     }
     for (int i = 0; i < Length; i++)
     {
         if (this[i] != other[i])
         {
             return(false);
         }
     }
     return(true);
 }
Example #11
0
        public void Length()
        {
            var items = new ReadonlyBytes(1, 2, 3);

            Assert.AreEqual(3, items.Length);
        }
Example #12
0
 protected bool Equals(ReadonlyBytes other)
 {
     return(Equals(bytes, other.bytes));
 }