Skip to content

Commit

Permalink
Fix tests for BlockBuilder.appendStructure()
Browse files Browse the repository at this point in the history
This is done via using different ways to copy the block in
AbstractTestBlock.

Tests for appendStructure() is missed in
2ccfa9b.
  • Loading branch information
wenleix committed Apr 20, 2018
1 parent 6088cac commit 4e881c8
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ protected <T> void assertBlock(Block block, Supplier<BlockBuilder> newBlockBuild
{
assertBlockPositions(block, newBlockBuilder, expectedValues);
assertBlockPositions(copyBlockViaBlockSerde(block), newBlockBuilder, expectedValues);
assertBlockPositions(copyBlockViaWritePositionTo(block, newBlockBuilder), newBlockBuilder, expectedValues);
if (expectedValues.getClass().getComponentType().isArray() ||
expectedValues.getClass().getComponentType() == List.class ||
expectedValues.getClass().getComponentType() == Map.class) {
assertBlockPositions(copyBlockViaWritePositionTo(block, newBlockBuilder), newBlockBuilder, expectedValues);
assertBlockPositions(copyBlockViaWriteStructure(block, newBlockBuilder), newBlockBuilder, expectedValues);
}

assertBlockSize(block);
Expand Down Expand Up @@ -169,7 +170,7 @@ private <T> void assertBlockPositions(Block block, Supplier<BlockBuilder> newBlo
{
assertEquals(block.getPositionCount(), expectedValues.length);
for (int position = 0; position < block.getPositionCount(); position++) {
assertBlockPosition(block, newBlockBuilder, position, expectedValues[position]);
assertBlockPosition(block, newBlockBuilder, position, expectedValues[position], expectedValues.getClass().getComponentType());
}
}

Expand Down Expand Up @@ -204,7 +205,8 @@ private void assertBlockSize(Block block)
assertEquals(block.getRegionSizeInBytes(firstHalf.getPositionCount(), secondHalf.getPositionCount()), expectedSecondHalfSize);
}

protected <T> void assertBlockPosition(Block block, Supplier<BlockBuilder> newBlockBuilder, int position, T expectedValue)
// expectedValueType is required since otherwise the expected value type is unknown when expectedValue is null.
protected <T> void assertBlockPosition(Block block, Supplier<BlockBuilder> newBlockBuilder, int position, T expectedValue, Class<?> expectedValueType)
{
assertPositionValue(block, position, expectedValue);
assertPositionValue(block.getSingleValueBlock(position), 0, expectedValue);
Expand All @@ -221,6 +223,12 @@ protected <T> void assertBlockPosition(Block block, Supplier<BlockBuilder> newBl
assertPositionValue(copyBlockViaWritePositionTo(block.getRegion(0, position + 1), newBlockBuilder), position, expectedValue);
assertPositionValue(copyBlockViaWritePositionTo(block.getRegion(position, block.getPositionCount() - position), newBlockBuilder), 0, expectedValue);

if (expectedValueType.isArray() || expectedValueType == List.class || expectedValueType == Map.class) {
assertPositionValue(copyBlockViaWriteStructure(block.getRegion(position, 1), newBlockBuilder), 0, expectedValue);
assertPositionValue(copyBlockViaWriteStructure(block.getRegion(0, position + 1), newBlockBuilder), position, expectedValue);
assertPositionValue(copyBlockViaWriteStructure(block.getRegion(position, block.getPositionCount() - position), newBlockBuilder), 0, expectedValue);
}

assertPositionValue(block.copyRegion(position, 1), 0, expectedValue);
assertPositionValue(block.copyRegion(0, position + 1), position, expectedValue);
assertPositionValue(block.copyRegion(position, block.getPositionCount() - position), 0, expectedValue);
Expand Down

0 comments on commit 4e881c8

Please sign in to comment.