public void SelectWithNullLambdaThrows() { var array = ArrayEx.Create(10, i => i + 1); Assert.That(() => array.Select <int, byte>(null), Throws.InstanceOf <ArgumentNullException>()); }
public void ResizeWithSameLengthProducesIdenticalArray() { var array = ArrayEx.Create(10, i => i + 1); var resizedArray = array.Resize(array.Length); Assert.That(resizedArray.Length, Is.EqualTo(array.Length)); Assert.That(resizedArray, Is.EqualTo(array)); }
public void SelectIntArrayToByteArray() { var array = ArrayEx.Create(10, i => i + 1); var newArray = array.Select(i => (byte)i); byte[] expected = ArrayEx.Create(10, i => (byte)(i + 1)); Assert.That(newArray, Is.EqualTo(expected)); }
public void ReadFullyProducesExpectedByteArray() { var bytes = ArrayEx.Create(8192, i => (byte)(i % 255)); using (var stream = new MemoryStream(bytes)) { var readBytes = stream.ReadFully(); Assert.That(readBytes, Is.EqualTo(bytes)); } }
public void CreateEmptyArrayWithNullLambda() { var array = ArrayEx.Create <int>(5); Assert.That(array.Length, Is.EqualTo(5)); for (int i = 0; i < array.Length; i++) { Assert.That(array[i], Is.EqualTo(0)); } }
public void ResizeWithSmallerLengthTruncates() { var array = ArrayEx.Create(10, i => i + 1); var resizedArray = array.Resize(array.Length / 2); Assert.That(resizedArray.Length, Is.LessThan(array.Length)); for (int i = 0; i < resizedArray.Length; i++) { Assert.That(resizedArray[i], Is.EqualTo(array[i])); } }
public void CreateSimpleArray() { var array = ArrayEx.Create <int>(5, i => i + 1); Assert.That(array.Length, Is.EqualTo(5)); int[] expected = { 1, 2, 3, 4, 5 }; for (int i = 0; i < array.Length; i++) { Assert.That(array[i], Is.EqualTo(expected[i])); } }
public void ResizeWithLargerLengthGrows() { var array = ArrayEx.Create(10, i => i + 1); var resizedArray = array.Resize(array.Length * 2); Assert.That(resizedArray.Length, Is.GreaterThan(array.Length)); for (int i = 0; i < array.Length; i++) { Assert.That(resizedArray[i], Is.EqualTo(array[i])); } for (int i = array.Length; i < resizedArray.Length; i++) { Assert.That(resizedArray[i], Is.EqualTo(0)); } }
public void NextByteWorksAsExpectedFromDifferentIndex() { var bytes = ArrayEx.Create(1024, i => (byte)(i % 255)); var reader = new MemoryReader(bytes, 512); for (int i = 512; i < bytes.Length; i++) { var b = reader.NextByte(); Assert.That(b, Is.EqualTo(bytes[i])); } Assert.That(reader.Address, Is.EqualTo(reader.Size)); Assert.That(() => reader.NextByte(), Throws.InstanceOf <InvalidOperationException>()); }
public void CreateWithLengthLessThanZeroThrows() { Assert.That(() => ArrayEx.Create <int>(-1), Throws.InstanceOf <ArgumentOutOfRangeException>()); }