Skip to content

Commit

Permalink
add tests for pertuple
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Jan 11, 2024
1 parent 01be69a commit 09e56bb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/core/algorithms/fd/pfdtane/pfdtane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ void PFDTane::RegisterUcc([[maybe_unused]] Vertical const& key, [[maybe_unused]]
count_of_ucc_++;
}

model::PositionListIndex *PFDTane::GetColumnIndex(unsigned int column) {
return relation_->GetColumnData(column).GetPositionListIndex();
}

unsigned long long PFDTane::ExecuteInternal() {
max_fd_error_ = max_ucc_error_;
RelationalSchema const* schema = relation_->GetSchema();
Expand Down
2 changes: 2 additions & 0 deletions src/core/algorithms/fd/pfdtane/pfdtane.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class PFDTane : public PliBasedFDAlgorithm {

PFDTane();

model::PositionListIndex *GetColumnIndex(unsigned int column); // for test

static double CalculateUccError(model::PositionListIndex const* pli,
ColumnLayoutRelationData const* relation_data);

Expand Down
22 changes: 22 additions & 0 deletions src/tests/test_pfdtane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,34 @@ TEST_P(TestPFDTane, DefaultTest) {
EXPECT_EQ(p.result, algos->GetJsonFDs());
}

TEST_P(TestPFDTane, PerTupleTest) {
auto const &p = GetParam();
auto mp = algos::StdParamsMap(p.params);
auto algos = algos::CreateAndLoadAlgorithm<algos::PFDTane>(mp);

std::vector<std::pair<int, int>> cols = {{2, 3}, {4, 5}, {3, 2}, {0, 1},
{1, 0}, {4, 3}, {1, 5}, {5, 1}};
std::vector<double> errors = {0.083333, 0.333333, 0.5, 0.75,
0.0, 0.083333, 0.416666, 0.0};
double eps = 0.0001;

for (std::size_t i = 0; i < cols.size(); i++) {
double error = algos->CalculateFdErrorPerTuple(
algos->GetColumnIndex(cols[i].first),
algos->GetColumnIndex(cols[i].first)
->Intersect(algos->GetColumnIndex(cols[i].second))
.get());
EXPECT_NEAR(error, errors[i], eps);
}
}

// clang-format off
INSTANTIATE_TEST_SUITE_P(
PFDTaneTestSuite, TestPFDTane,
::testing::Values(
PFDTaneParams(R"({"fds": [{"lhs": [1,4], "rhs": 2},{"lhs": [1,4], "rhs": 5},{"lhs": [1], "rhs": 3},{"lhs": [1], "rhs": 4},{"lhs": [2], "rhs": 1},{"lhs": [2], "rhs": 3},{"lhs": [2], "rhs": 4},{"lhs": [2], "rhs": 5},{"lhs": [3], "rhs": 1},{"lhs": [3], "rhs": 2},{"lhs": [3], "rhs": 4},{"lhs": [3], "rhs": 5},{"lhs": [4], "rhs": 1},{"lhs": [4], "rhs": 3},{"lhs": [5], "rhs": 1},{"lhs": [5], "rhs": 2},{"lhs": [5], "rhs": 3},{"lhs": [5], "rhs": 4},{"lhs": [], "rhs": 0}]})", 0.3)
));

// clang-format on

} // namespace tests

0 comments on commit 09e56bb

Please sign in to comment.