Exemple #1
0
        public void SelectWithNullLambdaThrows()
        {
            var array = ArrayEx.Create(10, i => i + 1);

            Assert.That(() =>
                        array.Select <int, byte>(null),
                        Throws.InstanceOf <ArgumentNullException>());
        }
Exemple #2
0
        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));
        }
Exemple #3
0
        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));
            }
        }
Exemple #5
0
        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));
            }
        }
Exemple #6
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]));
            }
        }
Exemple #7
0
        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]));
            }
        }
Exemple #8
0
        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));
            }
        }
Exemple #9
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>());
        }
Exemple #10
0
 public void CreateWithLengthLessThanZeroThrows()
 {
     Assert.That(() =>
                 ArrayEx.Create <int>(-1),
                 Throws.InstanceOf <ArgumentOutOfRangeException>());
 }