Skip to content

Commit

Permalink
Increase the test coverage further and while doing so understand the …
Browse files Browse the repository at this point in the history
…code better.
  • Loading branch information
joka921 committed Jan 11, 2024
1 parent 1f52072 commit a4cf4ac
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/util/JoinAlgorithms/JoinAlgorithms.h
Original file line number Diff line number Diff line change
Expand Up @@ -565,10 +565,6 @@ class BlockAndSubrange {
subrange_{0, block_->size()} {}

// Return a reference to the last element of the currently specified subrange.
reference back() {
AD_CORRECTNESS_CHECK(!empty() && subrange_.second <= block_->size());
return (*block_)[subrange_.second - 1];
}
const_reference back() const {
AD_CORRECTNESS_CHECK(!empty() && subrange_.second <= block_->size());
return std::as_const(*block_)[subrange_.second - 1];
Expand Down Expand Up @@ -826,9 +822,9 @@ struct BlockZipperJoinImpl {
// the last one, which might contain elements `> currentEl` at the end.
auto getEqualToCurrentEl(const auto& blocks, const auto& currentEl) {
auto result = blocks;
// If one of the inputs is empty, this function shouldn't have been called
// in the first place.
AD_CORRECTNESS_CHECK(!result.empty());
if (result.empty()) {
return result;
}
auto& last = result.back();
last.setSubrange(
std::ranges::equal_range(last.subrange(), currentEl, lessThan_));
Expand Down Expand Up @@ -973,19 +969,16 @@ struct BlockZipperJoinImpl {
while (!equalToCurrentElLeft.empty() && !equalToCurrentElRight.empty()) {
addAll<DoOptionalJoin>(equalToCurrentElLeft, equalToCurrentElRight);
switch (blockStatus.value()) {
case BlockStatus::allFilled: {
case BlockStatus::allFilled:
removeEqualToCurrentEl(sameBlocksLeft, currentEl);
removeEqualToCurrentEl(sameBlocksRight, currentEl);
return;
}
case BlockStatus::rightMissing: {
case BlockStatus::rightMissing:
getNextBlocks(equalToCurrentElRight, rightSide_);
continue;
}
case BlockStatus::leftMissing: {
case BlockStatus::leftMissing:
getNextBlocks(equalToCurrentElLeft, leftSide_);
continue;
}
default:
AD_FAIL();
}
Expand Down
10 changes: 10 additions & 0 deletions test/JoinAlgorithmsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,16 @@ TEST(JoinAlgorithms, JoinWithBlocksMoreThanThreeBlocksPerElement) {
testJoin(a, b, expectedResult);
}

// Test the coverage of a corner case.
TEST(JoinAlgorithms, JoinWithBlocksExactlyFourBlocksPerElement) {
NestedBlock a{{{42, 0}}, {{42, 1}}, {{42, 2}}, {{42, 3}},
{}, {{48, 5}, {67, 0}}, {{96, 32}}, {{96, 33}}};
NestedBlock b{{{42, 12}, {67, 13}}};
JoinResult expectedResult{
{42, 0, 12}, {42, 1, 12}, {42, 2, 12}, {42, 3, 12}, {67, 0, 13}};
testJoin(a, b, expectedResult);
}

// ________________________________________________________________________________________
TEST(JoinAlgorithms, JoinWithBlocksMultipleBlocksPerElementBothSides) {
NestedBlock a{{{42, 0}}, {{42, 1}, {42, 2}}, {{42, 3}, {67, 0}}};
Expand Down

0 comments on commit a4cf4ac

Please sign in to comment.