public void Creation() { var data = new ReadonlyBytes(new byte[] { 1, 2, 3 }); Assert.AreEqual(3, data.Length); Assert.AreEqual(1, data[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]); }
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()); } }
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 }
public void IndexOutOfRangeException() { var items = new ReadonlyBytes(4, 1, 2); // Обращение к индексу за границами исходного массива должно приводить // к исключению типа IndexOutOfRangeException Assert.Throws <IndexOutOfRangeException>(() => { var z = items[100500]; }); }
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); }
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); }
private bool Equals(ReadonlyBytes other) { var isItemsEqual = true; var count = 0; while (isItemsEqual && count < Length) { isItemsEqual = this[count] == other[count]; ++count; } return(isItemsEqual); }
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()); }
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); }
public void Length() { var items = new ReadonlyBytes(1, 2, 3); Assert.AreEqual(3, items.Length); }
protected bool Equals(ReadonlyBytes other) { return(Equals(bytes, other.bytes)); }