Skip to content

Commit

Permalink
Add StreamWriter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adamreeve committed Apr 15, 2024
1 parent 500101c commit bed8aa8
Showing 1 changed file with 38 additions and 8 deletions.
46 changes: 38 additions & 8 deletions csharp/test/Apache.Arrow.Tests/ArrowStreamWriterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,37 @@ public async Task WriteBatchWithNullsAsync()
await TestRoundTripRecordBatchAsync(originalBatch);
}

private static void TestRoundTripRecordBatches(List<RecordBatch> originalBatches, IpcOptions options = null)
[Theory]
[InlineData(0, 45)]
[InlineData(3, 45)]
[InlineData(16, 45)]
public void WriteSlicedArrays(int sliceOffset, int sliceLength)
{
var originalBatch = TestData.CreateSampleRecordBatch(length: 100);
var slicedArrays = originalBatch.Arrays
.Select(array => ArrowArrayFactory.Slice(array, sliceOffset, sliceLength))
.ToList();
var slicedBatch = new RecordBatch(originalBatch.Schema, slicedArrays, sliceLength);

TestRoundTripRecordBatch(slicedBatch, strictCompare: false);
}

[Theory]
[InlineData(0, 45)]
[InlineData(3, 45)]
[InlineData(16, 45)]
public async Task WriteSlicedArraysAsync(int sliceOffset, int sliceLength)
{
var originalBatch = TestData.CreateSampleRecordBatch(length: 100);
var slicedArrays = originalBatch.Arrays
.Select(array => ArrowArrayFactory.Slice(array, sliceOffset, sliceLength))
.ToList();
var slicedBatch = new RecordBatch(originalBatch.Schema, slicedArrays, sliceLength);

await TestRoundTripRecordBatchAsync(slicedBatch, strictCompare: false);
}

private static void TestRoundTripRecordBatches(List<RecordBatch> originalBatches, IpcOptions options = null, bool strictCompare = true)
{
using (MemoryStream stream = new MemoryStream())
{
Expand All @@ -223,13 +253,13 @@ private static void TestRoundTripRecordBatches(List<RecordBatch> originalBatches
foreach (RecordBatch originalBatch in originalBatches)
{
RecordBatch newBatch = reader.ReadNextRecordBatch();
ArrowReaderVerifier.CompareBatches(originalBatch, newBatch);
ArrowReaderVerifier.CompareBatches(originalBatch, newBatch, strictCompare: strictCompare);
}
}
}
}

private static async Task TestRoundTripRecordBatchesAsync(List<RecordBatch> originalBatches, IpcOptions options = null)
private static async Task TestRoundTripRecordBatchesAsync(List<RecordBatch> originalBatches, IpcOptions options = null, bool strictCompare = true)
{
using (MemoryStream stream = new MemoryStream())
{
Expand All @@ -249,20 +279,20 @@ private static async Task TestRoundTripRecordBatchesAsync(List<RecordBatch> orig
foreach (RecordBatch originalBatch in originalBatches)
{
RecordBatch newBatch = reader.ReadNextRecordBatch();
ArrowReaderVerifier.CompareBatches(originalBatch, newBatch);
ArrowReaderVerifier.CompareBatches(originalBatch, newBatch, strictCompare: strictCompare);
}
}
}
}

private static void TestRoundTripRecordBatch(RecordBatch originalBatch, IpcOptions options = null)
private static void TestRoundTripRecordBatch(RecordBatch originalBatch, IpcOptions options = null, bool strictCompare = true)
{
TestRoundTripRecordBatches(new List<RecordBatch> { originalBatch }, options);
TestRoundTripRecordBatches(new List<RecordBatch> { originalBatch }, options, strictCompare: strictCompare);
}

private static async Task TestRoundTripRecordBatchAsync(RecordBatch originalBatch, IpcOptions options = null)
private static async Task TestRoundTripRecordBatchAsync(RecordBatch originalBatch, IpcOptions options = null, bool strictCompare = true)
{
await TestRoundTripRecordBatchesAsync(new List<RecordBatch> { originalBatch }, options);
await TestRoundTripRecordBatchesAsync(new List<RecordBatch> { originalBatch }, options, strictCompare: strictCompare);
}

[Fact]
Expand Down

0 comments on commit bed8aa8

Please sign in to comment.