Skip to content

Commit

Permalink
should have resolved the issues with GetBatches. Added additional ass…
Browse files Browse the repository at this point in the history
…ert in TestGetBatches to discover missing bytes
  • Loading branch information
scbedd committed Feb 15, 2023
1 parent ffd48ea commit 6e2d8d5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in volup

[Theory]
[InlineData("", 1)]
[InlineData("small body", 10)]
[InlineData("small body", 5)]
[InlineData("this is a body", 3)]
[InlineData("This is a little bit longer of a body that we are dividing in 2", 2)]
[InlineData(longBody, 5)]
Expand All @@ -803,16 +803,20 @@ public void TestGetBatches(string input, int batchCount)
var chunks = testRecordingHandler.GetBatches(bodyData, batchCount);

int bodyPosition = 0;
int byteCount = 0;

// ensure that all bytes are accounted for across the batches
foreach(var chunk in chunks)
{
for (int j = 0; j < chunk.Length; j++)
for (int j = 0; j < chunk.Length && bodyPosition < bodyData.Length; j++)
{
Assert.Equal(chunk[j], bodyData[bodyPosition]);
bodyPosition++;
byteCount++;
}
}

Assert.Equal(byteCount, bodyData.Length);
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,13 +484,12 @@ public byte[][] GetBatches(byte[] bodyData, int batchCount)

int chunkLength = bodyData.Length / batchCount;
int remainder = (bodyData.Length % batchCount);
var batches = new byte[batchCount + remainder > 0 ? 1 : 0][];
var batches = new byte[batchCount + (remainder > 0 ? 1 : 0)][];

for(int i = 0; i < batches.Length; i++)
{
var batch = new byte[chunkLength];

Array.Copy(bodyData, i * chunkLength, batch, 0, chunkLength);
Array.Copy(bodyData, i * chunkLength, batch, 0, i == batches.Length - 1 && batches.Length > 1 && remainder > 0 ? remainder : chunkLength);

batches[i] = batch;
}
Expand Down

0 comments on commit 6e2d8d5

Please sign in to comment.