public void ToArray()
        {
            //Arrange
            var numberOfValuesPerPopulatingArrays = new int[] { 1000, 20, 1234, 100000 };
            var arrays = new List <decimal[]>();

            for (var i = 0; i < numberOfValuesPerPopulatingArrays.Length; i++)
            {
                var    number  = numberOfValuesPerPopulatingArrays[i];
                Random randNum = new Random(number + DateTime.Now.Millisecond);
                arrays.Add(Enumerable
                           .Repeat(0, number)
                           .Select(j => (decimal)randNum.Next(0, 10000000))
                           .ToArray());
            }
            var expectedResult = arrays.SelectMany(arr => arr).ToArray();

            //Action
            var builder = new StructArrayBuilder <decimal>();

            for (var i = 0; i < arrays.Count; i++)
            {
                var arr = arrays[i];
                builder.Append(arr);
            }
            var result = builder.ToArray();

            //Assert
            Assert.NotNull(result);
            Assert.Equal(expectedResult.Length, result.Length);
            Assert.Equal(expectedResult, result);

            Console.WriteLine("Ran StructArrayBuilder_Tests.ToArray");
        }
Beispiel #2
0
        public NonContiguousMemoryStream(byte[] buffer, bool writable)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }

            _buffer   = new StructArrayBuilder <byte>(buffer);
            _writable = writable;
            _isOpen   = true;
        }
Beispiel #3
0
        public NonContiguousMemoryStream(int capacity)
        {
            if (capacity < 0)
            {
                throw new ArgumentOutOfRangeException("capacity", "capacity cannot be negative");
            }

            _buffer   = new StructArrayBuilder <byte>(capacity);
            _writable = true;
            _isOpen   = true;
        }
        public TestState <decimal> Arrange_PrepArrayAndAppend(
            bool useSkipLists = true, int numValues = 10000, int chunkSize = 2000, int percentOfChunksToAction = 33)
        {
            //Arrange
            if (numValues < 5 * chunkSize)
            {
                chunkSize = numValues / 5;
            }
            var numberOfChunks = (int)(numValues / chunkSize);
            var numberOfValuesPerPopulatingArrays = Enumerable.Repeat(0, numberOfChunks).Select(n => chunkSize).ToArray();
            var arrays = new List <decimal[]>();

            for (var i = 0; i < numberOfValuesPerPopulatingArrays.Length; i++)
            {
                var    number  = numberOfValuesPerPopulatingArrays[i];
                Random randNum = new Random(number + DateTime.Now.Millisecond);
                arrays.Add(Enumerable
                           .Repeat(0, number)
                           .Select(j => (decimal)randNum.Next(0, 10000000))
                           .ToArray());
            }
            var expectedResult = arrays.SelectMany(arr => arr).ToArray();

            //Action
            var builder = new StructArrayBuilder <decimal>(useSkipLists);

            for (var i = 0; i < arrays.Count; i++)
            {
                var arr = arrays[i];
                builder.Append(arr);
            }

            return(new TestState <decimal>()
            {
                Builder = builder,
                ExpectedResult = expectedResult,
                NumberofChunksToAction = (int)(percentOfChunksToAction * numberOfChunks / 100)
            });
        }
Beispiel #5
0
        public NonContiguousMemoryStream(byte[] buffer, int index, int count, bool writable, bool publiclyVisible)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }
            if (index < 0)
            {
                throw new ArgumentOutOfRangeException("index", "index cannot be negative");
            }
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException("count", "count cannot be negative");
            }
            if (buffer.Length - index < count)
            {
                throw new ArgumentException("count and index define positions greater than buffer length");
            }

            _buffer   = new StructArrayBuilder <byte>(buffer, index, count, index + count);
            _position = index + count;
            _writable = writable;
            _isOpen   = true;
        }