public void Visit(BinaryType type) { BinaryArray.Builder resultBuilder = new BinaryArray.Builder().Reserve(_baseDataTotalElementCount); for (int i = 0; i < _baseDataListCount; i++) { List <int?> dataList = _baseData[i]; BinaryArray.Builder builder = new BinaryArray.Builder().Reserve(dataList.Count); foreach (byte?value in dataList) { if (value.HasValue) { builder.Append(value.Value); resultBuilder.Append(value.Value); } else { builder.AppendNull(); resultBuilder.AppendNull(); } } TestTargetArrayList.Add(builder.Build()); } ExpectedArray = resultBuilder.Build(); }
public void AppendThenBuild(byte[][] byteArrays) { // Arrange var builder = new BinaryArray.Builder(); foreach (var byteArray in byteArrays) { // Test the type of byte array to ensure each Append() overload is exercised. if (byteArray == null) { builder.AppendNull(); } else if (byteArray.Length == 1) { builder.Append(byteArray[0]); } else { builder.Append((ReadOnlySpan <byte>)byteArray); } } // Act var array = builder.Build(_allocator); // Assert AssertArrayContents(byteArrays, array); }
public void BuildImmediately() { // Arrange var builder = new BinaryArray.Builder(); // Act var array = builder.Build(_allocator); // Assert Assert.Equal(0, array.Length); }
public void BuildMultipleTimes(byte[][] byteArrays) { // Arrange var builder = new BinaryArray.Builder(); builder.AppendRange(byteArrays); builder.Build(_allocator); // Act var array = builder.Build(_allocator); // Assert AssertArrayContents(byteArrays, array); }
public void ThrowsWhenGetValueAndOffsetIndexOutOfBounds() { var array = new BinaryArray.Builder().Append(1).Append(2).Build(); Assert.Throws <ArgumentOutOfRangeException>(() => array.GetValueLength(-1)); Assert.Equal(1, array.GetValueLength(0)); Assert.Equal(1, array.GetValueLength(1)); Assert.Throws <ArgumentOutOfRangeException>(() => array.GetValueLength(2)); Assert.Throws <ArgumentOutOfRangeException>(() => array.GetValueOffset(-1)); Assert.Equal(0, array.GetValueOffset(0)); Assert.Equal(1, array.GetValueOffset(1)); Assert.Equal(2, array.GetValueOffset(2)); Assert.Throws <ArgumentOutOfRangeException>(() => array.GetValueOffset(3)); }
public void ClearEmpty() { // Arrange var builder = new BinaryArray.Builder(); // Act var actualReturnValue = builder.Clear(); // Assert Assert.NotNull(actualReturnValue); Assert.Equal(builder, actualReturnValue); Assert.Equal(0, builder.Length); var array = builder.Build(_allocator); Assert.Equal(0, array.Length); }
public void AppendRangeArraysAfterClear(byte[][] initialContents, byte[][] byteArrays) { // Arrange var builder = new BinaryArray.Builder(); if (initialContents.Length > 0) { builder.AppendRange(initialContents); } builder.Clear(); var expectedArrayContents = byteArrays; // Act var actualReturnValue = builder.AppendRange(byteArrays); // Assert Assert.Equal(builder, actualReturnValue); Assert.Equal(byteArrays.Length, builder.Length); var actualArray = builder.Build(_allocator); AssertArrayContents(expectedArrayContents, actualArray); }
public void AppendSingleByte(byte[][] initialContents, byte singleByte) { // Arrange var builder = new BinaryArray.Builder(); if (initialContents.Length > 0) { builder.AppendRange(initialContents); } int initialLength = builder.Length; int expectedLength = initialLength + 1; var expectedArrayContents = initialContents.Append(new[] { singleByte }); // Act var actualReturnValue = builder.Append(singleByte); // Assert Assert.Equal(builder, actualReturnValue); Assert.Equal(expectedLength, builder.Length); var actualArray = builder.Build(_allocator); AssertArrayContents(expectedArrayContents, actualArray); }
public void AppendRangeArrays(byte[][] initialContents, byte[][] byteArrays) { // Arrange var builder = new BinaryArray.Builder(); if (initialContents.Length > 0) { builder.AppendRange(initialContents); } int initialLength = builder.Length; int expectedNewLength = initialLength + byteArrays.Length; var expectedArrayContents = initialContents.Concat(byteArrays); // Act var actualReturnValue = builder.AppendRange(byteArrays); // Assert Assert.Equal(builder, actualReturnValue); Assert.Equal(expectedNewLength, builder.Length); var actualArray = builder.Build(_allocator); AssertArrayContents(expectedArrayContents, actualArray); }
public void AppendEnumerableAfterClear(byte[][] initialContents, byte[] bytes) { // Arrange var builder = new BinaryArray.Builder(); if (initialContents.Length > 0) { builder.AppendRange(initialContents); } builder.Clear(); var enumerable = (IEnumerable <byte>)bytes; var expectedArrayContents = new[] { bytes }; // Act var actualReturnValue = builder.Append(enumerable); // Assert Assert.Equal(builder, actualReturnValue); Assert.Equal(1, builder.Length); var actualArray = builder.Build(_allocator); AssertArrayContents(expectedArrayContents, actualArray); }
public void ThrowsWhenGetValueAndOffsetIndexOutOfBounds() { var array = new BinaryArray.Builder().Append(1).Append(2).Build(); Assert.Throws <ArgumentOutOfRangeException>(() => array.GetValueLength(-1)); Assert.Equal(1, array.GetValueLength(0)); Assert.Equal(1, array.GetValueLength(1)); Assert.Throws <ArgumentOutOfRangeException>(() => array.GetValueLength(2)); #pragma warning disable 618 Assert.Throws <ArgumentOutOfRangeException>(() => array.GetValueOffset(-1)); Assert.Equal(0, array.GetValueOffset(0)); Assert.Equal(1, array.GetValueOffset(1)); Assert.Equal(2, array.GetValueOffset(2)); Assert.Throws <ArgumentOutOfRangeException>(() => array.GetValueOffset(3)); #pragma warning restore 618 Assert.Throws <IndexOutOfRangeException>(() => array.ValueOffsets[-1]); Assert.Equal(0, array.ValueOffsets[0]); Assert.Equal(1, array.ValueOffsets[1]); Assert.Equal(2, array.ValueOffsets[2]); Assert.Throws <IndexOutOfRangeException>(() => array.ValueOffsets[3]); }
public void AppendReadOnlySpan(byte[][] initialContents, byte[] bytes) { // Arrange var builder = new BinaryArray.Builder(); if (initialContents.Length > 0) { builder.AppendRange(initialContents); } int initialLength = builder.Length; var span = (ReadOnlySpan <byte>)bytes; int expectedLength = initialLength + 1; var expectedArrayContents = initialContents.Append(bytes); // Act var actualReturnValue = builder.Append(span); // Assert Assert.Equal(builder, actualReturnValue); Assert.Equal(expectedLength, builder.Length); var actualArray = builder.Build(_allocator); AssertArrayContents(expectedArrayContents, actualArray); }
public void NewBatch() { _builder = new BinaryArray.Builder(); size = 0; }